diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7e6b5e1e..23466a91 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,7 +34,7 @@ jobs: python --version conda install -c conda-forge pytest pytest-cov certifi">=2017.4.17" pandoc pip install -r requirements-dev.txt - pip install git+https://github.com/kujaku11/mt_metadata.git + pip install git+https://github.com/kujaku11/mt_metadata.git@fix_issue_91 pip install git+https://github.com/kujaku11/mth5.git #@branch_name - name: Install Our Package diff --git a/aurora/channel_nomenclature.py b/aurora/channel_nomenclature.py new file mode 100644 index 00000000..33b46c4b --- /dev/null +++ b/aurora/channel_nomenclature.py @@ -0,0 +1,64 @@ +""" +2022-07-31 +prototype module to enable handling of channel names that depart from the usual +hexy convention. + +""" + +DEFAULT_CHANNEL_MAP = { + "hx": "hx", + "hy": "hy", + "hz": "hz", + "ex": "ex", + "ey": "ey", +} + +LEMI_CHANNEL_MAP_12 = { + "hx": "bx", + "hy": "by", + "hz": "bz", + "ex": "e1", + "ey": "e2", +} + +LEMI_CHANNEL_MAP_34 = { + "hx": "bx", + "hy": "by", + "hz": "bz", + "ex": "e3", + "ey": "e4", +} + +THE_BEATLES = { + "hx": "john", + "hy": "paul", + "hz": "george", + "ex": "ringo", + "ey": "the fifth beatle", +} + + +def get_channel_map(mt_system): + if mt_system == "LEMI12": + channel_map = LEMI_CHANNEL_MAP_12 + elif mt_system == "LEMI34": + channel_map = LEMI_CHANNEL_MAP_34 + elif mt_system == "NIMS": + channel_map = DEFAULT_CHANNEL_MAP + elif mt_system == "beatles": + channel_map = THE_BEATLES + else: + print(f"whoops mt_system {mt_system} unknown") + channel_map = DEFAULT_CHANNEL_MAP + # raise NotImplementedError + return channel_map + + +def map_channels(mt_system): + channel_map = get_channel_map(mt_system) + ex = channel_map["ex"] + ey = channel_map["ey"] + hx = channel_map["hx"] + hy = channel_map["hy"] + hz = channel_map["hz"] + return ex, ey, hx, hy, hz diff --git a/aurora/config/metadata/standards/processing.json b/aurora/config/metadata/standards/processing.json index 8a394b36..980ac7d7 100644 --- a/aurora/config/metadata/standards/processing.json +++ b/aurora/config/metadata/standards/processing.json @@ -20,5 +20,16 @@ "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" } } \ No newline at end of file diff --git a/aurora/pipelines/process_mth5.py b/aurora/pipelines/process_mth5.py index 1ac324e2..8e877d0b 100644 --- a/aurora/pipelines/process_mth5.py +++ b/aurora/pipelines/process_mth5.py @@ -197,11 +197,15 @@ def process_tf_decimation_level( config, i_dec_level, local_stft_obj, remote_stft_obj, transfer_function_obj ) - transfer_function_obj.apparent_resistivity(units=units) return transfer_function_obj -def export_tf(tf_collection, station_metadata_dict={}, survey_dict={}): +def export_tf( + tf_collection, + station_metadata_dict={}, + survey_dict={}, + channel_nomenclature="default", +): """ This method may wind up being embedded in the TF class Assign transfer_function, residual_covariance, inverse_signal_power, station, survey @@ -218,9 +222,8 @@ def export_tf(tf_collection, station_metadata_dict={}, survey_dict={}): tf_cls: mt_metadata.transfer_functions.core.TF Transfer function container """ - merged_tf_dict = tf_collection.get_merged_dict() - tf_cls = TF() - # Transfer Function + merged_tf_dict = tf_collection.get_merged_dict(channel_nomenclature) + tf_cls = TF(channel_nomenclature=channel_nomenclature) renamer_dict = {"output_channel": "output", "input_channel": "input"} tmp = merged_tf_dict["tf"].rename(renamer_dict) tf_cls.transfer_function = tmp @@ -425,9 +428,10 @@ def process_mth5( i_dec_level, local_merged_stft_obj, remote_merged_stft_obj, - units=units, ) - + tf_obj.apparent_resistivity( + units=units, channel_nomenclature=processing_config.channel_nomenclature + ) tf_dict[i_dec_level] = tf_obj if show_plot: @@ -474,6 +478,7 @@ def process_mth5( tf_collection, 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 diff --git a/aurora/test_utils/synthetic/make_mth5_from_asc.py b/aurora/test_utils/synthetic/make_mth5_from_asc.py index 718750c0..d71f6a7c 100644 --- a/aurora/test_utils/synthetic/make_mth5_from_asc.py +++ b/aurora/test_utils/synthetic/make_mth5_from_asc.py @@ -13,21 +13,21 @@ import numpy as np from pathlib import Path -from random import seed + import pandas as pd from mth5.timeseries import ChannelTS, RunTS from mth5.mth5 import MTH5 +from aurora.channel_nomenclature import map_channels 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 from aurora.test_utils.synthetic.synthetic_station_config import make_station_03 - -seed(0) +np.random.seed(0) -def create_run_ts_from_synthetic_run(run, df): +def create_run_ts_from_synthetic_run(run, df, channel_nomenclature="default"): """ Loop over stations and make ChannelTS objects. Need to add a tag in the channels @@ -44,11 +44,12 @@ def create_run_ts_from_synthetic_run(run, df): ------- """ + EX, EY, HX, HY, HZ = map_channels(channel_nomenclature) ch_list = [] for col in df.columns: data = df[col].values - if col in ["ex", "ey"]: + if col in [EX, EY]: meta_dict = { "component": col, "sample_rate": run.sample_rate, @@ -59,10 +60,10 @@ def create_run_ts_from_synthetic_run(run, df): ) # add metadata to the channel here chts.channel_metadata.dipole_length = 50 - if col == "ey": + if col == EY: chts.channel_metadata.measurement_azimuth = 90.0 - elif col in ["hx", "hy", "hz"]: + elif col in [HX, HY, HZ]: meta_dict = { "component": col, "sample_rate": run.sample_rate, @@ -71,7 +72,7 @@ def create_run_ts_from_synthetic_run(run, df): chts = ChannelTS( channel_type="magnetic", data=data, channel_metadata=meta_dict ) - if col == "hy": + if col == HY: chts.channel_metadata.measurement_azimuth = 90.0 ch_list.append(chts) @@ -86,7 +87,12 @@ def create_run_ts_from_synthetic_run(run, df): def create_mth5_synthetic_file( - station_cfgs, mth5_path, plot=False, add_nan_values=False, file_version="0.1.0" + station_cfgs, + mth5_path, + plot=False, + add_nan_values=False, + file_version="0.1.0", + channel_nomenclature="default", ): """ @@ -135,7 +141,9 @@ def create_mth5_synthetic_file( df[col].loc[ndx : ndx + num_nan] = np.nan # cast to run_ts - runts = create_run_ts_from_synthetic_run(run, df) + runts = create_run_ts_from_synthetic_run( + run, df, channel_nomenclature=channel_nomenclature + ) runts.station_metadata.id = station_cfg.id # plot the data @@ -162,8 +170,8 @@ def create_mth5_synthetic_file( return mth5_path -def create_test1_h5(file_version="0.1.0"): - station_01_params = make_station_01() +def create_test1_h5(file_version="0.1.0", channel_nomenclature="default"): + station_01_params = make_station_01(channel_nomenclature=channel_nomenclature) mth5_path = station_01_params.mth5_path # DATA_PATH.joinpath("test1.h5") mth5_path = create_mth5_synthetic_file( [ @@ -172,12 +180,13 @@ def create_test1_h5(file_version="0.1.0"): mth5_path, plot=False, file_version=file_version, + channel_nomenclature=channel_nomenclature, ) return mth5_path -def create_test2_h5(file_version="0.1.0"): - station_02_params = make_station_02() +def create_test2_h5(file_version="0.1.0", channel_nomenclature="default"): + station_02_params = make_station_02(channel_nomenclature=channel_nomenclature) mth5_path = station_02_params.mth5_path mth5_path = create_mth5_synthetic_file( [ @@ -190,8 +199,8 @@ def create_test2_h5(file_version="0.1.0"): return mth5_path -def create_test1_h5_with_nan(file_version="0.1.0"): - station_01_params = make_station_01() +def create_test1_h5_with_nan(file_version="0.1.0", channel_nomenclature="default"): + station_01_params = make_station_01(channel_nomenclature=channel_nomenclature) mth5_path = station_01_params.mth5_path # DATA_PATH.joinpath("test1.h5") mth5_path = create_mth5_synthetic_file( [ @@ -205,19 +214,22 @@ def create_test1_h5_with_nan(file_version="0.1.0"): return mth5_path -def create_test12rr_h5(file_version="0.1.0"): - station_01_params = make_station_01() - station_02_params = make_station_02() +def create_test12rr_h5(file_version="0.1.0", channel_nomenclature="default"): + station_01_params = make_station_01(channel_nomenclature=channel_nomenclature) + station_02_params = make_station_02(channel_nomenclature=channel_nomenclature) station_params = [station_01_params, station_02_params] mth5_path = station_01_params.mth5_path.__str__().replace("test1.h5", "test12rr.h5") mth5_path = create_mth5_synthetic_file( - station_params, mth5_path, file_version=file_version + station_params, + mth5_path, + file_version=file_version, + channel_nomenclature=channel_nomenclature, ) return mth5_path -def create_test3_h5(file_version="0.1.0"): - station_params = make_station_03() +def create_test3_h5(file_version="0.1.0", channel_nomenclature="default"): + station_params = make_station_03(channel_nomenclature=channel_nomenclature) mth5_path = create_mth5_synthetic_file( [ station_params, diff --git a/aurora/test_utils/synthetic/make_processing_configs.py b/aurora/test_utils/synthetic/make_processing_configs.py index 3364e4ab..5630be8f 100644 --- a/aurora/test_utils/synthetic/make_processing_configs.py +++ b/aurora/test_utils/synthetic/make_processing_configs.py @@ -1,3 +1,4 @@ +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 @@ -5,7 +6,13 @@ from aurora.test_utils.synthetic.paths import DATA_PATH -def create_test_run_config(test_case_id, ds_df, matlab_or_fortran="", save="json"): +def create_test_run_config( + test_case_id, + ds_df, + matlab_or_fortran="", + save="json", + channel_nomenclature="default", +): """ Use config creator to generate a processing config file for the synthetic data. @@ -21,18 +28,21 @@ def create_test_run_config(test_case_id, ds_df, matlab_or_fortran="", save="json """ + 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"] + 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"] + reference_channels = [HX, HY] local_station_id = "test2" remote_station_id = "test1" @@ -55,8 +65,13 @@ def create_test_run_config(test_case_id, ds_df, matlab_or_fortran="", save="json cc = ConfigCreator(config_path=CONFIG_PATH) if test_case_id in ["test1", "test2"]: - p = cc.create_run_processing_object(emtf_band_file=emtf_band_setup_file) + 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: @@ -70,8 +85,13 @@ def create_test_run_config(test_case_id, ds_df, matlab_or_fortran="", save="json 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) + 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: diff --git a/aurora/test_utils/synthetic/synthetic_station_config.py b/aurora/test_utils/synthetic/synthetic_station_config.py index 2b440fd6..b2d47e1c 100644 --- a/aurora/test_utils/synthetic/synthetic_station_config.py +++ b/aurora/test_utils/synthetic/synthetic_station_config.py @@ -21,6 +21,9 @@ 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) @@ -52,11 +55,14 @@ def make_filters(as_list=False): class SyntheticRun(object): + """ """ + 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.channels = kwargs.get("channels", ["hx", "hy", "hz", "ex", "ey"]) + self.channel_nomenclature = kwargs.get("channel_nomenclature", "default") + 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", {}) self.filters = kwargs.get("filters", {}) @@ -66,8 +72,18 @@ def __init__(self, id, **kwargs): for channel in self.channels: self.noise_scalars[channel] = 0.0 # np.random.rand(1) + @property + def channel_map(self): + return get_channel_map(self.channel_nomenclature) + class SyntheticStation(object): + """ + TODO: could add channel_nomenclature to this obj (instead of run, say) and clean + things up somewhat. ... i.e. inclde the channel_map() property etc. + + """ + def __init__(self, id, **kwargs): self.id = id self.latitude = kwargs.get("latitude", 0.0) @@ -75,31 +91,33 @@ def __init__(self, id, **kwargs): self.mth5_path = kwargs.get("mth5_path", None) # not always used -def make_station_01(): +def make_station_01(channel_nomenclature="default"): + EX, EY, HX, HY, HZ = map_channels(channel_nomenclature) station = SyntheticStation("test1") station.mth5_path = DATA_PATH.joinpath("test1.h5") run_001 = SyntheticRun( "001", raw_data_path=DATA_PATH.joinpath("test1.asc"), + channel_nomenclature=channel_nomenclature, ) nan_indices = {} for ch in run_001.channels: nan_indices[ch] = [] - if ch == "hx": + if ch == HX: nan_indices[ch].append([11, 100]) - if ch == "hy": + if ch == HY: nan_indices[ch].append([11, 100]) nan_indices[ch].append([20000, 444]) run_001.nan_indices = nan_indices filters = {} for ch in run_001.channels: - if ch in ["ex", "ey"]: + if ch in [EX, EY]: filters[ch] = [ FILTERS["1x"].name, ] - elif ch in ["hx", "hy", "hz"]: + elif ch in [HX, HY, HZ]: filters[ch] = [FILTERS["10x"].name, FILTERS["0.1x"].name] run_001.filters = filters @@ -110,8 +128,8 @@ def make_station_01(): return station -def make_station_02(): - test2 = make_station_01() +def make_station_02(channel_nomenclature="default"): + test2 = make_station_01(channel_nomenclature=channel_nomenclature) test2.mth5_path = DATA_PATH.joinpath("test2.h5") test2.id = "test2" test2.runs[0].raw_data_path = DATA_PATH.joinpath("test2.asc") @@ -122,10 +140,11 @@ def make_station_02(): return test2 -def make_station_03(): +def make_station_03(channel_nomenclature="default"): + EX, EY, HX, HY, HZ = map_channels(channel_nomenclature) station = SyntheticStation("test3") station.mth5_path = DATA_PATH.joinpath("test3.h5") - channels = ["hx", "hy", "hz", "ex", "ey"] + channels = list(get_channel_map(channel_nomenclature).values()) nan_indices = {} for ch in channels: @@ -133,11 +152,11 @@ def make_station_03(): filters = {} for ch in channels: - if ch in ["ex", "ey"]: + if ch in [EX, EY]: filters[ch] = [ FILTERS["1x"].name, ] - elif ch in ["hx", "hy", "hz"]: + elif ch in [HX, HY, HZ]: filters[ch] = [FILTERS["10x"].name, FILTERS["0.1x"].name] run_001 = SyntheticRun( @@ -145,6 +164,7 @@ def make_station_03(): raw_data_path=DATA_PATH.joinpath("test1.asc"), nan_indices=nan_indices, filters=filters, + channel_nomenclature=channel_nomenclature, ) noise_scalars = {} @@ -156,6 +176,7 @@ def make_station_03(): noise_scalars=noise_scalars, nan_indices=nan_indices, filters=filters, + channel_nomenclature=channel_nomenclature, ) for ch in channels: @@ -166,6 +187,7 @@ def make_station_03(): noise_scalars=noise_scalars, nan_indices=nan_indices, filters=filters, + channel_nomenclature=channel_nomenclature, ) for ch in channels: @@ -176,6 +198,7 @@ def make_station_03(): noise_scalars=noise_scalars, nan_indices=nan_indices, filters=filters, + channel_nomenclature=channel_nomenclature, ) run_001.filters = filters diff --git a/aurora/transfer_function/TTFZ.py b/aurora/transfer_function/TTFZ.py index ec2d769f..3d81bf64 100644 --- a/aurora/transfer_function/TTFZ.py +++ b/aurora/transfer_function/TTFZ.py @@ -6,6 +6,9 @@ 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): """ @@ -23,7 +26,7 @@ class TTFZ(TransferFunction): def __init__(self, *args, **kwargs): super(TTFZ, self).__init__(*args, **kwargs) - def apparent_resistivity(self, units="SI"): + def apparent_resistivity(self, units="SI", channel_nomenclature="default"): """ 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) ; @@ -31,23 +34,29 @@ def apparent_resistivity(self, units="SI"): % sig_s = inverse signal covariance matrix (from Z_****** file) % sig_e = residual covariance matrix (from Z_****** file) % periods = array of periods (sec) - Returns - ------- + + Parameters + ---------- + units: str + one of ["MT","SI"] + channel_nomenclature: str + free form, but normally the mt_acquisition system ["MT","SI"] """ + ex, ey, hx, hy, hz = map_channels(channel_nomenclature) rad_deg = 180 / np.pi # off - diagonal impedances self.rho = np.zeros((self.num_bands, 2)) self.rho_se = np.zeros((self.num_bands, 2)) self.phi = np.zeros((self.num_bands, 2)) self.phi_se = np.zeros((self.num_bands, 2)) - Zxy = self.tf.loc["ex", "hy", :].data - Zyx = self.tf.loc["ey", "hx", :].data + Zxy = self.tf.loc[ex, hy, :].data + Zyx = self.tf.loc[ey, hx, :].data # standard deviation of real and imaginary parts of impedance - Zxy_se = self.standard_error().loc["ex", "hy", :].data / np.sqrt(2) - Zyx_se = self.standard_error().loc["ey", "hx", :].data / np.sqrt(2) + Zxy_se = self.standard_error().loc[ex, hy, :].data / np.sqrt(2) + Zyx_se = self.standard_error().loc[ey, hx, :].data / np.sqrt(2) if units == "SI": rxy = 2e-7 * self.periods * (abs(Zxy) ** 2) diff --git a/aurora/transfer_function/transfer_function_collection.py b/aurora/transfer_function/transfer_function_collection.py index d752a212..adf53f47 100644 --- a/aurora/transfer_function/transfer_function_collection.py +++ b/aurora/transfer_function/transfer_function_collection.py @@ -20,6 +20,8 @@ from aurora.transfer_function.plot.rho_phi_helpers import plot_phi from aurora.transfer_function.plot.rho_phi_helpers import plot_rho +# from mt_metadata.transfer_functions.channel_nomenclature import map_channels +from aurora.channel_nomenclature import map_channels EMTF_REGRESSION_ENGINE_LABELS = {} EMTF_REGRESSION_ENGINE_LABELS["RME"] = "Robust Single station" @@ -90,11 +92,10 @@ def total_number_of_channels(self): def number_of_decimation_levels(self): return len(self.tf_dict) - def get_merged_dict(self): + def get_merged_dict(self, channel_nomenclature): output = {} self._merge_decimation_levels() - self.check_all_channels_present() - # self.relabel_merged_decimation_levels_for_export() + self.check_all_channels_present(channel_nomenclature) output["tf"] = self.merged_tf output["tf_xarray"] = self.labelled_tf output["cov_ss_inv"] = self.merged_cov_ss_inv @@ -153,11 +154,23 @@ def _merge_decimation_levels(self): return - def check_all_channels_present(self): - if "hz" not in self.merged_tf.output_channel.data.tolist(): + def check_all_channels_present(self, channel_nomenclature): + """ + + Parameters + ---------- + channel_nomenclature: str + How channels are named + + Returns + ------- + + """ + ex, ey, hx, hy, hz = map_channels(channel_nomenclature) + if hz not in self.merged_tf.output_channel.data.tolist(): output_channels_original = self.merged_tf.output_channel.data.tolist() output_channels = [f"tmp___{x}" for x in output_channels_original] - output_channels[0] = "hz" + output_channels[0] = hz tmp = self.merged_tf.copy(deep=True) tmp = tmp.assign_coords({"output_channel": output_channels}) tmp.data *= np.nan @@ -197,50 +210,6 @@ def check_all_channels_present(self): pass self.merged_cov_nn = cov_nn - def relabel_merged_decimation_levels_for_export(self): - """ - This method was specifcally related to issue #93, but may not be needed afterall - Returns - ------- - - """ - - if self.merged_tf is None: - self._merge_decimation_levels() - - # - tmp_tipper = self.merged_tf.sel(output_channel="hz") - tmp_tipper = tmp_tipper.reset_coords(drop="output_channel") - tmp_tipper = tmp_tipper.to_dataset("input_channel") - tf_xarray = tmp_tipper.rename({"hx": "tzx", "hy": "tzy"}) - - zxx = self.merged_tf.sel(output_channel="ex", input_channel="hx") - zxx = zxx.reset_coords(drop=["input_channel", "output_channel"]) - zxx = zxx.to_dataset(name="zxx") - if tf_xarray: - tf_xarray = tf_xarray.merge(zxx) - else: - tf_xarray = zxx - zxy = self.merged_tf.sel(output_channel="ex", input_channel="hy") - zxy = zxy.reset_coords(drop=["input_channel", "output_channel"]) - zxy = zxy.to_dataset(name="zxy") - tf_xarray = tf_xarray.merge(zxy) - - zyx = self.merged_tf.sel(output_channel="ey", input_channel="hx") - zyx = zyx.reset_coords(drop=["input_channel", "output_channel"]) - zyx = zyx.to_dataset(name="zyx") - tf_xarray = tf_xarray.merge(zyx) - - zyy = self.merged_tf.sel(output_channel="ey", input_channel="hy") - zyy = zyy.reset_coords(drop=["input_channel", "output_channel"]) - zyy = zyy.to_dataset(name="zyy") - tf_xarray = tf_xarray.merge(zyy) - self.labelled_tf = tf_xarray - - # - - return - def write_emtf_z_file(self, z_file_path, run_obj=None, orientation_strs=None): """ Could probably move this into EMTFUtils() class diff --git a/tests/synthetic/test_synthetic_driver.py b/tests/synthetic/test_synthetic_driver.py index 74919119..1c75872c 100644 --- a/tests/synthetic/test_synthetic_driver.py +++ b/tests/synthetic/test_synthetic_driver.py @@ -1,3 +1,4 @@ +from aurora.channel_nomenclature import map_channels from aurora.pipelines.run_summary import RunSummary from aurora.test_utils.synthetic.make_mth5_from_asc import create_test1_h5 from aurora.test_utils.synthetic.make_mth5_from_asc import create_test2_h5 @@ -44,6 +45,7 @@ def process_synthetic_1( test_simultaneous_regression=False, file_version="0.1.0", return_collection=True, + channel_nomenclature="default", ): """ @@ -62,7 +64,9 @@ def process_synthetic_1( tf_result: TransferFunctionCollection or mt_metadata.transfer_functions.TF Should change so that it is mt_metadata.TF (see Issue #143) """ - mth5_path = create_test1_h5(file_version=file_version) + mth5_path = create_test1_h5( + file_version=file_version, channel_nomenclature=channel_nomenclature + ) run_summary = RunSummary() run_summary.from_mth5s( [ @@ -83,7 +87,9 @@ def process_synthetic_1( else: tfk_dataset.df.drop(columns=["channel_scale_factors"], inplace=True) - processing_config = create_test_run_config("test1", tfk_dataset.df) + processing_config = create_test_run_config( + "test1", tfk_dataset.df, channel_nomenclature=channel_nomenclature + ) if test_simultaneous_regression: for decimation in processing_config.decimations: @@ -126,8 +132,8 @@ def process_synthetic_2(): return tfc -def process_synthetic_rr12(): - mth5_path = create_test12rr_h5() +def process_synthetic_rr12(channel_nomenclature="default", return_collection=True): + mth5_path = create_test12rr_h5(channel_nomenclature=channel_nomenclature) run_summary = RunSummary() run_summary.from_mth5s( [ @@ -136,8 +142,14 @@ def process_synthetic_rr12(): ) tfk_dataset = KernelDataset() tfk_dataset.from_run_summary(run_summary, "test1", "test2") - processing_config = create_test_run_config("test1r2", tfk_dataset.df) - tfc = process_sythetic_data(processing_config, tfk_dataset) + processing_config = create_test_run_config( + "test1r2", tfk_dataset.df, channel_nomenclature=channel_nomenclature + ) + tfc = process_sythetic_data( + processing_config, + tfk_dataset, + return_collection=return_collection, + ) return tfc @@ -163,6 +175,7 @@ def test_process_mth5(): # process_synthetic_1_with_nans() z_file_path = AURORA_RESULTS_PATH.joinpath("syn1.zss") + tf_collection = process_synthetic_1(z_file_path=z_file_path, file_version="0.1.0") tf_cls = process_synthetic_1( z_file_path=z_file_path, file_version="0.1.0", return_collection=False @@ -170,6 +183,23 @@ def test_process_mth5(): xml_file_base = "syn1_mth5-010.xml" xml_file_name = AURORA_RESULTS_PATH.joinpath(xml_file_base) tf_cls.write_tf_file(fn=xml_file_name, file_type="emtfxml") + + tf_collection = process_synthetic_1( + z_file_path=z_file_path, file_version="0.1.0", channel_nomenclature="LEMI12" + ) + + tf_cls = process_synthetic_1( + z_file_path=z_file_path, + file_version="0.1.0", + return_collection=False, + channel_nomenclature="LEMI12", + ) + xml_file_base = "syn1_mth5-010_LEMI.xml" + xml_file_name = AURORA_RESULTS_PATH.joinpath(xml_file_base) + tf_cls.write_tf_file( + fn=xml_file_name, file_type="emtfxml", channel_nomenclature="LEMI12" + ) + tf_cls = process_synthetic_1( z_file_path=z_file_path, file_version="0.2.0", return_collection=False ) @@ -184,6 +214,23 @@ def test_process_mth5(): ) tf_collection = process_synthetic_2() tf_collection = process_synthetic_rr12() + + tf_cls = process_synthetic_rr12( + channel_nomenclature="default", return_collection=False + ) + xml_file_base = "syn12rr_mth5-010.xml" + xml_file_name = AURORA_RESULTS_PATH.joinpath(xml_file_base) + tf_cls.write_tf_file( + fn=xml_file_name, file_type="emtfxml", channel_nomenclature="default" + ) + tf_cls = process_synthetic_rr12( + channel_nomenclature="LEMI34", return_collection=False + ) + xml_file_base = "syn12rr_mth5-010_LEMI34.xml" + xml_file_name = AURORA_RESULTS_PATH.joinpath(xml_file_base) + tf_cls.write_tf_file( + fn=xml_file_name, file_type="emtfxml", channel_nomenclature="LEMI34" + ) return tf_collection