Skip to content

Commit

Permalink
Merge pull request #88 from lifewatch/feature/frequency_crop
Browse files Browse the repository at this point in the history
added select_frequency_range function
  • Loading branch information
cparcerisas authored Oct 6, 2023
2 parents bf02385 + 6b64327 commit 5179880
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pypam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
join_all_ds_output_station
join_all_ds_output_deployment
select_datetime_range
select_frequency_range
merge_ds
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5179880

Please sign in to comment.