mt_metadata.transfer_functions.io ================================= .. py:module:: mt_metadata.transfer_functions.io Submodules ---------- .. toctree:: :maxdepth: 1 /source/api/mt_metadata/transfer_functions/io/edi/index /source/api/mt_metadata/transfer_functions/io/emtfxml/index /source/api/mt_metadata/transfer_functions/io/jfiles/index /source/api/mt_metadata/transfer_functions/io/tools/index /source/api/mt_metadata/transfer_functions/io/zfiles/index /source/api/mt_metadata/transfer_functions/io/zonge/index Classes ------- .. autoapisummary:: mt_metadata.transfer_functions.io.EDI mt_metadata.transfer_functions.io.EMTFXML mt_metadata.transfer_functions.io.JFile mt_metadata.transfer_functions.io.ZMM mt_metadata.transfer_functions.io.ZongeMTAvg Package Contents ---------------- .. py:class:: 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. :param fn: 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 :type fn: string or :class:`pathlib.Path` :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() .. py:attribute:: logger .. py:attribute:: Header .. py:attribute:: Info .. py:attribute:: Measurement .. py:attribute:: Data .. py:attribute:: z :value: None .. py:attribute:: z_err :value: None .. py:attribute:: t :value: None .. py:attribute:: t_err :value: None .. py:attribute:: frequency :value: None .. py:attribute:: rotation_angle :value: None .. py:attribute:: residual_covariance :value: None .. py:attribute:: signal_inverse_power :value: None .. py:attribute:: tf :value: None .. py:attribute:: tf_err :value: None .. py:property:: fn .. py:property:: period :type: numpy.typing.NDArray | None .. py:method:: 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. :param fn: full path to .edi file to be read in *default* is None :type fn: string :Example: :: >>> from mt_metadata.transfer_functions.io.edi import EDI >>> edi_obj = EDI >>> edi_obj.read(fn=r"/home/mt/mt01.edi") .. py:method:: 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. :param new_edi_fn: 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" :type new_edi_fn: string :param longitude_format: whether to write longitude as LON or LONG. options are 'LON' or 'LONG', default 'LON' :type longitude_format: string :param latlon_format: format of latitude and longitude in output edi, degrees minutes seconds ('dms') or decimal degrees ('dd') :type latlon_format: string :returns: full path to new edi file :rtype: 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() .. py:property:: lat :type: float | None latitude in decimal degrees .. py:property:: lon :type: float | None longitude in decimal degrees .. py:property:: elev :type: float Elevation in elevation units .. py:property:: station :type: str | None station name .. py:property:: survey_metadata :type: mt_metadata.timeseries.Survey .. py:property:: station_metadata :type: mt_metadata.transfer_functions.tf.Station .. py:property:: ex_metadata .. py:property:: ey_metadata .. py:property:: hx_metadata .. py:property:: hy_metadata .. py:property:: hz_metadata .. py:property:: rrhx_metadata .. py:property:: rrhy_metadata .. py:class:: 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. .. py:attribute:: emtf .. py:attribute:: external_url .. py:attribute:: primary_data .. py:attribute:: attachment .. py:attribute:: provenance .. py:attribute:: copyright .. py:attribute:: site .. py:attribute:: field_notes .. py:attribute:: processing_info .. py:attribute:: statistical_estimates .. py:attribute:: data_types .. py:attribute:: site_layout .. py:attribute:: data .. py:attribute:: period_range .. py:property:: fn .. py:attribute:: element_keys :value: ['description', 'product_id', 'sub_type', 'notes', 'tags', 'external_url', 'primary_data',... .. py:property:: save_dir .. py:property:: description :type: str .. py:property:: product_id :type: str .. py:property:: tags :type: str .. py:property:: sub_type :type: str .. py:property:: notes :type: str .. py:method:: read(fn = None, get_elevation = False) Read xml file :param fn: XML file path to read, if None, use self.fn :type fn: str | Path :return: None :rtype: None .. py:method:: 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 .. py:property:: survey_metadata .. py:property:: station_metadata .. py:class:: JFile(fn = None, **kwargs) be able to read and write a j-file .. py:attribute:: header .. py:property:: fn .. py:attribute:: z :value: None .. py:attribute:: z_err :value: None .. py:attribute:: t :value: None .. py:attribute:: t_err :value: None .. py:attribute:: frequency :value: None .. py:property:: periods :type: None | numpy.typing.NDArray[numpy.float64] .. py:method:: read(fn = None, get_elevation=False) Read data from a j file :param fn: full path to j-file to read, defaults to None :type fn: str | Path | None :param get_elevation: if True, will try to get elevation from the NM elevation service, defaults to False :type get_elevation: bool, optional :raises ValueError: If the file is not found or cannot be opened. :raises NameError: If the file is not a valid j-file. :returns: Reads the data into the instance variables. :rtype: None .. py:property:: station_metadata .. py:property:: survey_metadata .. py:class:: ZMM(fn = None, **kwargs) Bases: :py:obj:`ZMMHeader` Container for Egberts zrr format. .. py:attribute:: fn :value: None .. py:attribute:: transfer_functions :value: None .. py:attribute:: sigma_e :value: None .. py:attribute:: sigma_s :value: None .. py:attribute:: periods :value: None .. py:attribute:: dataset :value: None .. py:attribute:: decimation_dict .. py:property:: channel_nomenclature :type: dict[str, str] .. py:property:: frequencies :type: numpy.typing.NDArray[numpy.float64] | None .. py:method:: initialize_arrays() make initial arrays based on number of frequencies and channels .. py:method:: read(fn = None, get_elevation = False, rotate_to_measurement_coordinates = True, use_declination = False) Read in Egbert zrr/zmm file :param fn: The file name to read, by default None :type fn: str | Path | None, optional :param get_elevation: If True, fetch elevation from the National Map, by default False :type get_elevation: bool, optional :param rotate_to_measurement_coordinates: If True, rotate impedance to the provided reference frame of the channel metadata, by default True :type rotate_to_measurement_coordinates: bool, optional :param use_declination: If True, rotate impedance to true north using declination value in metadata, by default False :type use_declination: bool, optional :raises ZMMError: If the file cannot be read or is not in the expected format. .. py:method:: 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 :param fn: The file name to write, by default None :type fn: str | Path | None, optional :param decimation_levels: A dictionary containing decimation levels and their properties, by default None. :type decimation_levels: dict, optional :raises ZMMError: If the file cannot be written or is not in the expected format. .. py:method:: calculate_impedance(angle = 0.0) calculate the impedances from the transfer functions :param angle: The angle to rotate the impedance tensor. :type angle: float, optional :returns: * **z** (*np.ndarray | None*) -- The impedance tensor. * **error** (*np.ndarray | None*) -- The impedance tensor error. .. py:method:: calculate_tippers(angle = 0.0) calculate induction vectors :param angle: The angle to rotate the tipper tensor. :type angle: float, optional :returns: **tipper** -- The tipper tensor. :rtype: np.ndarray .. py:property:: survey_metadata .. py:property:: ex_metadata :type: mt_metadata.timeseries.Electric .. py:property:: ey_metadata :type: mt_metadata.timeseries.Electric .. py:property:: hx_metadata :type: mt_metadata.timeseries.Magnetic .. py:property:: hy_metadata :type: mt_metadata.timeseries.Magnetic .. py:property:: hz_metadata :type: mt_metadata.timeseries.Magnetic .. py:class:: ZongeMTAvg(fn=None, **kwargs) deal with avg files output from mtedit .. py:attribute:: header .. py:attribute:: info_keys :value: ['skip', 'frequency', 'e_magnitude', 'b_magnitude', 'z_magnitude', 'z_phase',... .. py:attribute:: info_fmt :value: [] .. py:attribute:: z :value: None .. py:attribute:: z_err :value: None .. py:attribute:: t :value: None .. py:attribute:: t_err :value: None .. py:attribute:: components :value: [] .. py:attribute:: freq_index_dict :value: None .. py:attribute:: z_positive :value: 'down' .. py:property:: fn :type: pathlib.Path | None .. py:method:: read(fn = None, get_elevation = False) Read data from a file into the object as a pandas DataFrame :param fn: The file name to read from, by default None :type fn: str | Path | None, optional :param get_elevation: Whether to get elevation data, by default False :type get_elevation: bool, optional .. py:method:: 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. :param zmag: The magnitude array. :type zmag: np.typing.NDArray :param zphase: The phase array. :type zphase: np.typing.NDArray :returns: The real and imaginary parts of the complex representation. :rtype: tuple[np.typing.NDArray, np.typing.NDArray] .. py:method:: to_amp_phase(zreal, zimag) Convert to amplitude and phase from real and imaginary :param zreal: The real part of the complex representation. :type zreal: np.typing.NDArray :param zimag: The imaginary part of the complex representation. :type zimag: np.typing.NDArray :returns: The amplitude and phase representation. :rtype: tuple[np.typing.NDArray, np.typing.NDArray] .. py:property:: run_metadata :type: mt_metadata.timeseries.Run .. py:property:: ex_metadata :type: mt_metadata.timeseries.Electric .. py:property:: ey_metadata :type: mt_metadata.timeseries.Electric .. py:property:: hx_metadata :type: mt_metadata.timeseries.Magnetic .. py:property:: hy_metadata :type: mt_metadata.timeseries.Magnetic .. py:property:: hz_metadata :type: mt_metadata.timeseries.Magnetic .. py:property:: station_metadata :type: mt_metadata.transfer_functions.tf.Station .. py:property:: survey_metadata :type: mt_metadata.timeseries.Survey .. py:method:: write(fn) Write an .avg file :param fn: Filename to write to :type fn: str or Path