Skip to content

Commit

Permalink
replace aurora's extract_band method with mth5 method
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl Kappler committed Jan 6, 2025
1 parent ae76455 commit aef6c2b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 45 deletions.
2 changes: 1 addition & 1 deletion aurora/pipelines/process_mth5.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def load_stft_obj_from_mth5(
"""
Load stft_obj from mth5 (instead of compute)
Note #1: See note #1 in time_series.frequency_band_helpers.extract_band
Note #1: See note #1 in mth5.timeseries.spectre.spectrogram.py in extract_band function.
Parameters
----------
Expand Down
45 changes: 1 addition & 44 deletions aurora/time_series/frequency_band_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from mt_metadata.transfer_functions.processing.aurora import (
DecimationLevel as AuroraDecimationLevel,
)
from mth5.timeseries.spectre.spectrogram import extract_band


def get_band_for_tf_estimate(
Expand Down Expand Up @@ -52,50 +53,6 @@ def get_band_for_tf_estimate(

return X, Y, RR


def extract_band(frequency_band, fft_obj, channels=[], epsilon=1e-7):
"""
Extracts a frequency band from xr.DataArray representing a spectrogram.
Stand alone version of the method that is used by WIP Spectrogram class.
Development Notes:
#1: 20230902
TODO: Decide if base dataset object should be a xr.DataArray (not xr.Dataset)
- drop=True does not play nice with h5py and Dataset, results in a type error.
File "stringsource", line 2, in h5py.h5r.Reference.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__
However, it works OK with DataArray, so maybe use data array in general
Parameters
----------
frequency_band: mt_metadata.transfer_functions.processing.aurora.band.Band
Specifies interval corresponding to a frequency band
fft_obj: xarray.core.dataset.Dataset
To be replaced with an fft_obj() class in future
epsilon: float
Use this when you are worried about missing a frequency due to
round off error. This is in general not needed if we use a df/2 pad
around true harmonics.
Returns
-------
band: xr.DataArray
The frequencies within the band passed into this function
"""
cond1 = fft_obj.frequency >= frequency_band.lower_bound - epsilon
cond2 = fft_obj.frequency <= frequency_band.upper_bound + epsilon
try:
band = fft_obj.where(cond1 & cond2, drop=True)
except TypeError: # see Note #1
tmp = fft_obj.to_array()
band = tmp.where(cond1 & cond2, drop=True)
band = band.to_dataset("variable")
if channels:
band = band[channels]
return band


def check_time_axes_synched(X, Y):
"""
Utility function for checking that time axes agree.
Expand Down

0 comments on commit aef6c2b

Please sign in to comment.