Skip to content

Commit dbbb8f2

Browse files
authored
Merge pull request #96 from chrishavlin/scipy_opt_import
use optional import for scipy
2 parents bcfeebe + 511176d commit dbbb8f2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

yt_xarray/utilities/_grid_decomposition.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import List, Optional, Tuple, Union
22

33
import numpy as np
4-
from scipy.signal import butter, filtfilt
54
from yt import load_amr_grids
65

76
from yt_xarray.transformations import Transformer
@@ -19,11 +18,14 @@ def _dsig2_dpx2(sig1d):
1918
def _lowpass_filter(sig_1d):
2019
# pass a signature array through a lowpass filter. should expose some of these
2120
# for when a grid is not properly decomposing...
21+
msg = "This functionality requires scipy. Install it and try again."
22+
scp_signal = _import_optional_dep("scipy.signal", custom_message=msg)
23+
2224
order = 2 # keep at 2
2325
fs = 1.0 # sampling frequency [Hz]
2426
Wn = 0.1 # critical frequency [Hz]
25-
b, a = butter(order, Wn=Wn, fs=fs, btype="low", analog=False)
26-
y = filtfilt(b, a, sig_1d)
27+
b, a = scp_signal.butter(order, Wn=Wn, fs=fs, btype="low", analog=False)
28+
y = scp_signal.filtfilt(b, a, sig_1d)
2729
return y
2830

2931

0 commit comments

Comments
 (0)