Skip to content

Commit

Permalink
Merge pull request #96 from chrishavlin/scipy_opt_import
Browse files Browse the repository at this point in the history
use optional import for scipy
  • Loading branch information
chrishavlin authored Jul 3, 2024
2 parents bcfeebe + 511176d commit dbbb8f2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions yt_xarray/utilities/_grid_decomposition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import List, Optional, Tuple, Union

import numpy as np
from scipy.signal import butter, filtfilt
from yt import load_amr_grids

from yt_xarray.transformations import Transformer
Expand All @@ -19,11 +18,14 @@ def _dsig2_dpx2(sig1d):
def _lowpass_filter(sig_1d):
# pass a signature array through a lowpass filter. should expose some of these
# for when a grid is not properly decomposing...
msg = "This functionality requires scipy. Install it and try again."
scp_signal = _import_optional_dep("scipy.signal", custom_message=msg)

order = 2 # keep at 2
fs = 1.0 # sampling frequency [Hz]
Wn = 0.1 # critical frequency [Hz]
b, a = butter(order, Wn=Wn, fs=fs, btype="low", analog=False)
y = filtfilt(b, a, sig_1d)
b, a = scp_signal.butter(order, Wn=Wn, fs=fs, btype="low", analog=False)
y = scp_signal.filtfilt(b, a, sig_1d)
return y


Expand Down

0 comments on commit dbbb8f2

Please sign in to comment.