xdas.atoms.FIRFilter#

class xdas.atoms.FIRFilter(numtaps, cutoff, btype='bandpass', window='hamming', width=None, scale=True, dim='last')[source]#

Pipeline implementation of an FIR filter.

Parameters:
  • numtaps (int) – The order (number of taps) of the FIR filter

  • cutoff (float or tuple) – The frequency cut-off of the filter. In the case of a low/high-pass filter, cutoff is a single number. In the case of a bandpass filter, cutoff is a tuple of two number (the upper and lower cut-off frequency, resp.).

  • btype (str) –

    The type of the filter band. Valid options are:
    • lowpass: removing frequencies above cutoff

    • highpass: removing frequencies below cutoff

    • bandpass (default): removing frequencies below cutoff[0] and above cutoff[1]

  • window (str or tuple of string and parameter values) – The window function to apply befor FIR filtering. If a tuple is given, it needs to be compatible with scipy.signal.get_window. Default: hamming

  • width – Default: None

  • scale (bool) – Default: True

  • dim (str or int) – The dimension along which the downsampling is applied. This is either an index, time or distance, or last. Default: last

Examples

>>> from xdas.synthetics import wavelet_wavefronts
>>> from xdas.atoms import Sequential, FIRFilter
>>> da = wavelet_wavefronts()

Using FIRFilter directly:

>>> # Highpass > 1.5 Hz
>>> da2 = FIRFilter(numtaps=5, cutoff=1.5, btype="highpass", dim="time")(da)
>>> da2
<xdas.DataArray (time: 300, distance: 401)>
[[-2.339751e-04  2.991040e-04 -3.702198e-04 ...  6.916895e-04
-6.370217e-04  1.334117e-03]
[-1.091503e-03  1.471451e-03 -2.193486e-03 ...  4.060728e-03
-4.168370e-03  8.518611e-03]
[ 5.014406e-02 -6.344995e-02  7.666315e-02 ... -1.428919e-01
1.298806e-01 -2.729624e-01]
...
[ 9.129921e-02 -1.841086e-01  2.547145e-03 ... -4.218528e-01
3.117905e-01 -2.467233e-01]
[-1.979881e-01 -8.168980e-03  5.458106e-01 ...  4.309588e-01
-1.352775e-01 -3.427569e-02]
[ 1.808382e-01 -2.270671e-02 -2.354151e-01 ... -1.836509e-01
-3.396010e-01  4.366619e-01]]
Coordinates:
* time (time): 2022-12-31T23:59:59.960 to 2023-01-01T00:00:05.940
* distance (distance): 0.000 to 10000.000

Using FIRFilter as an atom in Sequential:

>>> # Bandpass between 1 and 10 Hz
>>> sequence = Sequential([
...    FIRFilter(numtaps=6, cutoff=(1.0, 10.0), btype="bandpass", dim="time")
... ])
>>> result = sequence(da)
>>> result
<xdas.DataArray (time: 300, distance: 401)>
[[-0.000244  0.000312 -0.000386 ...  0.000722 -0.000665  0.001392]
[ 0.00554  -0.007003  0.00828  ... -0.015509  0.013836 -0.029197]
[ 0.012271 -0.017179  0.029934 ... -0.054504  0.060639 -0.12196 ]
...
[ 0.056955 -0.078299 -0.089504 ... -0.020045  0.120977 -0.096129]
[-0.027768 -0.105027  0.228342 ...  0.025277  0.035432 -0.081469]
[-0.021963 -0.046354  0.186166 ...  0.051622 -0.163209  0.177261]]
Coordinates:
* time (time): 2022-12-31T23:59:59.960 to 2023-01-01T00:00:05.940
* distance (distance): 0.000 to 10000.000
__init__(numtaps, cutoff, btype='bandpass', window='hamming', width=None, scale=True, dim='last')[source]#

Methods

__init__(numtaps, cutoff[, btype, window, ...])

call(da, **flags)

Apply the FIR taps to da and correct the time coordinate for filter lag.

initialize(da, **flags)

Determine the sampling rate from da and recompute the FIR taps.

initialize_from_state()

Recompute the FIR taps and lag from the current design parameters.

load_state(path)

Load the atom state from the NetCDF4 file at path.

reset()

Reset all state entries to ... (uninitialised sentinel).

save_state(path)

Serialise the current state to a NetCDF4 file at path.

set_state(state)

Restore the atom state from a previously saved state dict.

Attributes

initialized

True if every state key has been initialised (no ... sentinels remain).

state

Dict of the current state, including nested atom states.