This notebook provides an example of how to read in ZEN (.Z3D) files into an MTH5.
from mth5.mth5 import MTH5
from mth5.clients import MakeMTH5
2022-09-07 18:20:17,973 [line 135] mth5.setup_logger - INFO: Logging file can be found C:\Users\jpeacock\OneDrive - DOI\Documents\GitHub\mth5\logs\mth5_debug.log
Z3D Collection¶
We will use the Z3DCollection
to assemble the .z3d files into a logical order by schedule action or run.
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. Same with start
and end
. start
is based on the schedule start time which is usually 2 seconds earlier than the data start because of instrument buffer while chaning sampling rates. end
is based on file size and sample rate.
The Z3DCollection.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.
zc = Z3DCollection(r"/mt/example_z3d_data")
runs = zc.get_runs(sample_rates=[4096, 256])
print(f"Found {len(runs)} station with {len(runs[list(runs.keys())[0]])} runs")
Found 1 station with 2 runs
runs["100"]["sr4096_0001"]
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 we need to keep track of.
- The station metadata pulled directly from the Z3D files can be input into the station metadata, be sure to use the
write_metadata
method to write the metadata to the MTH5. - The Z3D files have the coil response and zen response embedded in the file, so we can put those into the appropriate filter container in MTH5. This is important for calibrating later.
- Since this is a MTH5 file version 0.2.0 the filters are in the
survey_group
so add them there. - If you want to calibrate the data set calibrate to
True
.
mth5_path = MakeMTH5.from_zen(
"data_path",
calibration_path="path_to_calibration_file_amtant.cal",
survey_id="common_survey_id",
combine=True,
**kwargs
)
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: dipole_55.00m
-----------------------
|- Group: dipole_56.00m
-----------------------
|- Group: zen_counts2mv
-----------------------
|- Group: fap
-------------
|- Group: ant4_2314_response
----------------------------
--> Dataset: fap_table
........................
|- Group: ant4_2324_response
----------------------------
--> Dataset: fap_table
........................
|- Group: ant4_2334_response
----------------------------
--> Dataset: fap_table
........................
|- Group: fir
-------------
|- Group: time_delay
--------------------
|- Group: zpk
-------------
|- Group: Reports
-----------------
|- Group: Standards
-------------------
--> Dataset: summary
......................
|- Group: Stations
------------------
|- Group: 100
-------------
|- Group: Transfer_Functions
----------------------------
|- Group: sr256_0002
--------------------
--> Dataset: ex
.................
--> Dataset: ey
.................
--> Dataset: hx
.................
--> Dataset: hy
.................
--> Dataset: hz
.................
|- Group: sr4096_0001
---------------------
--> Dataset: ex
.................
--> Dataset: ey
.................
--> Dataset: hx
.................
--> Dataset: hy
.................
--> Dataset: hz
.................
--> 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:20:39,445 [line 744] mth5.mth5.MTH5.close_mth5 - INFO: Flushing and closing c:\Users\jpeacock\OneDrive - DOI\mt\example_z3d_data\from_z3d.h5