mth5.io.lemi.lemi_collection

Collection of TXT files combined into runs

Created on Wed Aug 31 10:32:44 2022

@author: jpeacock

Classes

LEMICollection

Collection of LEMI 424 files into runs based on start and end times.

Module Contents

class mth5.io.lemi.lemi_collection.LEMICollection(file_path: str | pathlib.Path | None = None, file_ext: List[str] | None = None, **kwargs)[source]

Bases: mth5.io.collection.Collection

Collection of LEMI 424 files into runs based on start and end times.

Will assign the run name as ‘sr1_{index:0{zeros}}’ –> ‘sr1_0001’ for zeros = 4.

Notes

This class assumes that the given file path contains a single LEMI station. If you want to do multiple stations merge the returned data frames.

LEMI data comes with little metadata about the station or survey, therefore you should assign station_id and survey_id.

Parameters:
  • file_path (str or pathlib.Path, optional) – Full path to single station LEMI424 directory, by default None

  • file_ext (list of str, optional) – Extension of LEMI424 files, by default [“txt”, “TXT”]

  • **kwargs – Additional keyword arguments passed to parent Collection class

station_id[source]

Station identification string, defaults to “mt001”

Type:

str

survey_id[source]

Survey identification string, defaults to “mt”

Type:

str

Examples

>>> from mth5.io.lemi import LEMICollection
>>> lc = LEMICollection(r"/path/to/single/lemi/station")
>>> lc.station_id = "mt001"
>>> lc.survey_id = "test_survey"
>>> run_dict = lc.get_runs(1)
station_id = 'mt001'[source]
survey_id = 'mt'[source]
calibration_dict[source]
get_calibrations(calibration_path: str | pathlib.Path) dict[source]

Get calibration dictionary for LEMI424 files. This assumes that the calibrations files are in JSON format and named as ‘LEMI-424-<component>.json’

Parameters:

calibration_path (str or pathlib.Path) – Path to calibration files

Returns:

Calibration dictionary for LEMI424 files

Return type:

dict

Examples

>>> from mth5.io.lemi import LEMICollection
>>> lc = LEMICollection("/path/to/single/lemi/station")
>>> cal_dict = lc.get_calibrations(Path("/path/to/calibrations"))
to_dataframe(sample_rates: int | List[int] | None = None, run_name_zeros: int = 4, calibration_path: str | pathlib.Path | None = None) pandas.DataFrame[source]

Create a data frame of each TXT file in a given directory.

Notes

This assumes the given directory contains a single station

Parameters:
  • sample_rates (int or list of int, optional) – Sample rate to get, will always be 1 for LEMI data, by default [1]

  • run_name_zeros (int, optional) – Number of zeros to assign to the run name, by default 4

  • calibration_path (str or pathlib.Path, optional) – Path to calibration files, by default None

Returns:

DataFrame with information of each TXT file in the given directory

Return type:

pd.DataFrame

Examples

>>> from mth5.io.lemi import LEMICollection
>>> lc = LEMICollection("/path/to/single/lemi/station")
>>> lemi_df = lc.to_dataframe()
assign_run_names(df: pandas.DataFrame, zeros: int = 4) pandas.DataFrame[source]

Assign run names based on start and end times.

Checks if a file has the same start time as the last end time. Run names are assigned as sr{sample_rate}_{run_number:0{zeros}}.

Parameters:
  • df (pd.DataFrame) – DataFrame with the appropriate columns

  • zeros (int, optional) – Number of zeros in run name, by default 4

Returns:

DataFrame with run names assigned

Return type:

pd.DataFrame