From 76cdca132fa77b254082dd143450c3329a8bc108 Mon Sep 17 00:00:00 2001 From: "Karl N. Kappler" Date: Mon, 8 Jan 2024 17:22:16 -0800 Subject: [PATCH] one less arg into process_transfer_functions - the integer decimation level was not needed - this propagates to some other functions, that now take dec_level_cfg instead of config - only logic change was tfk validator now drops ref channels if no RR station --- aurora/pipelines/process_mth5.py | 13 ++++++++++--- aurora/pipelines/transfer_function_helpers.py | 8 +++----- aurora/pipelines/transfer_function_kernel.py | 8 +++++--- aurora/time_series/frequency_band_helpers.py | 5 ++--- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/aurora/pipelines/process_mth5.py b/aurora/pipelines/process_mth5.py index 9faf9ea2..15bb0174 100644 --- a/aurora/pipelines/process_mth5.py +++ b/aurora/pipelines/process_mth5.py @@ -39,6 +39,7 @@ # ============================================================================= + def make_stft_objects( processing_config, i_dec_level, run_obj, run_xrds, station_id, units="MT" ): @@ -122,6 +123,7 @@ def process_tf_decimation_level( Processing pipeline for a single decimation_level TODO: Add a check that the processing config sample rates agree with the data + TODO: Add units to local_stft_obj, remote_stft_obj sampling rates otherwise raise Exception This method can be single station or remote based on the process cfg @@ -146,9 +148,9 @@ def process_tf_decimation_level( """ frequency_bands = config.decimations[i_dec_level].frequency_bands_obj() transfer_function_obj = TTFZ(i_dec_level, frequency_bands, processing_config=config) - + dec_level_config = config.decimations[i_dec_level] transfer_function_obj = process_transfer_functions( - config, i_dec_level, local_stft_obj, remote_stft_obj, transfer_function_obj + dec_level_config, local_stft_obj, remote_stft_obj, transfer_function_obj ) return transfer_function_obj @@ -368,7 +370,12 @@ def process_mth5( run_obj.metadata.id = row.run_id stft_obj = make_stft_objects( - tfk.config, i_dec_level, run_obj, run_xrds, row.station_id, units, + tfk.config, + i_dec_level, + run_obj, + run_xrds, + row.station_id, + units, ) # Pack FCs into h5 save_fourier_coefficients( diff --git a/aurora/pipelines/transfer_function_helpers.py b/aurora/pipelines/transfer_function_helpers.py index 7e4513cf..2762332a 100644 --- a/aurora/pipelines/transfer_function_helpers.py +++ b/aurora/pipelines/transfer_function_helpers.py @@ -90,8 +90,7 @@ def select_channel(xrda, channel_label): def process_transfer_functions( - config, - i_dec_level, + dec_level_config, local_stft_obj, remote_stft_obj, transfer_function_obj, @@ -103,7 +102,7 @@ def process_transfer_functions( Parameters ---------- - config + dec_level_config local_stft_obj remote_stft_obj transfer_function_obj: aurora.transfer_function.TTFZ.TTFZ @@ -129,12 +128,11 @@ def process_transfer_functions( """ # PUT COHERENCE SORTING HERE IF WIDE BAND? - dec_level_config = config.decimations[i_dec_level] estimator_class = get_estimator_class(dec_level_config.estimator.engine) for band in transfer_function_obj.frequency_bands.bands(): iter_control = set_up_iter_control(dec_level_config) X, Y, RR = get_band_for_tf_estimate( - band, config, local_stft_obj, remote_stft_obj + band, dec_level_config, local_stft_obj, remote_stft_obj ) # if there are segment weights apply them here # if there are channel weights apply them here diff --git a/aurora/pipelines/transfer_function_kernel.py b/aurora/pipelines/transfer_function_kernel.py index 6236c532..28dfae13 100644 --- a/aurora/pipelines/transfer_function_kernel.py +++ b/aurora/pipelines/transfer_function_kernel.py @@ -2,8 +2,6 @@ import pandas as pd import psutil -from loguru import logger - from aurora.pipelines.helpers import initialize_config from aurora.pipelines.time_series_helpers import prototype_decimate from mth5.utils.exceptions import MTH5Error @@ -322,7 +320,9 @@ def make_processing_summary(self): df.dec_level.diff()[1:] == 1 ).all() # dec levels increment by 1 except AssertionError: - logger.info(f"Skipping {group} because decimation levels are messy.") + logger.info( + f"Skipping {group} because decimation levels are messy." + ) continue assert df.dec_factor.iloc[0] == 1 assert df.dec_level.iloc[0] == 0 @@ -396,12 +396,14 @@ def validate_processing(self): 1. The default estimation engine from the json file is "RME_RR", which is fine ( we expect to in general to do more RR processing than SS) but if there is only one station (no remote)then the RME_RR should be replaced by default with "RME". + - also if there is only one station, set reference channels to [] 2. make sure local station id is defined (correctly from kernel dataset) """ # Make sure a RR method is not being called for a SS config if not self.config.stations.remote: + self.config.drop_reference_channels() for decimation in self.config.decimations: if decimation.estimator.engine == "RME_RR": logger.info("No RR station specified, switching RME_RR to RME") diff --git a/aurora/time_series/frequency_band_helpers.py b/aurora/time_series/frequency_band_helpers.py index 6d0ac08e..2bc16e5b 100644 --- a/aurora/time_series/frequency_band_helpers.py +++ b/aurora/time_series/frequency_band_helpers.py @@ -2,7 +2,7 @@ from loguru import logger -def get_band_for_tf_estimate(band, config, local_stft_obj, remote_stft_obj): +def get_band_for_tf_estimate(band, dec_level_config, local_stft_obj, remote_stft_obj): """ Get data for TF estimation for a particular band. @@ -28,13 +28,12 @@ def get_band_for_tf_estimate(band, config, local_stft_obj, remote_stft_obj): reference_channels and also the frequency axes are restricted to being within the frequency band given as an input argument. """ - dec_level_config = config.decimations[0] logger.info(f"Processing band {band.center_period:.6f}s") band_dataset = extract_band(band, local_stft_obj) X = band_dataset[dec_level_config.input_channels] Y = band_dataset[dec_level_config.output_channels] check_time_axes_synched(X, Y) - if config.stations.remote: + if dec_level_config.reference_channels: band_dataset = extract_band(band, remote_stft_obj) RR = band_dataset[dec_level_config.reference_channels] check_time_axes_synched(Y, RR)