From 8ef6903186d1fe80d0ce19b750548a7038020a3a Mon Sep 17 00:00:00 2001 From: kkappler Date: Fri, 8 Dec 2023 21:04:30 -0800 Subject: [PATCH] channel_response_filter-->channel_response --- aurora/pipelines/time_series_helpers.py | 4 +- aurora/sandbox/mth5_helpers.py | 40 ++++++++++++------- .../parkfield/calibration_helpers.py | 5 ++- aurora/time_series/windowed_time_series.py | 2 +- tests/parkfield/test_calibrate_parkfield.py | 4 +- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/aurora/pipelines/time_series_helpers.py b/aurora/pipelines/time_series_helpers.py index 1405b4fe..48a74955 100644 --- a/aurora/pipelines/time_series_helpers.py +++ b/aurora/pipelines/time_series_helpers.py @@ -292,14 +292,14 @@ def calibrate_stft_obj(stft_obj, run_obj, units="MT", channel_scale_factors=None """ for channel_id in stft_obj.keys(): mth5_channel = run_obj.get_channel(channel_id) - channel_filter = mth5_channel.channel_response_filter + channel_filter = mth5_channel.channel_response if not channel_filter.filters_list: msg = f"Channel {channel_id} with empty filters list detected" logger.warning(msg) if channel_id == "hy": msg = "Channel hy has no filters, try using filters from hx" logger.warning("Channel HY has no filters, try using filters from HX") - channel_filter = run_obj.get_channel("hx").channel_response_filter + channel_filter = run_obj.get_channel("hx").channel_response calibration_response = channel_filter.complex_response(stft_obj.frequency.data) if channel_scale_factors: try: diff --git a/aurora/sandbox/mth5_helpers.py b/aurora/sandbox/mth5_helpers.py index b56007b0..d3d3fbdc 100644 --- a/aurora/sandbox/mth5_helpers.py +++ b/aurora/sandbox/mth5_helpers.py @@ -40,17 +40,21 @@ def enrich_channel_summary(mth5_object, df, keyword): channel = mth5_object.get_channel( row.station, row.run, row.component, row.survey ) - num_filters = len(channel.channel_response_filter.filters_list) + num_filters = len(channel.channel_response.filters_list) df[keyword].iat[i_row] = num_filters - elif keyword=="filter_units_in": + elif keyword == "filter_units_in": for i_row, row in df.iterrows(): - channel = mth5_object.get_channel(row.station, row.run, row.component, row.survey) - units_in = [x.units_in for x in channel.channel_response_filter.filters_list] + channel = mth5_object.get_channel( + row.station, row.run, row.component, row.survey + ) + units_in = [x.units_in for x in channel.channel_response.filters_list] df[keyword].iat[i_row] = units_in - elif keyword=="filter_units_out": + elif keyword == "filter_units_out": for i_row, row in df.iterrows(): - channel = mth5_object.get_channel(row.station, row.run, row.component, row.survey) - units_out = [x.units_out for x in channel.channel_response_filter.filters_list] + channel = mth5_object.get_channel( + row.station, row.run, row.component, row.survey + ) + units_out = [x.units_out for x in channel.channel_response.filters_list] df[keyword].iat[i_row] = units_out return df @@ -75,14 +79,20 @@ def augmented_channel_summary(mth5_object, df=None): # , **kwargs): channel = mth5_object.get_channel( row.station, row.run, row.component, row.survey ) - n_filters = len(channel.channel_response_filter.filters_list) + n_filters = len(channel.channel_response.filters_list) df.n_filters.iat[i_row] = n_filters return df -def build_request_df(network_id, station_id, channels=None, - start=None, end=None, time_period_dict={}, - mth5_version='0.2.0'): +def build_request_df( + network_id, + station_id, + channels=None, + start=None, + end=None, + time_period_dict={}, + mth5_version="0.2.0", +): """ Parameters @@ -113,15 +123,15 @@ def build_request_df(network_id, station_id, channels=None, A formatted dataframe that can be passed to mth5.clients.FDSN to request metdata or data. """ - from mth5.clients import FDSN + def get_time_period_bounds(ch): if ch in time_period_dict.keys(): - time_interval = time_period_dict[ch] + # time_interval = time_period_dict[ch] ch_start = time_period_dict[ch].left.isoformat() ch_end = time_period_dict[ch].right.isoformat() else: if start is None: - ch_start = '1970-01-01 00:00:00' + ch_start = "1970-01-01 00:00:00" else: ch_start = start if end is None: @@ -138,7 +148,7 @@ def get_time_period_bounds(ch): request_list = [] for channel in channels: ch_start, ch_end = get_time_period_bounds(channel) - request_list.append([network_id, station_id, '', channel, ch_start, ch_end]) + request_list.append([network_id, station_id, "", channel, ch_start, ch_end]) logger.info(f"request_list: {request_list}") diff --git a/aurora/test_utils/parkfield/calibration_helpers.py b/aurora/test_utils/parkfield/calibration_helpers.py index b78a4d7b..06c8d83c 100644 --- a/aurora/test_utils/parkfield/calibration_helpers.py +++ b/aurora/test_utils/parkfield/calibration_helpers.py @@ -125,11 +125,12 @@ def parkfield_sanity_check( channel = run_obj.get_channel(key) # pole-zero calibration response - pz_calibration_response = channel.channel_response_filter.complex_response( + + pz_calibration_response = channel.channel_response.complex_response( frequencies, include_decimation=include_decimation ) - if channel.channel_response_filter.units_in.lower() in ["t", "tesla"]: + if channel.channel_response.units_in.lower() in ["t", "tesla"]: logger.warning("WARNING: Expecting nT but got T") # Frequency response table response diff --git a/aurora/time_series/windowed_time_series.py b/aurora/time_series/windowed_time_series.py index c350b908..0af10545 100644 --- a/aurora/time_series/windowed_time_series.py +++ b/aurora/time_series/windowed_time_series.py @@ -201,7 +201,7 @@ def delay_correction(self, dataset, run_obj): # "NOT TESTED - PSEUDOCODE ONLY" for channel_id in dataset.keys(): mth5_channel = run_obj.get_channel(channel_id) - channel_filter = mth5_channel.channel_response_filter + channel_filter = mth5_channel.channel_response delay_in_seconds = channel_filter.total_delay true_time_axis = dataset.time + delay_in_seconds interpolator = interp1d( diff --git a/tests/parkfield/test_calibrate_parkfield.py b/tests/parkfield/test_calibrate_parkfield.py index 862fb9f6..7bd66b40 100644 --- a/tests/parkfield/test_calibrate_parkfield.py +++ b/tests/parkfield/test_calibrate_parkfield.py @@ -46,7 +46,9 @@ def validate_bulk_spectra_have_correct_units(run_obj, run_ts_obj, show_spectra=F num_samples_overlap=0, sample_rate=run_ts_obj.sample_rate, # 40.0 sps ) - windowed_obj = windowing_scheme.apply_sliding_window(run_ts_obj.dataset) + windowed_obj = windowing_scheme.apply_sliding_window( + run_ts_obj.dataset, dt=1.0 / run_ts_obj.sample_rate + ) tapered_obj = windowing_scheme.apply_taper(windowed_obj) fft_obj = windowing_scheme.apply_fft(tapered_obj)