From 6e69bca30d717cb1f5a665111a308c8895d8eb75 Mon Sep 17 00:00:00 2001 From: kkappler Date: Sun, 29 Dec 2024 08:19:35 -0800 Subject: [PATCH] Update per changes in mt_metadata - rename extra_pre_fft_detrend_type to per_window_detrend_type - add explicit assignment of per_window_detrend_type="linear" in config creator --- aurora/config/config_creator.py | 16 +++++++--------- aurora/pipelines/fourier_coefficients.py | 2 +- aurora/pipelines/time_series_helpers.py | 2 +- tests/synthetic/test_stft_methods_agree.py | 6 ++---- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/aurora/config/config_creator.py b/aurora/config/config_creator.py index 269e2974..da68da0e 100644 --- a/aurora/config/config_creator.py +++ b/aurora/config/config_creator.py @@ -108,9 +108,7 @@ def determine_band_specification_style(self) -> None: logger.info(msg) self._emtf_band_file = BANDS_DEFAULT_FILE self._band_specification_style = "EMTF" - elif (self._emtf_band_file is not None) & ( - self._band_edges is not None - ): + elif (self._emtf_band_file is not None) & (self._band_edges is not None): msg = "Bands defined twice, and possibly inconsistently" logger.error(msg) raise ValueError(msg) @@ -152,6 +150,8 @@ def create_from_kernel_dataset( Theoretically, you could also use the number of decimations implied by bands_dict but this is sloppy, because it would assume the decimation factor. + 3. 2024-12-29 Added setting of decimation_obj.stft.per_window_detrend_type = "linear" + This makes tests pass following a refactoring of mt_metadata. Could use more testing. Parameters ---------- @@ -178,9 +178,7 @@ def create_from_kernel_dataset( Object storing the processing parameters. """ - processing_obj = Processing( - id=kernel_dataset.processing_id - ) # , **kwargs) + processing_obj = Processing(id=kernel_dataset.processing_id) # , **kwargs) # pack station and run info into processing object processing_obj.stations.from_dataset_dataframe(kernel_dataset.df) @@ -209,9 +207,7 @@ def create_from_kernel_dataset( decimation_factors[0] = 1 if num_samples_window is None: default_window = Window() - num_samples_window = num_decimations * [ - default_window.num_samples - ] + num_samples_window = num_decimations * [default_window.num_samples] elif isinstance(num_samples_window, int): num_samples_window = num_decimations * [num_samples_window] # now you can define the frequency bands @@ -248,4 +244,6 @@ def create_from_kernel_dataset( decimation_obj.estimator.engine = estimator["engine"] except KeyError: pass + decimation_obj.stft.per_window_detrend_type = "linear" + return processing_obj diff --git a/aurora/pipelines/fourier_coefficients.py b/aurora/pipelines/fourier_coefficients.py index e958936c..2b3b5839 100644 --- a/aurora/pipelines/fourier_coefficients.py +++ b/aurora/pipelines/fourier_coefficients.py @@ -8,7 +8,7 @@ "decimation.level": 2, "decimation.method": "default", "decimation.sample_rate": 0.0625, -"extra_pre_fft_detrend_type": "linear", +"per_window_detrend_type": "linear", "prewhitening_type": "first difference", "window.clock_zero_type": "ignore", "window.num_samples": 128, diff --git a/aurora/pipelines/time_series_helpers.py b/aurora/pipelines/time_series_helpers.py index 2b3138a0..90b71933 100644 --- a/aurora/pipelines/time_series_helpers.py +++ b/aurora/pipelines/time_series_helpers.py @@ -336,7 +336,7 @@ def run_ts_to_stft( data=tapered_obj, sample_rate=windowing_scheme.sample_rate, spectral_density_correction=windowing_scheme.linear_spectral_density_calibration_factor, - detrend_type=decimation_obj.extra_pre_fft_detrend_type, + detrend_type=decimation_obj.stft.per_window_detrend_type, ) if decimation_obj.stft.recoloring: diff --git a/tests/synthetic/test_stft_methods_agree.py b/tests/synthetic/test_stft_methods_agree.py index e920e03d..3878882a 100644 --- a/tests/synthetic/test_stft_methods_agree.py +++ b/tests/synthetic/test_stft_methods_agree.py @@ -68,11 +68,9 @@ def test_stft_methods_agree(): run_ts = run_obj.to_runts(start=None, end=None) local_run_xrts = run_ts.dataset else: - local_run_xrts = prototype_decimate( - dec_config.decimation, local_run_xrts - ) + local_run_xrts = prototype_decimate(dec_config.decimation, local_run_xrts) - dec_config.extra_pre_fft_detrend_type = "constant" + dec_config.stft.per_window_detrend_type = "constant" local_stft_obj = run_ts_to_stft(dec_config, local_run_xrts) local_stft_obj2 = run_ts_to_stft_scipy(dec_config, local_run_xrts) stft_difference = local_stft_obj - local_stft_obj2