From 6b64327f0e14246a1105ad4c1141e55edb6f1683 Mon Sep 17 00:00:00 2001 From: Clea Parcerisas Date: Fri, 6 Oct 2023 12:58:14 +0200 Subject: [PATCH] added select_frequency_range function --- pypam/utils.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pypam/utils.py b/pypam/utils.py index 1383cc8..56d2880 100644 --- a/pypam/utils.py +++ b/pypam/utils.py @@ -14,6 +14,7 @@ join_all_ds_output_station join_all_ds_output_deployment select_datetime_range + select_frequency_range merge_ds @@ -668,6 +669,30 @@ def select_datetime_range(da_sxx, start_datetime, end_datetime): return da_sxx, old_start_datetime, old_end_datetime +def select_frequency_range(ds, min_freq, max_freq, frequency_coord='frequency'): + """ + Crop the dataset to the specified band between min freq and max freq. + + Parameters + ---------- + ds: Dataset or DataArray + Data to crop + min_freq: float + Minimum frequency in Hz + max_freq: float + Maximum frequency in Hz + frequency_coord: string + Name of the frequency coordinate + + Returns + ------- + The dataset cropped + """ + ds_cropped = ds.sel(frequency=ds[frequency_coord][ + (ds[frequency_coord] > min_freq) & (ds[frequency_coord] < max_freq)]) + return ds_cropped + + def join_all_ds_output_station(directory_path, station, data_var_name, drop=False): """ Return a DataArray by joining the data you selected from all the output ds for one station