This notebook provides an example of how to read in LEMI (.TXT) files into an MTH5.
from mth5.mth5 import MTH5
from mth5.io.lemi import LEMICollection
from mth5.clients import MakeMTH52022-09-07 18:07:09,774 [line 135] mth5.setup_logger - INFO: Logging file can be found C:\Users\jpeacock\OneDrive - DOI\Documents\GitHub\mth5\logs\mth5_debug.log
LEMI Collection¶
We will use the LEMICollection to assemble the .txt files into a logical order by schedule action or run. The output LEMI files include all data for each channel.
IMPORTANT: LEMICollection assumes the given file path is for a single station.
Metadata: we need to input the station_id and the survey_id to provide minimal metadata when making an MTH5 fild.
The LEMICollection.get_runs() will return a two level ordered dictionary (OrderedDict). The first level is keyed by station ID. These objects are in turn ordered dictionaries by run ID. Therefore you can loop over stations and runs.
Note: n_samples is an estimate based on file size not the data. To get an accurate number you should read in the full file.
lemi_station_path = r"c:\Users\jpeacock\OneDrive - DOI\mt\lemi\DATA0110"zc = LEMICollection(lemi_station_data_path)
zc.station_id = "mt001"
zc.survey_id = "test"
runs = zc.get_runs(sample_rates=[1])
print(f"Found {len(runs)} station with {len(runs[list(runs.keys())[0]])} runs")Found 1 station with 5 runs
for run_id, run_df in runs[zc.station_id].items():
display(run_df)Build MTH5¶
Now that we have a logical collection of files, lets load them into an MTH5. We will simply loop of the stations, runs, and channels in the ordered dictionary.
There are a few things that to keep in mind:
The LEMI raw files come with very little metadata, so as a user you will have to manually input most of it.
The output files from a LEMI are already calibrated into units of nT and mV/km (I think), therefore there are no filter to apply to calibrate the data.
Since this is a MTH5 file version 0.2.0 the filters are in the
survey_groupso add them there.
mth5_path = MakeMTH5.from_lemi424(lemi_station_path, "test", "mt01")MTH5 Structure¶
Have a look at the MTH5 structure and make sure it looks correct.
m = MTH5()
m = m.open_mth5(mth5_path)m/:
====================
|- Group: Experiment
--------------------
|- Group: Reports
-----------------
|- Group: Standards
-------------------
--> Dataset: summary
......................
|- Group: Surveys
-----------------
|- Group: test
--------------
|- Group: Filters
-----------------
|- Group: coefficient
---------------------
|- Group: fap
-------------
|- Group: fir
-------------
|- Group: time_delay
--------------------
|- Group: zpk
-------------
|- Group: Reports
-----------------
|- Group: Standards
-------------------
--> Dataset: summary
......................
|- Group: Stations
------------------
|- Group: mt001
---------------
|- Group: Transfer_Functions
----------------------------
|- Group: sr1_0001
------------------
--> Dataset: bx
.................
--> Dataset: by
.................
--> Dataset: bz
.................
--> Dataset: e1
.................
--> Dataset: e2
.................
--> Dataset: temperature_e
............................
--> Dataset: temperature_h
............................
|- Group: sr1_0002
------------------
--> Dataset: bx
.................
--> Dataset: by
.................
--> Dataset: bz
.................
--> Dataset: e1
.................
--> Dataset: e2
.................
--> Dataset: temperature_e
............................
--> Dataset: temperature_h
............................
|- Group: sr1_0003
------------------
--> Dataset: bx
.................
--> Dataset: by
.................
--> Dataset: bz
.................
--> Dataset: e1
.................
--> Dataset: e2
.................
--> Dataset: temperature_e
............................
--> Dataset: temperature_h
............................
|- Group: sr1_0004
------------------
--> Dataset: bx
.................
--> Dataset: by
.................
--> Dataset: bz
.................
--> Dataset: e1
.................
--> Dataset: e2
.................
--> Dataset: temperature_e
............................
--> Dataset: temperature_h
............................
|- Group: sr1_0005
------------------
--> Dataset: bx
.................
--> Dataset: by
.................
--> Dataset: bz
.................
--> Dataset: e1
.................
--> Dataset: e2
.................
--> Dataset: temperature_e
............................
--> Dataset: temperature_h
............................
--> Dataset: channel_summary
..............................
--> Dataset: tf_summary
.........................Channel Summary¶
Have a look at the channel summary and make sure everything looks good.
m.channel_summary.summarize()
m.channel_summary.to_dataframe()Close the MTH5¶
This is important, you should close the file after you are done using it. Otherwise bad things can happen if you try to open it with another program or Python interpreter.
m.close_mth5()2022-09-07 18:08:23,271 [line 744] mth5.mth5.MTH5.close_mth5 - INFO: Flushing and closing c:\Users\jpeacock\OneDrive - DOI\mt\lemi\DATA0110\from_lemi.h5