Skip to content

Commit

Permalink
channel_response_filter-->channel_response
Browse files Browse the repository at this point in the history
  • Loading branch information
kkappler committed Dec 9, 2023
1 parent 43ab8b2 commit 8ef6903
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
4 changes: 2 additions & 2 deletions aurora/pipelines/time_series_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 25 additions & 15 deletions aurora/sandbox/mth5_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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}")

Expand Down
5 changes: 3 additions & 2 deletions aurora/test_utils/parkfield/calibration_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aurora/time_series/windowed_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion tests/parkfield/test_calibrate_parkfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8ef6903

Please sign in to comment.