Skip to content

Commit

Permalink
cleanup and bug fix
Browse files Browse the repository at this point in the history
- Now that the actual Run class is being used, needed to update  test
  metadat set correctly to use correct syntax.
  • Loading branch information
kkappler committed Jun 8, 2024
1 parent 030dddb commit 0f8bdb1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
28 changes: 7 additions & 21 deletions aurora/test_utils/synthetic/make_mth5_from_asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
from loguru import logger
from mth5.mth5 import MTH5
from mth5.timeseries import ChannelTS, RunTS
import mt_metadata.timeseries as metadata_ts
from mt_metadata.transfer_functions.processing.aurora import ChannelNomenclature
from mt_metadata.timeseries import Channel
from mt_metadata.timeseries import Electric
from mt_metadata.timeseries import Magnetic
from mth5.utils.helpers import add_filters
Expand Down Expand Up @@ -71,40 +69,29 @@ def create_run_ts_from_synthetic_run(run, df, channel_nomenclature="default"):
-------
"""
# meta_classes = dict(inspect.getmembers(metadata_ts, inspect.isclass))

channel_nomenclature_obj = ChannelNomenclature()
channel_nomenclature_obj.keyword = channel_nomenclature
EX, EY, HX, HY, HZ = channel_nomenclature_obj.unpack()
ch_list = []
for col in df.columns:

data = df[col].values
# meta_dict = {
# "component": col,
# "sample_rate": run.run_metadata.sample_rate,
# "filter.name": run.filters[col],
# "filter.applied": len(run.filters[col])
# * [
# True,
# ],
# "time_period.start": run.start,
# }
if col in [EX, EY]:
if col in channel_nomenclature_obj.ex_ey:
channel_metadata = Electric()
channel_metadata.component = col
channel_metadata.units = "millivolts per kilometer"
chts = ChannelTS(
channel_type="electric",
data=data,
channel_metadata=channel_metadata.to_dict(), # ["electric"],
channel_metadata=channel_metadata.to_dict(),
)

# add metadata to the channel here
chts.channel_metadata.dipole_length = 50
if col == EY:
if col == channel_nomenclature_obj.ey:
chts.channel_metadata.measurement_azimuth = 90.0

elif col in [HX, HY, HZ]:
elif col in channel_nomenclature_obj.hx_hy_hz:
channel_metadata = Magnetic()
channel_metadata.units = "nanotesla"
channel_metadata.component = col
Expand All @@ -116,11 +103,11 @@ def create_run_ts_from_synthetic_run(run, df, channel_nomenclature="default"):
chts = ChannelTS(
channel_type=channel_metadata.type,
data=data,
channel_metadata=channel_metadata.to_dict()["magnetic"],
channel_metadata=channel_metadata.to_dict(),
)
chts.component = col

if col == HY:
if col == channel_nomenclature_obj.ey:
chts.channel_metadata.measurement_azimuth = 90.0

chts.channel_metadata.component = col
Expand Down Expand Up @@ -271,7 +258,6 @@ def update_mth5_path(mth5_path, add_nan_values, channel_nomenclature):
station_group = m.add_station(station_cfg.id, survey=survey_id)

for run in station_cfg.runs:
# station_obj = m.get_station(station_cfg.id, survey_id)
df = get_time_series_dataframe(run, source_folder, add_nan_values)

# cast to run_ts
Expand Down
25 changes: 17 additions & 8 deletions aurora/test_utils/synthetic/station_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ class SyntheticStation(object):
"""
Class used to contain information needed to generate MTH5 file from synthetic data.
TODO: could add channel_nomenclature to this obj (instead of run, say) and clean
things up somewhat. ... i.e. include the channel_map() property etc.
TODO: This looks like a "dataclass"
TODO: could add channel_nomenclature to this obj (instead of run) but would need to decide that
runs cannot change channel nomenclature first. If that were decided, the channel_map() could go here as well.
"""

Expand Down Expand Up @@ -206,6 +205,17 @@ def make_station_01(channel_nomenclature="default"):


def make_station_02(channel_nomenclature="default"):
"""
Just like station 1, but the data are different
Parameters
----------
channel_nomenclature
Returns
-------
"""
test2 = make_station_01(channel_nomenclature=channel_nomenclature)
test2.id = "test2"
test2.mth5_name = "test2.h5"
Expand All @@ -219,8 +229,9 @@ def make_station_02(channel_nomenclature="default"):

def make_station_03(channel_nomenclature="default"):
"""
Here we create a synthetic station with multiple runs. Rather than generate fresh
Create a synthetic station with multiple runs. Rather than generate fresh
synthetic data, we just reuse test1.asc for each run.
Parameters
----------
channel_nomenclature: str
Expand All @@ -235,7 +246,6 @@ def make_station_03(channel_nomenclature="default"):
"""
channel_nomenclature_obj = ChannelNomenclature()
channel_nomenclature_obj.keyword = channel_nomenclature
EX, EY, HX, HY, HZ = channel_nomenclature_obj.unpack()
station = SyntheticStation("test3")
station.mth5_name = "test3.h5"
channels = channel_nomenclature_obj.channels
Expand All @@ -246,11 +256,11 @@ def make_station_03(channel_nomenclature="default"):

filters = {}
for ch in channels:
if ch in [EX, EY]:
if ch in channel_nomenclature_obj.ex_ey:
filters[ch] = [
FILTERS["1x"].name,
]
elif ch in [HX, HY, HZ]:
elif ch in channel_nomenclature_obj.hx_hy_hz:
filters[ch] = [FILTERS["10x"].name, FILTERS["0.1x"].name]

run_001 = SyntheticRun(
Expand Down Expand Up @@ -315,7 +325,6 @@ def make_station_04(channel_nomenclature="default"):
station_metadata.id = "test1"
channel_nomenclature_obj = ChannelNomenclature()
channel_nomenclature_obj.keyword = channel_nomenclature
EX, EY, HX, HY, HZ = channel_nomenclature_obj.unpack()

station = SyntheticStation("test1")
station.mth5_name = "test_04_8Hz.h5"
Expand Down
4 changes: 3 additions & 1 deletion tests/synthetic/test_metadata_values_set_correctly.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def test_start_times_correct(self):
run_summary
station_03 = make_station_03()
for run in station_03.runs:
summary_row = run_summary.df[run_summary.df.run_id == run.id].iloc[0]
summary_row = run_summary.df[
run_summary.df.run_id == run.run_metadata.id
].iloc[0]
assert summary_row.start == pd.Timestamp(run.start)


Expand Down

0 comments on commit 0f8bdb1

Please sign in to comment.