mth5.io.lemi.lemi424

Created on Tue May 11 15:31:31 2021

copyright:

Jared Peacock (jpeacock@usgs.gov)

license:

MIT

Classes

LEMI424

Read and process LEMI424 magnetotelluric data files.

Functions

lemi_date_parser(→ pandas.Series)

Combine the date-time columns that are output by LEMI into a single column.

lemi_position_parser(→ float)

Parse LEMI location strings into decimal degrees.

lemi_hemisphere_parser(→ int)

Convert hemisphere into a value [-1, 1].

read_lemi424(→ mth5.timeseries.RunTS)

Read a LEMI 424 TXT file.

Module Contents

mth5.io.lemi.lemi424.lemi_date_parser(year: int, month: int, day: int, hour: int, minute: int, second: int) pandas.Series[source]

Combine the date-time columns that are output by LEMI into a single column.

Assumes UTC timezone.

Parameters:
  • year (int) – Year value.

  • month (int) – Month value (1-12).

  • day (int) – Day of the month (1-31).

  • hour (int) – Hour in 24-hour format (0-23).

  • minute (int) – Minutes in the hour (0-59).

  • second (int) – Seconds in the minute (0-59).

Returns:

Combined date-time as a pandas DatetimeIndex.

Return type:

pd.DatetimeIndex

mth5.io.lemi.lemi424.lemi_position_parser(position: float) float[source]

Parse LEMI location strings into decimal degrees.

Uses the hemisphere for the sign.

Notes

The format of the location is odd in that it is multiplied by 100 within the LEMI to provide a single floating point value that includes the degrees and decimal degrees –> {degrees}{degrees[mm.ss]}. For example 40.50166 would be represented as 4030.1.

Parameters:

position (float) – LEMI position value to parse.

Returns:

Decimal degrees position.

Return type:

float

mth5.io.lemi.lemi424.lemi_hemisphere_parser(hemisphere: str) int[source]

Convert hemisphere into a value [-1, 1].

Assumes the prime meridian is 0.

Parameters:

hemisphere (str) – Hemisphere string. Valid values are ‘N’, ‘S’, ‘E’, ‘W’.

Returns:

Unity with a sign for the given hemisphere. Returns -1 for ‘S’ or ‘W’, 1 for ‘N’ or ‘E’.

Return type:

int

class mth5.io.lemi.lemi424.LEMI424(fn: str | pathlib.Path | None = None, **kwargs: Any)[source]

Read and process LEMI424 magnetotelluric data files.

This is a placeholder until IRIS finalizes their reader.

Parameters:
  • fn (str or pathlib.Path, optional) – Full path to LEMI424 file, by default None.

  • **kwargs (dict) – Additional keyword arguments for configuration.

sample_rate[source]

Sample rate of the file, default is 1.0.

Type:

float

chunk_size[source]

Chunk size for pandas to use, default is 8640.

Type:

int

file_column_names[source]

Column names of the LEMI424 file.

Type:

list of str

dtypes[source]

Data types for each column.

Type:

dict

data_column_names[source]

Same as file_column_names with an added column for date.

Type:

list of str

data[source]

The loaded data.

Type:

pd.DataFrame or None

Notes

LEMI424 File Column Names:

year, month, day, hour, minute, second, bx, by, bz, temperature_e, temperature_h, e1, e2, e3, e4, battery, elevation, latitude, lat_hemisphere, longitude, lon_hemisphere, n_satellites, gps_fix, time_diff

Data Column Names:

date, bx, by, bz, temperature_e, temperature_h, e1, e2, e3, e4, battery, elevation, latitude, lat_hemisphere, longitude, lon_hemisphere, n_satellites, gps_fix, time_diff

logger[source]
property fn: pathlib.Path | None[source]

Full path to LEMI424 file.

Returns:

Path to the file or None if not set.

Return type:

pathlib.Path or None

sample_rate = 1.0[source]
chunk_size = 8640[source]
property data: pandas.DataFrame | None[source]

Data represented as a pandas DataFrame with data column names.

Returns:

The loaded data or None if no data is loaded.

Return type:

pd.DataFrame or None

file_column_names = ['year', 'month', 'day', 'hour', 'minute', 'second', 'bx', 'by', 'bz', 'temperature_e',...[source]
dtypes[source]
data_column_names = ['date', 'bx', 'by', 'bz', 'temperature_e', 'temperature_h', 'e1', 'e2', 'e3', 'e4', 'battery',...[source]
property file_size: int | None[source]

Size of file in bytes.

Returns:

File size in bytes or None if no file is set.

Return type:

int or None

property start: mt_metadata.common.mttime.MTime | None[source]

Start time of data collection in the LEMI424 file.

Returns:

Start time or None if no data is loaded.

Return type:

MTime or None

property end: mt_metadata.common.mttime.MTime | None[source]

End time of data collection in the LEMI424 file.

Returns:

End time or None if no data is loaded.

Return type:

MTime or None

property latitude: float | None[source]

Median latitude where data have been collected.

Returns:

Median latitude in degrees or None if no data is loaded.

Return type:

float or None

property longitude: float | None[source]

Median longitude where data have been collected.

Returns:

Median longitude in degrees or None if no data is loaded.

Return type:

float or None

property elevation: float | None[source]

Median elevation where data have been collected.

Returns:

Median elevation in meters or None if no data is loaded.

Return type:

float or None

property n_samples: int | None[source]

Number of samples in the file.

Returns:

Number of samples or None if no data/file available.

Return type:

int or None

property gps_lock: Any | None[source]

GPS lock status array.

Returns:

GPS fix values or None if no data is loaded.

Return type:

numpy.ndarray or None

property station_metadata: mt_metadata.timeseries.Station[source]

Station metadata as mt_metadata.timeseries.Station object.

Returns:

Station metadata object.

Return type:

mt_metadata.timeseries.Station

property run_metadata: mt_metadata.timeseries.Run[source]

Run metadata as mt_metadata.timeseries.Run object.

Returns:

Run metadata object.

Return type:

mt_metadata.timeseries.Run

read(fn: str | pathlib.Path | None = None, fast: bool = True) None[source]

Read a LEMI424 file using pandas.

The fast way will read in the first and last line to get the start and end time to make a time index. Then it will read in the data skipping parsing the date time columns. It will check to make sure the expected amount of points are correct. If not then it will read in the slower way which uses the date time parser to ensure any time gaps are respected.

Parameters:
  • fn (str, pathlib.Path, or None, optional) – Full path to file. Uses LEMI424.fn if not provided, by default None.

  • fast (bool, optional) – Read the fast way (True) or not (False), by default True.

Raises:

IOError – If file cannot be found.

read_metadata() None[source]

Read only first and last rows to get important metadata.

This method is used to extract essential metadata from the collection without loading the entire dataset.

read_calibration(fn: str | pathlib.Path) mt_metadata.timeseries.filters.FrequencyResponseTableFilter[source]

Read a LEMI424 calibration file.

Calibration files are assumed to be JSON files with the following format: {

“Calibration”: {

“gain”: float, “Freq”: [float], “Re”: [float], “Im”: [float]

}

}

Parameters:

fn (str or pathlib.Path) – Full path to calibration file.

Returns:

Calibration filter object.

Return type:

mt_metadata.timeseries.filters.FrequencyResponseTableFilter

to_run_ts(fn: str | pathlib.Path | None = None, e_channels: list[str] = ['e1', 'e2'], calibration_dict: dict | None = None) mth5.timeseries.RunTS[source]

Create a RunTS object from the data.

Parameters:
  • fn (str, pathlib.Path, or None, optional) – Full path to file. Will use LEMI424.fn if None, by default None.

  • e_channels (list of str, optional) – Column names for the electric channels to use, by default [“e1”, “e2”].

  • calibration_dict (dict, optional) – Calibration dictionary to apply to the data, by default {}. Keys are the channel names and values are the calibration file path. The file path is assumed to be in the format lemi-{component}.sr.json.

Returns:

RunTS object containing the data.

Return type:

mth5.timeseries.RunTS

mth5.io.lemi.lemi424.read_lemi424(fn: str | pathlib.Path | list[str | pathlib.Path], e_channels: list[str] = ['e1', 'e2'], fast: bool = True, calibration_dict: dict | None = None) mth5.timeseries.RunTS[source]

Read a LEMI 424 TXT file.

Parameters:
  • fn (str or pathlib.Path) – Input file name.

  • e_channels (list of str, optional) – A list of electric channels to read, by default [“e1”, “e2”].

  • fast (bool, optional) – Use fast reading method, by default True.

  • calibration_dict (dict, optional) – Calibration dictionary to apply to the data, by default None. Keys are the channel names and values are the calibration file path.

Returns:

A RunTS object with appropriate metadata.

Return type:

mth5.timeseries.RunTS