mt_metadata.transfer_functions.io
Submodules
Classes
This class is for .edi files, mainly reading and writing. Has been tested |
|
This is meant to follow Anna's XML schema for transfer functions |
|
be able to read and write a j-file |
|
Container for Egberts zrr format. |
|
deal with avg files output from mtedit |
Package Contents
- class mt_metadata.transfer_functions.io.EDI(fn=None, **kwargs)
This class is for .edi files, mainly reading and writing. Has been tested on Winglink and Phoenix output .edi’s, which are meant to follow the archaic EDI format put forward by SEG. Can read impedance, Tipper and/or spectra data.
The Edi class contains a class for each major section of the .edi file.
Frequency and components are ordered from highest to lowest frequency.
- Parameters:
fn (string or
pathlib.Path) – full path to .edi file to be read in. default is None. If an .edi file is input, it is automatically read in and attributes of Edi are filled- Change Latitude:
>>> from mt_metadata.transfer_functions.io.edi import EDI >>> edi_obj = EDI(fn=r"/home/mt/mt01.edi") >>> # change the latitude >>> edi_obj.lat = 45.7869 >>> new_edi_fn = edi_obj.write()
- logger
- Header
- Info
- Measurement
- Data
- z = None
- z_err = None
- t = None
- t_err = None
- frequency = None
- rotation_angle = None
- residual_covariance = None
- signal_inverse_power = None
- tf = None
- tf_err = None
- property fn
- property period: numpy.typing.NDArray | None
- read(fn=None, get_elevation=False)
Read in an edi file and fill attributes of each section’s classes. Including:
Header
Info
Measurement
Data
z, z_err
t, t_err
Note
Automatically detects if data is in spectra format. All data read in is converted to impedance and Tipper.
- Parameters:
fn (string) – full path to .edi file to be read in default is None
- Example:
>>> from mt_metadata.transfer_functions.io.edi import EDI >>> edi_obj = EDI >>> edi_obj.read(fn=r"/home/mt/mt01.edi")
- write(new_edi_fn=None, longitude_format='LON', latlon_format='dms')
Write a new edi file from either an existing .edi file or from data input by the user into the attributes of Edi.
- Parameters:
new_edi_fn (string) – full path to new edi file. default is None, which will write to the same file as the input .edi with as: r”/home/mt/mt01_1.edi”
longitude_format (string) – whether to write longitude as LON or LONG. options are ‘LON’ or ‘LONG’, default ‘LON’
latlon_format (string) – format of latitude and longitude in output edi, degrees minutes seconds (‘dms’) or decimal degrees (‘dd’)
- Returns:
full path to new edi file
- Return type:
string
- Example:
>>> import mtpy.core.edi as mtedi >>> edi_obj = mtedi.Edi(fn=r"/home/mt/mt01/edi") >>> edi_obj.Header.dataid = 'mt01_rr' >>> n_edi_fn = edi_obj.write_edi_file()
- property lat: float | None
latitude in decimal degrees
- property lon: float | None
longitude in decimal degrees
- property elev: float
Elevation in elevation units
- property station: str | None
station name
- property survey_metadata: mt_metadata.timeseries.Survey
- property station_metadata: mt_metadata.transfer_functions.tf.Station
- property ex_metadata
- property ey_metadata
- property hx_metadata
- property hy_metadata
- property hz_metadata
- property rrhx_metadata
- property rrhy_metadata
- class mt_metadata.transfer_functions.io.EMTFXML(fn=None, **kwargs)
This is meant to follow Anna’s XML schema for transfer functions
[Kelbert2019](https://doi.org/10.1190/geo2018-0679.1).
making this a MetadataBase object is complicated because of station and survey metadata, so we are going to leave this as just an object.
- emtf
- external_url
- primary_data
- attachment
- provenance
- copyright
- site
- field_notes
- processing_info
- statistical_estimates
- data_types
- site_layout
- data
- period_range
- property fn
- element_keys = ['description', 'product_id', 'sub_type', 'notes', 'tags', 'external_url', 'primary_data',...
- property save_dir
- property description: str
- property product_id: str
- property tags: str
- property sub_type: str
- property notes: str
- read(fn=None, get_elevation=False)
Read xml file
- Parameters:
fn (str | Path) – XML file path to read, if None, use self.fn
- Returns:
None
- Return type:
None
- write(fn, skip_field_notes=False)
Write an xml :param fn: XML file path to write :type fn: str | Path :return: None :rtype: None :rtype: TYPE
- property survey_metadata
- property station_metadata
- class mt_metadata.transfer_functions.io.JFile(fn=None, **kwargs)
be able to read and write a j-file
- header
- property fn
- z = None
- z_err = None
- t = None
- t_err = None
- frequency = None
- property periods: None | numpy.typing.NDArray[numpy.float64]
- read(fn=None, get_elevation=False)
Read data from a j file
- Parameters:
fn (str | Path | None) – full path to j-file to read, defaults to None
get_elevation (bool, optional) – if True, will try to get elevation from the NM elevation service, defaults to False
- Raises:
ValueError – If the file is not found or cannot be opened.
NameError – If the file is not a valid j-file.
- Returns:
Reads the data into the instance variables.
- Return type:
None
- property station_metadata
- property survey_metadata
- class mt_metadata.transfer_functions.io.ZMM(fn=None, **kwargs)
Bases:
ZMMHeaderContainer for Egberts zrr format.
- fn = None
- transfer_functions = None
- sigma_e = None
- sigma_s = None
- periods = None
- dataset = None
- decimation_dict
- property channel_nomenclature: dict[str, str]
- property frequencies: numpy.typing.NDArray[numpy.float64] | None
- initialize_arrays()
make initial arrays based on number of frequencies and channels
- read(fn=None, get_elevation=False, rotate_to_measurement_coordinates=True, use_declination=False)
Read in Egbert zrr/zmm file
- Parameters:
fn (str | Path | None, optional) – The file name to read, by default None
get_elevation (bool, optional) – If True, fetch elevation from the National Map, by default False
rotate_to_measurement_coordinates (bool, optional) – If True, rotate impedance to the provided reference frame of the channel metadata, by default True
use_declination (bool, optional) – If True, rotate impedance to true north using declination value in metadata, by default False
- Raises:
ZMMError – If the file cannot be read or is not in the expected format.
- write(fn=None, decimation_levels=None)
write a zmm file
decimation_levels should be a dictionary with keys
decimation_level
values will be a dictionary with keys
frequency_band, value = (min, max)
n_points, value = int
sampling_freq, value = float
- Parameters:
fn (str | Path | None, optional) – The file name to write, by default None
decimation_levels (dict, optional) – A dictionary containing decimation levels and their properties, by default None.
- Raises:
ZMMError – If the file cannot be written or is not in the expected format.
- calculate_impedance(angle=0.0)
calculate the impedances from the transfer functions
- Parameters:
angle (float, optional) – The angle to rotate the impedance tensor.
- Returns:
z (np.ndarray | None) – The impedance tensor.
error (np.ndarray | None) – The impedance tensor error.
- Return type:
tuple[numpy.typing.NDArray[numpy.complex64] | None, numpy.typing.NDArray[numpy.float64] | None]
- calculate_tippers(angle=0.0)
calculate induction vectors
- Parameters:
angle (float, optional) – The angle to rotate the tipper tensor.
- Returns:
tipper – The tipper tensor.
- Return type:
np.ndarray
- property survey_metadata
- property ex_metadata: mt_metadata.timeseries.Electric
- property ey_metadata: mt_metadata.timeseries.Electric
- property hx_metadata: mt_metadata.timeseries.Magnetic
- property hy_metadata: mt_metadata.timeseries.Magnetic
- property hz_metadata: mt_metadata.timeseries.Magnetic
- class mt_metadata.transfer_functions.io.ZongeMTAvg(fn=None, **kwargs)
deal with avg files output from mtedit
- header
- info_keys = ['skip', 'frequency', 'e_magnitude', 'b_magnitude', 'z_magnitude', 'z_phase',...
- info_fmt = []
- z = None
- z_err = None
- t = None
- t_err = None
- components = []
- freq_index_dict = None
- z_positive = 'down'
- property fn: pathlib.Path | None
- read(fn=None, get_elevation=False)
Read data from a file into the object as a pandas DataFrame
- Parameters:
fn (str | Path | None, optional) – The file name to read from, by default None
get_elevation (bool, optional) – Whether to get elevation data, by default False
- to_complex(zmag, zphase)
Convert magnitude and phase to complex representation.
Outputs of mtedit are magnitude and phase of z, convert to real and imaginary parts, phase is in milliradians.
- Parameters:
zmag (np.typing.NDArray) – The magnitude array.
zphase (np.typing.NDArray) – The phase array.
- Returns:
The real and imaginary parts of the complex representation.
- Return type:
tuple[np.typing.NDArray, np.typing.NDArray]
- to_amp_phase(zreal, zimag)
Convert to amplitude and phase from real and imaginary
- Parameters:
zreal (np.typing.NDArray) – The real part of the complex representation.
zimag (np.typing.NDArray) – The imaginary part of the complex representation.
- Returns:
The amplitude and phase representation.
- Return type:
tuple[np.typing.NDArray, np.typing.NDArray]
- property run_metadata: mt_metadata.timeseries.Run
- property ex_metadata: mt_metadata.timeseries.Electric
- property ey_metadata: mt_metadata.timeseries.Electric
- property hx_metadata: mt_metadata.timeseries.Magnetic
- property hy_metadata: mt_metadata.timeseries.Magnetic
- property hz_metadata: mt_metadata.timeseries.Magnetic
- property station_metadata: mt_metadata.transfer_functions.tf.Station
- property survey_metadata: mt_metadata.timeseries.Survey
- write(fn)
Write an .avg file
- Parameters:
fn (str or Path) – Filename to write to