dspk.ops.math
Per-channel statistics on the device, and window designs.
channel_mad |
Median absolute deviation of every channel, median(|x - median(x)|). |
channel_mean_std |
Mean and population standard deviation of every channel. |
channel_noise_std |
Robust noise level of every channel. |
window |
A symmetric window of length values. |
Functions
Section titled “Functions”channel_mad
Section titled “channel_mad”channel_mad(data, *, runtime: str | None = None) -> np.ndarrayMedian absolute deviation of every channel, median(|x - median(x)|).
Unscaled: divide by MAD_TO_SIGMA for a standard deviation (SpikeInterface’s
get_noise_levels(method="mad") does). Medians of an even count are NumPy’s.
Parameters
data:array_like
Signal(channels, samples). float32, int8, int16, uint16 and int32 arrays go to the device as they are and are converted there; other dtypes and lists become float32 first.runtime:str, defaultNone
A runtime fromruntime.available("cuda","hip","wgpu","cpu") for this call. By default: the one chosen withruntime.set, elseDSPK_RUNTIME, else the first available (GPUs first).
Returns
np.ndarray— One value per channel(channels,).
Examples
>>> import numpy as np>>> import dspk>>> x = np.random.default_rng(0).standard_normal((4, 30_000)).astype(np.float32)>>> mad = dspk.ops.math.channel_mad(x)channel_mean_std
Section titled “channel_mean_std”channel_mean_std( data, *, runtime: str | None = None,) -> tuple[np.ndarray, np.ndarray]Mean and population standard deviation of every channel.
Parameters
data:array_like
Signal(channels, samples). float32, int8, int16, uint16 and int32 arrays go to the device as they are and are converted there; other dtypes and lists become float32 first.runtime:str, defaultNone
A runtime fromruntime.available("cuda","hip","wgpu","cpu") for this call. By default: the one chosen withruntime.set, elseDSPK_RUNTIME, else the first available (GPUs first).
Returns
np.ndarray—(channels,).np.ndarray—(channels,), population (ddof=0).
Examples
>>> import numpy as np>>> import dspk>>> x = np.random.default_rng(0).standard_normal((4, 30_000)).astype(np.float32)>>> mean, std = dspk.ops.math.channel_mean_std(x)channel_noise_std
Section titled “channel_noise_std”channel_noise_std( data, *, runtime: str | None = None,) -> np.ndarrayRobust noise level of every channel: median(|x|) / MAD_TO_SIGMA.
The usual threshold for spike detection: unlike the standard deviation it is barely moved by
the spikes themselves. The median here is the magnitude at index samples // 2 when sorted.
Parameters
data:array_like
Signal(channels, samples). float32, int8, int16, uint16 and int32 arrays go to the device as they are and are converted there; other dtypes and lists become float32 first.runtime:str, defaultNone
A runtime fromruntime.available("cuda","hip","wgpu","cpu") for this call. By default: the one chosen withruntime.set, elseDSPK_RUNTIME, else the first available (GPUs first).
Returns
np.ndarray— One value per channel(channels,).
Examples
>>> import numpy as np>>> import dspk>>> x = np.random.default_rng(0).standard_normal((4, 30_000)).astype(np.float32)>>> noise = dspk.ops.math.channel_noise_std(x)window
Section titled “window”window( name: str, length: int, *, sigma: float | None = None, beta: float | None = None,) -> np.ndarrayA symmetric window of length values.
Parameters
name:{"hann", "hamming", "gaussian", "kaiser"}
The window.length:int
Number of values.sigma:float, defaultNone
Standard deviation, in samples;"gaussian"needs it.beta:float, defaultNone
Shape;"kaiser"needs it.
Returns
np.ndarray—(length,).
Raises
ValueError: For an unknownname, orsigma/betamissing from (or given to) a window.
Examples
>>> import dspk>>> w = dspk.ops.math.window("kaiser", 51, beta=5.0)Constants
Section titled “Constants”| Name | Type | Value | Description |
|---|---|---|---|
MAD_TO_SIGMA |
float |
0.67448974 |