mth5.io.conversion
Convert MTH5 to other formats
MTH5 -> miniSEED + StationXML
Classes
Convert MTH5 files to miniSEED and StationXML formats. |
Functions
|
Determine consistent data encoding for miniSEED files across channels. |
|
Split an existing miniSEED file into daily files. |
Module Contents
- class mth5.io.conversion.MTH5ToMiniSEEDStationXML(mth5_path: str | pathlib.Path | None = None, save_path: str | pathlib.Path | None = None, network_code: str = 'ZU', use_runs_with_data_only: bool = True, **kwargs: Any)[source]
Convert MTH5 files to miniSEED and StationXML formats.
This class provides functionality to convert magnetotelluric data stored in MTH5 format to industry-standard miniSEED time series files and StationXML metadata files for data exchange and archival purposes.
- Parameters:
mth5_path (str, Path, or None, default None) – Path to the input MTH5 file to be converted
save_path (str, Path, or None, default None) – Directory path where output files will be saved. If None, uses the parent directory of mth5_path
network_code (str, default "ZU") – Two-character FDSN network code for the output files
use_runs_with_data_only (bool, default True) – If True, only process runs that contain actual time series data
**kwargs (dict) – Additional keyword arguments to set as instance attributes
Examples
>>> converter = MTH5ToMiniSEEDStationXML( ... mth5_path="/path/to/data.h5", ... network_code="MT", ... save_path="/path/to/output" ... ) >>> xml_file, mseed_files = converter.convert_mth5_to_ms_stationxml()
- property mth5_path: pathlib.Path | None[source]
Path to the MTH5 input file.
- Returns:
Path to the MTH5 file to be converted, or None if not set.
- Return type:
Path or None
- property save_path: pathlib.Path[source]
Directory path where output files will be saved.
- Returns:
Directory path for saving miniSEED and StationXML files.
- Return type:
Path
- property network_code: str[source]
Two-character FDSN network code.
- Returns:
Alphanumeric string of exactly 2 characters as required by FDSN DMC.
- Return type:
str
- classmethod convert_mth5_to_ms_stationxml(mth5_path: str | pathlib.Path, save_path: str | pathlib.Path | None = None, network_code: str = 'ZU', use_runs_with_data_only: bool = True, **kwargs: Any) tuple[pathlib.Path, list[pathlib.Path]][source]
Convert an MTH5 file to miniSEED and StationXML formats.
Class method that provides a convenient interface to convert MTH5 data to standard seismological formats for data exchange and archival.
- Parameters:
mth5_path (str or Path) – Path to the input MTH5 file to be converted
save_path (str, Path, or None, default None) – Directory where output files will be saved. If None, uses the parent directory of mth5_path
network_code (str, default "ZU") – Two-character FDSN network code for output files
use_runs_with_data_only (bool, default True) – If True, only process runs containing actual time series data
**kwargs (dict) – Additional keyword arguments passed to converter initialization
- Returns:
Tuple containing: - Path to the generated StationXML file - List of paths to generated miniSEED files (one per day per channel)
- Return type:
tuple[Path, list[Path]]
Examples
>>> xml_file, mseed_files = MTH5ToMiniSEEDStationXML.convert_mth5_to_ms_stationxml( ... "/path/to/data.h5", ... network_code="MT", ... save_path="/output/directory" ... ) >>> print(f"Created {len(mseed_files)} miniSEED files and {xml_file}")
- split_ms_to_days(streams, save_path: pathlib.Path, encoding: str) list[pathlib.Path][source]
Split miniSEED traces into daily files.
Splits continuous time series traces into separate files for each day to conform with standard seismological data archiving practices.
- Parameters:
streams (obspy.Stream) – Stream object containing traces to be split by day
save_path (Path) – Directory where daily miniSEED files will be saved
encoding (str) – Data encoding format for miniSEED files (e.g., ‘INT32’, ‘FLOAT64’)
- Returns:
List of paths to the generated daily miniSEED files
- Return type:
list[Path]
Notes
Files are named using the pattern: {network}_{station}_{location}_{channel}_{YYYY_MM_DDTHH_MM_SS}.mseed
- mth5.io.conversion.get_encoding(run_ts) str[source]
Determine consistent data encoding for miniSEED files across channels.
Analyzes data types across all channels in a run and selects a median encoding to ensure compatibility in miniSEED file generation.
- Parameters:
run_ts (RunTS) – Run time series object containing multiple channels of data
- Returns:
String identifier for miniSEED encoding format (e.g., ‘INT32’, ‘FLOAT64’)
- Return type:
str
Notes
Uses median data type to handle mixed precision datasets. Automatically converts INT64 to INT32 for miniSEED compatibility since some readers don’t support 64-bit integers.
Examples
>>> encoding = get_encoding(run_timeseries) >>> print(f"Selected encoding: {encoding}")
- mth5.io.conversion.split_miniseed_by_day(input_file: str | pathlib.Path) list[pathlib.Path][source]
Split an existing miniSEED file into daily files.
Utility function to split a multi-day miniSEED file into separate files for each calendar day, following standard seismological archiving practices.
- Parameters:
input_file (str or Path) – Path to the input miniSEED file to be split
- Returns:
List of paths to the generated daily miniSEED files
- Return type:
list[Path]
Notes
Output files are named using the pattern: {network}.{station}.{location}.{channel}.{YYYY-MM-DD}.mseed
Files are saved in the same directory as the input file.
Examples
>>> daily_files = split_miniseed_by_day("/path/to/continuous.mseed") >>> print(f"Created {len(daily_files)} daily files")