Skip to content

Commit

Permalink
Udpdate channel nomenclature to be in config
Browse files Browse the repository at this point in the history
-Added ChannelNomenclature and channel_nomenclature to config
-weave ChannelNomenclature class into synthetic tests
-added methods for setting default input/output/reference channels to processing
 config (may need mod for 4 channel stations)
-changed channel_nomenclature from kwarg to ard in process_mth5
-modified TTFZ to use ChannelNomenclature class
-removed dependencies on aurora.channel_nomenclature

[Issue(s): #74]
  • Loading branch information
kkappler committed Aug 6, 2022
1 parent d67aca2 commit ce61f0d
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 141 deletions.
64 changes: 0 additions & 64 deletions aurora/channel_nomenclature.py

This file was deleted.

2 changes: 2 additions & 0 deletions aurora/config/metadata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .window import Window
from .station import Station
from .channel import Channel
from .channel_nomenclature import ChannelNomenclature
from .run import Run
from .stations import Stations
from .band import Band
Expand All @@ -14,6 +15,7 @@
"Window",
"Station",
"Channel",
"ChannelNomenclature",
"Run",
"Stations",
"Band",
Expand Down
26 changes: 25 additions & 1 deletion aurora/config/metadata/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
from mt_metadata.base import get_schema, Base
from .standards import SCHEMA_FN_PATHS

from . import DecimationLevel, Stations, Band
from . import DecimationLevel, Stations, Band, ChannelNomenclature


# =============================================================================
attr_dict = get_schema("processing", SCHEMA_FN_PATHS)
attr_dict.add_dict(Stations()._attr_dict, "stations")
attr_dict.add_dict(ChannelNomenclature()._attr_dict, "channel_nomenclature")


# =============================================================================
class Processing(Base):
Expand All @@ -28,6 +30,7 @@ def __init__(self, **kwargs):

self.stations = Stations()
self._decimations = []
self.channel_nomenclature = ChannelNomenclature()

super().__init__(attr_dict=attr_dict, **kwargs)

Expand Down Expand Up @@ -179,6 +182,27 @@ def drop_reference_channels(self):
decimation.reference_channels = []
return

def set_input_channels(self, channels):
for decimation in self.decimations:
decimation.input_channels = channels

def set_output_channels(self, channels):
for decimation in self.decimations:
decimation.output_channels = channels

def set_reference_channels(self, channels):
for decimation in self.decimations:
decimation.reference_channels = channels

def set_default_input_output_channels(self):
self.set_input_channels(self.channel_nomenclature.default_input_channels)
self.set_output_channels(self.channel_nomenclature.default_output_channels)

def set_default_reference_channels(self):
self.set_reference_channels(
self.channel_nomenclature.default_reference_channels
)

def validate(self):
"""
Placeholder. Some of the checks and methods here maybe better placed in
Expand Down
11 changes: 0 additions & 11 deletions aurora/config/metadata/standards/processing.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,5 @@
"alias": [],
"example": "0",
"default": null
},
"channel_nomenclature": {
"type": "string",
"required": true,
"style": "free form",
"units": null,
"description": "key to a dict of how channels are named",
"options": [],
"alias": [],
"example": "LEMI12",
"default": "default"
}
}
8 changes: 3 additions & 5 deletions aurora/pipelines/process_mth5.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ def process_tf_decimation_level(

def export_tf(
tf_collection,
channel_nomenclature,
station_metadata_dict={},
survey_dict={},
channel_nomenclature="default",
):
"""
This method may wind up being embedded in the TF class
Expand Down Expand Up @@ -429,9 +429,7 @@ def process_mth5(
local_merged_stft_obj,
remote_merged_stft_obj,
)
tf_obj.apparent_resistivity(
units=units, channel_nomenclature=processing_config.channel_nomenclature
)
tf_obj.apparent_resistivity(processing_config.channel_nomenclature, units=units)
tf_dict[i_dec_level] = tf_obj

if show_plot:
Expand Down Expand Up @@ -476,9 +474,9 @@ def process_mth5(

tf_cls = export_tf(
tf_collection,
processing_config.channel_nomenclature,
station_metadata_dict=station_metadata.to_dict(),
survey_dict=survey_dict,
channel_nomenclature=processing_config.channel_nomenclature,
)
close_mths_objs(dataset_df)
return tf_cls
6 changes: 4 additions & 2 deletions aurora/test_utils/synthetic/make_mth5_from_asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mth5.timeseries import ChannelTS, RunTS
from mth5.mth5 import MTH5

from aurora.channel_nomenclature import map_channels
from aurora.config.metadata.channel_nomenclature import ChannelNomenclature
from aurora.test_utils.synthetic.synthetic_station_config import make_filters
from aurora.test_utils.synthetic.synthetic_station_config import make_station_01
from aurora.test_utils.synthetic.synthetic_station_config import make_station_02
Expand All @@ -44,7 +44,9 @@ def create_run_ts_from_synthetic_run(run, df, channel_nomenclature="default"):
-------
"""
EX, EY, HX, HY, HZ = map_channels(channel_nomenclature)
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
Expand Down
43 changes: 14 additions & 29 deletions aurora/test_utils/synthetic/make_processing_configs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from aurora.channel_nomenclature import map_channels
from aurora.config import BANDS_DEFAULT_FILE
from aurora.config import BANDS_256_FILE
from aurora.config.config_creator import ConfigCreator
Expand Down Expand Up @@ -28,21 +27,16 @@ def create_test_run_config(
"""
EX, EY, HX, HY, HZ = map_channels(channel_nomenclature)
estimation_engine = "RME"
local_station_id = test_case_id
remote_station_id = ""
reference_channels = []
input_channels = [HX, HY]
output_channels = [HZ, EX, EY]

if test_case_id == "test1r2":
estimation_engine = "RME_RR"
reference_channels = [HX, HY]
local_station_id = "test1"
remote_station_id = "test2"
if test_case_id == "test2r1":
estimation_engine = "RME_RR"
reference_channels = [HX, HY]
local_station_id = "test2"
remote_station_id = "test1"

Expand All @@ -67,40 +61,31 @@ def create_test_run_config(
if test_case_id in ["test1", "test2"]:
p = cc.create_run_processing_object(
emtf_band_file=emtf_band_setup_file,
input_channels=input_channels,
output_channels=output_channels,
)
p.id = config_id
p.channel_nomenclature = channel_nomenclature
p.stations.from_dataset_dataframe(ds_df)

for decimation in p.decimations:
decimation.estimator.engine = estimation_engine
decimation.window.type = "hamming"
decimation.window.num_samples = num_samples_window
decimation.window.overlap = num_samples_overlap
decimation.regression.max_redescending_iterations = 2

p.channel_nomenclature.keyword = channel_nomenclature
p.set_default_input_output_channels()
p.drop_reference_channels()
p.stations.from_dataset_dataframe(ds_df)

elif test_case_id in ["test2r1", "test1r2"]:
config_id = f"{config_id}-RR{remote_station_id}"
p = cc.create_run_processing_object(
emtf_band_file=emtf_band_setup_file,
input_channels=input_channels,
output_channels=output_channels,
)
p.id = config_id
p.channel_nomenclature = channel_nomenclature
p.id = config_id
p.channel_nomenclature.keyword = channel_nomenclature
p.set_default_input_output_channels()
p.set_default_reference_channels()
p.stations.from_dataset_dataframe(ds_df)

for decimation in p.decimations:
decimation.estimator.engine = estimation_engine
decimation.window.type = "hamming"
decimation.window.num_samples = num_samples_window
decimation.window.overlap = num_samples_overlap
decimation.regression.max_redescending_iterations = 2
decimation.reference_channels = reference_channels
for decimation in p.decimations:
decimation.estimator.engine = estimation_engine
decimation.window.type = "hamming"
decimation.window.num_samples = num_samples_window
decimation.window.overlap = num_samples_overlap
decimation.regression.max_redescending_iterations = 2

if save == "json":
cc.to_json(p)
Expand Down
32 changes: 24 additions & 8 deletions aurora/test_utils/synthetic/synthetic_station_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import numpy as np
import random

from aurora.config.metadata.channel_nomenclature import ChannelNomenclature
from aurora.test_utils.synthetic.paths import DATA_PATH
from aurora.time_series.filters.filter_helpers import make_coefficient_filter

from aurora.channel_nomenclature import get_channel_map
from aurora.channel_nomenclature import map_channels

random.seed(0)


Expand Down Expand Up @@ -61,7 +59,13 @@ def __init__(self, id, **kwargs):
self.id = id
self.sample_rate = kwargs.get("sample_rate", 1.0)
self.raw_data_path = kwargs.get("raw_data_path", None)
self.channel_nomenclature = kwargs.get("channel_nomenclature", "default")

# set channel_map
self._channel_map = None
self.channel_nomemclature_keyword = kwargs.get(
"channel_nomenclature", "default"
)
self.set_channel_map()
self.channels = kwargs.get("channels", list(self.channel_map.values()))
self.noise_scalars = kwargs.get("noise_scalars", None)
self.nan_indices = kwargs.get("nan_indices", {})
Expand All @@ -74,7 +78,15 @@ def __init__(self, id, **kwargs):

@property
def channel_map(self):
return get_channel_map(self.channel_nomenclature)
return self._channel_map

def set_channel_map(self):
channel_nomenclature = ChannelNomenclature()
channel_nomenclature.keyword = self.channel_nomemclature_keyword
channel_map = channel_nomenclature.get_channel_map(
self.channel_nomemclature_keyword
)
self._channel_map = channel_map


class SyntheticStation(object):
Expand All @@ -92,7 +104,9 @@ def __init__(self, id, **kwargs):


def make_station_01(channel_nomenclature="default"):
EX, EY, HX, HY, HZ = map_channels(channel_nomenclature)
channel_nomenclature_obj = ChannelNomenclature()
channel_nomenclature_obj.keyword = channel_nomenclature
EX, EY, HX, HY, HZ = channel_nomenclature_obj.unpack()
station = SyntheticStation("test1")
station.mth5_path = DATA_PATH.joinpath("test1.h5")

Expand Down Expand Up @@ -141,10 +155,12 @@ def make_station_02(channel_nomenclature="default"):


def make_station_03(channel_nomenclature="default"):
EX, EY, HX, HY, HZ = map_channels(channel_nomenclature)
channel_nomenclature_obj = ChannelNomenclature()
channel_nomenclature_obj.keyword = channel_nomenclature
EX, EY, HX, HY, HZ = channel_nomenclature_obj.unpack()
station = SyntheticStation("test3")
station.mth5_path = DATA_PATH.joinpath("test3.h5")
channels = list(get_channel_map(channel_nomenclature).values())
channels = channel_nomenclature_obj.channels

nan_indices = {}
for ch in channels:
Expand Down
13 changes: 5 additions & 8 deletions aurora/transfer_function/TTFZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

from aurora.transfer_function.base import TransferFunction

# from mt_metadata.transfer_functions.channel_nomenclature import map_channels
from aurora.channel_nomenclature import map_channels


class TTFZ(TransferFunction):
"""
Expand All @@ -26,7 +23,7 @@ class TTFZ(TransferFunction):
def __init__(self, *args, **kwargs):
super(TTFZ, self).__init__(*args, **kwargs)

def apparent_resistivity(self, units="SI", channel_nomenclature="default"):
def apparent_resistivity(self, channel_nomenclature, units="SI"):
"""
ap_res(...) : computes app. res., phase, errors, given imped., cov.
%USAGE: [rho,rho_se,ph,ph_se] = ap_res(z,sig_s,sig_e,periods) ;
Expand All @@ -39,12 +36,12 @@ def apparent_resistivity(self, units="SI", channel_nomenclature="default"):
----------
units: str
one of ["MT","SI"]
channel_nomenclature: str
free form, but normally the mt_acquisition system ["MT","SI"]
channel_nomenclature:
aurora.config.metadata.channel_nomenclature.ChannelNomenclature
has a dict that you
"""

ex, ey, hx, hy, hz = map_channels(channel_nomenclature)
ex, ey, hx, hy, hz = channel_nomenclature.unpack()
rad_deg = 180 / np.pi
# off - diagonal impedances
self.rho = np.zeros((self.num_bands, 2))
Expand Down
Loading

0 comments on commit ce61f0d

Please sign in to comment.