dspk.ops.stage
Pipeline stages (see ops.Pipeline). Defaults follow scipy where an equivalent exists.
car |
Common average reference, as ops.spatial.car. |
clamp |
Clips to a range. |
cmr |
Common median reference, as ops.spatial.cmr. |
fir |
An FIR filter with explicit taps, causal or centred. |
gaussian_smooth |
Zero-phase Gaussian smoothing, as ops.filter.gaussian_smooth. |
laplacian |
A ops.spatial.Laplacian as a stage. |
whiten |
A fitted ops.spatial.Whitening as a stage. |
iir |
An IIR filter, as ops.filter.iir; the pipeline gives the sample rate. |
median |
Running median, as ops.filter.median. |
notch |
A second-order notch, as ops.filter.notch. |
scale |
Scales and shifts. |
sos |
Second-order sections you already have, such as from scipy.signal. |
subtract_baseline |
Subtracts a constant. |
remap |
A channel map that keeps every channel, as a stage (reorder_channels of its order). |
reorder_channels |
The channels in a new order. |
teager_kaiser |
Teager–Kaiser energy, as ops.filter.teager_kaiser. |
rectify |
Full-wave rectification, |x|; a low-pass after it gives an envelope. |
square |
Instantaneous power, x**2; a low-pass and sqrt after it give a moving RMS. |
sqrt |
Square root, sqrt(x), with negative values taken as 0. |
log10 |
log10(|x|), with magnitudes below LOG10_FLOOR taken as it. |
Stage |
One pipeline stage (build with the functions of dspk.ops.stage). |
Functions
Section titled “Functions”car() -> StageCommon average reference, as ops.spatial.car.
Returns
Stage
clamp(min: float, max: float) -> StageClips to a range: y = clip(x, min, max).
Parameters
min:float
Lower bound.max:float
Upper bound, at leastmin.
Returns
Stage
Raises
ValueError: Whenminis abovemax.
cmr() -> StageCommon median reference, as ops.spatial.cmr.
Returns
Stage
fir( taps, *, centered: bool = False, edge: str = FIR_DEFAULT_EDGE,) -> StageAn FIR filter with explicit taps, causal or centred.
Parameters
taps:array_like
Filter taps (1-D), e.g. fromops.filter.firwin.centered:bool, defaultFalse
False: causal.True: the taps (an odd number) centred on each sample.edge:{"zeros", "odd", "reflect", "nearest"}, defaultFIR_DEFAULT_EDGE(‘zeros’)
What the samples past each end are taken to be.
Returns
Stage
Raises
ValueError: For emptytapsor an even number of centred taps.
Notes
In Pipeline(stream=True) the taps’ history is not carried from one chunk to the next: run
it on independent chunks with settling of context, which is exact for a FIR.
gaussian_smooth
Section titled “gaussian_smooth”gaussian_smooth( sigma_samples: float, *, edge: str = GAUSSIAN_DEFAULT_EDGE,) -> StageZero-phase Gaussian smoothing, as ops.filter.gaussian_smooth.
Parameters
sigma_samples:float
Standard deviation, in samples.edge:{"zeros", "odd", "reflect", "nearest"}, defaultGAUSSIAN_DEFAULT_EDGE(‘reflect’)
What the samples past each end are taken to be.
Returns
Stage
Raises
ValueError: For a non-positivesigma_samples.
laplacian
Section titled “laplacian”laplacian(laplacian) -> StageA ops.spatial.Laplacian as a stage.
Parameters
laplacian:dspk.ops.spatial.Laplacian
Made for as many channels as the pipeline’s input.
Returns
Stage
whiten
Section titled “whiten”whiten(whitening) -> StageA fitted ops.spatial.Whitening as a stage.
Parameters
whitening:dspk.ops.spatial.Whitening
Fitted on as many channels as the pipeline’s input.
Returns
Stage
iir( band: str, cutoff: float | Sequence[float], *, order: int = DEFAULT_ORDER, design: str = 'butterworth', ripple_db: float | None = None, mode: str = 'forward_backward', start: str = 'rest',) -> StageAn IIR filter, as ops.filter.iir; the pipeline gives the sample rate.
Parameters
band:{"lowpass", "highpass", "bandpass", "bandstop"}
The band the filter passes (or stops).cutoff:float or (float, float)
Cutoff in Hz: one, or(low, high)for the band filters.order:int, defaultDEFAULT_ORDER(5)
Filter order.design:{"butterworth", "chebyshev1", "bessel"}, default'butterworth'
The filter family.ripple_db:float, defaultNone
Passband ripple in dB;"chebyshev1"needs it.mode:{"forward_backward", "forward"}, default'forward_backward'
"forward_backward": zero phase (windowed runs only)."forward": causal, the modestream=Trueneeds.start:{"rest", "steady_state"}, default'rest'
Where a"forward"pass starts, as inops.filter.iir.
Returns
Stage
Raises
ValueError: For an invalid design,modeorstart.
median
Section titled “median”median(width: int, *, edge: str = MEDIAN_DEFAULT_EDGE) -> StageRunning median, as ops.filter.median.
Parameters
width:int
Window length in samples, odd, at mostMAX_MEDIAN_WIDTH.edge:{"zeros", "odd", "reflect", "nearest"}, defaultMEDIAN_DEFAULT_EDGE(‘zeros’)
What the samples past each end are taken to be.
Returns
Stage
Raises
ValueError: For an even or too largewidth.
notch( freq: float, q: float, *, mode: str = 'forward_backward', start: str = 'rest',) -> StageA second-order notch, as ops.filter.notch.
Parameters
freq:float
Frequency to remove, in Hz.q:float
Quality factor: the notch isfreq / qHz wide at -3 dB.mode:{"forward_backward", "forward"}, default'forward_backward'
"forward_backward": zero phase (windowed runs only)."forward": causal, the modestream=Trueneeds.start:{"rest", "steady_state"}, default'rest'
Where a"forward"pass starts, as inops.filter.iir.
Returns
Stage
scale(alpha: float, beta: float = 0.0) -> StageScales and shifts: y = alpha * x + beta.
Parameters
alpha:float
Factor.beta:float, default0.0
Offset, in the signal’s unit.
Returns
Stage
sos( sections: np.ndarray, *, mode: str = 'forward_backward', start: str = 'rest',) -> StageSecond-order sections you already have, such as from scipy.signal.
Parameters
sections:numpy.ndarray
(sections, 6)in scipy’s layout.mode:{"forward_backward", "forward"}, default'forward_backward'
"forward_backward": zero phase (windowed runs only)."forward": causal, the modestream=Trueneeds.start:{"rest", "steady_state"}, default'rest'
Where a"forward"pass starts, as inops.filter.iir.
Returns
Stage
subtract_baseline
Section titled “subtract_baseline”subtract_baseline(baseline: float) -> StageSubtracts a constant: y = x - baseline.
Parameters
baseline:float
In the signal’s unit.
Returns
Stage
remap(map) -> StageA channel map that keeps every channel, as a stage (reorder_channels of its order).
Parameters
map:dict, list of dict, str or os.PathLike
A channel map: a{"base", "pairs"}dict (or a file’s{"remap": {...}}), a list of{"from", "to", "name"}pairs, or the path of a.toml/.jsonmap file.
Returns
Stage
Raises
ValueError: When the map is invalid or drops channels.
reorder_channels
Section titled “reorder_channels”reorder_channels(order: Sequence[int]) -> StageThe channels in a new order: output channel i is input channel order[i].
Every channel is used once, so the channel count stays. To drop channels, use
ops.layout.remap, or a remap node right after read or before write in a
pipeline spec.
Parameters
order:sequence of int
A permutation of0..channels.
Returns
Stage
Raises
ValueError: Whenorderis not a permutation.
teager_kaiser
Section titled “teager_kaiser”teager_kaiser( *, edge: str = TEAGER_KAISER_DEFAULT_EDGE,) -> StageTeager–Kaiser energy, as ops.filter.teager_kaiser.
Parameters
edge:{"zeros", "odd", "reflect", "nearest"}, defaultTEAGER_KAISER_DEFAULT_EDGE(‘reflect’)
What the samples past each end are taken to be.
Returns
Stage
rectify
Section titled “rectify”rectify() -> StageFull-wave rectification, |x|; a low-pass after it gives an envelope.
Returns
Stage
square
Section titled “square”square() -> StageInstantaneous power, x**2; a low-pass and sqrt after it give a moving RMS.
Returns
Stage
sqrt() -> StageSquare root, sqrt(x), with negative values taken as 0.
Returns
Stage
log10() -> Stagelog10(|x|), with magnitudes below LOG10_FLOOR taken as it.
Returns
Stage
Classes
Section titled “Classes”One pipeline stage (build with the functions of dspk.ops.stage).