stompy.filters — Flavors of lowpass filters

General zero-phase filter. Thanks to Ed Gross for most of this. It’s mostly a python translation of matlab code he provided. (this is a generalization of the code in tidal_filter.py)

stompy.filters.lowpass(data, in_t=None, cutoff=None, order=4, dt=None, axis=-1, causal=False)[source]

data: vector of data in_t: sample times cutoff: cutoff period in the same units as in_t

returns vector same as data, but with high frequencies removed

stompy.filters.lowpass_fir(x, winsize, ignore_nan=True, axis=-1, mode='same', use_fft=False, nan_weight_threshold=0.49999)[source]

In the absence of exact filtering needs, choose the window size to match the cutoff period. Signals with a frequency corresponding to that cutoff period will be attenuated to about 50% of their original amplitude, corresponding to the -6dB point.

Rolloff is about 18dB/octave, though highly scalloped so it’s not as simple as with a Butterworth filter. That 18dB/octave is roughly the same as a 3rd order butterworth, but it’s a bit unclear on exactly where the 18dB/octave rolloff holds.

x: ndarray winsize: integer - how long the hanning window is axis: the axis along which to apply the filter mode: same as for scipy.signal convolve operations use_fft: using the fft is faster, but sometimes less robust nan_weight_threshold: items with a weight less than this will be marked nan

the default value is slightly less than half, to avoid numerical roundoff issues with 0.49999999 < 0.5

N.B. In the case of an input with nan only at the beginning and end, to guarantee that the output will have the same nans as the input winsize must be odd. Otherwise there can be nan-weights exactly==0.500 on both ends.

stompy.filters.lowpass_godin(data, in_t_days=None, ends='pass', mean_dt_h=None, *args, **kwargs)[source]

Approximate Godin’s tidal filter Note that in preserving the length of the dataset, the ends aren’t really valid

data: array suitable to pass to np.convolve in_t_days: timestamps in decimal days. This is only used to establish the time step, which is assumed to be constant. dt_h: directly specify timestep in hours.

ends: ‘pass’ no special treatment at the ends. The first and last ~37

hours will be contaminated by end-effects.

‘nan’ will replace potentially contaminated end samples with nan

*args,**kwargs are allowed but ignored. They are present to make it easier to slip this method in to replace others without having to change the call signature

stompy.filters.lowpass_gotin(data, in_t_days, *args, **kwargs)[source]
stompy.filters.lowpass_xr(da, cutoff, **kw)[source]

Like lowpass(), but ds is a data array with a time coordinate, and cutoff is a timedelta64.