diff --git a/aurora/sandbox/mth5_helpers.py b/aurora/sandbox/mth5_helpers.py index f17b7cf7..38cfc58f 100644 --- a/aurora/sandbox/mth5_helpers.py +++ b/aurora/sandbox/mth5_helpers.py @@ -16,6 +16,53 @@ from mth5.clients import FDSN from mth5.utils.helpers import initialize_mth5 +def enrich_channel_summary(mth5_object, df, keyword): + """ + + Parameters + ---------- + mth5_object: mth5.mth5.MTH5 + df: pd.DataFrame + A channel summary dataframe + keyword: str + supported keywords are ["num_filters",] + "num_filters" computes the number of filters associated with each row (channel-run) and adds that "num_filters" column of df + + Returns + ------- + df: pd.DataFrame + The channel summary df with the new column + """ + df[keyword] = -1 + if keyword=="num_filters": + for i_row, row in df.iterrows(): + channel = mth5_object.get_channel(row.station, row.run, row.component, row.survey) + num_filters = len(channel.channel_response_filter.filters_list) + df[keyword].iat[i_row] = num_filters + return df + +def augmented_channel_summary(mth5_object, df=None):#, **kwargs): + """ + Consider supportig kwargs, such as a list of keyords that tell what columns to add + For now, we only want to add n_filters + Parameters + ---------- + df: channel summary dataframe + + + Returns + ------- + + """ + if not df: + df = mth5_object.channel_summary.to_dataframe() + df["n_filters"] = -1 + for i_row, row in df.iterrows(): + channel = mth5_object.get_channel(row.station, row.run, row.component, row.survey) + n_filters = len(channel.channel_response_filter.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): """ diff --git a/tests/cas04/02b_process_cas04_mth5.py b/tests/cas04/02b_process_cas04_mth5.py index c21bbcf8..66628734 100644 --- a/tests/cas04/02b_process_cas04_mth5.py +++ b/tests/cas04/02b_process_cas04_mth5.py @@ -356,7 +356,7 @@ def old_main(): #process_run_list("CAS04", ["b", "c", "d"]) # , reprocess=False) #process_with_remote(h5_paths, "CAS04", "CAV07") #process_with_remote(h5_paths, "CAS04", "NVR11", band_setup_file=BANDS_DEFAULT_FILE) - #process_with_remote(h5_paths, "CAS04", "REV06") + process_with_remote(h5_paths, "CAS04", "REV06") #for RR in ["CAV07", "NVR11", "REV06"]: for RR in ["REV06",]: