77from operator import add
88
99import numpy as np
10- from scipy .signal import windows # the best operating system?
1110
1211from dascore .constants import PatchType
1312from dascore .exceptions import ParameterError
1413from dascore .units import Quantity
1514from dascore .utils .docs import compose_docstring
1615from dascore .utils .misc import broadcast_for_index
1716from dascore .utils .patch import get_dim_axis_value , patch_function
17+ from dascore .utils .signal import WINDOW_FUNCTIONS , _get_window_function
1818from dascore .utils .time import to_float
1919
20- TAPER_FUNCTIONS = dict (
21- barthann = windows .barthann ,
22- bartlett = windows .bartlett ,
23- blackman = windows .blackman ,
24- blackmanharris = windows .blackmanharris ,
25- bohman = windows .bohman ,
26- hamming = windows .hamming ,
27- hann = windows .hann ,
28- cos = windows .hann ,
29- nuttall = windows .nuttall ,
30- parzen = windows .parzen ,
31- triang = windows .triang ,
32- ramp = windows .triang ,
33- )
34-
3520
3621def _get_taper_slices (patch , kwargs ):
3722 """Get slice for start/end of patch."""
@@ -42,7 +27,7 @@ def _get_taper_slices(patch, kwargs):
4227 start , stop = value [0 ], value [1 ]
4328 else :
4429 start , stop = value , value
45- dur = coord .max () - coord . min ( )
30+ dur = coord .coord_range ( exact = False )
4631 # either let units pass through or multiply by d_len
4732 clses = (Quantity , np .timedelta64 )
4833 start = start if isinstance (start , clses ) or start is None else start * dur
@@ -53,19 +38,6 @@ def _get_taper_slices(patch, kwargs):
5338 return axis , (start , stop ), inds_1 , inds_2
5439
5540
56- def _get_window_function (window_type ):
57- """Get the window function to use for taper."""
58- # get taper function or raise if it isn't known.
59- if window_type not in TAPER_FUNCTIONS :
60- msg = (
61- f"'{ window_type } ' is not a known window type. "
62- f"Options are: { sorted (TAPER_FUNCTIONS )} "
63- )
64- raise ParameterError (msg )
65- func = TAPER_FUNCTIONS [window_type ]
66- return func
67-
68-
6941def _validate_windows (samps , start_slice , end_slice , shape , axis ):
7042 """Validate the windows don't overlap or exceed dim len."""
7143 max_len = shape [axis ]
@@ -87,7 +59,7 @@ def _validate_windows(samps, start_slice, end_slice, shape, axis):
8759
8860
8961@patch_function ()
90- @compose_docstring (taper_type = sorted (TAPER_FUNCTIONS ))
62+ @compose_docstring (taper_type = sorted (WINDOW_FUNCTIONS ))
9163def taper (
9264 patch : PatchType ,
9365 window_type : str = "hann" ,
@@ -219,7 +191,7 @@ def _get_range_envelope(coord, inds, window_type, invert):
219191
220192
221193@patch_function ()
222- @compose_docstring (taper_type = sorted (TAPER_FUNCTIONS ))
194+ @compose_docstring (taper_type = sorted (WINDOW_FUNCTIONS ))
223195def taper_range (
224196 patch : PatchType ,
225197 window_type : str = "hann" ,
0 commit comments