smlmlp.signal_temporal_filter module
- smlmlp.signal_temporal_filter(channels, /, temporal_kernel, signals=None, bkgds=None, noise_corrections=None, *, cuda=False, parallel=False)[source]
Apply a temporal filter to enhance signals.
This function applies a temporal correlation filter independently to each channel. If backgrounds are provided, they are subtracted before filtering. The noise correction factors are updated according to the norm of the temporal kernel.
- Parameters:
channels (sequence of ndarray) – Sequence of input channel stacks, one per channel.
temporal_kernel (array-like) – Temporal kernel used by
stacklp.temporal_correlate().signals (sequence of ndarray or None, optional) – Optional preallocated output arrays for the filtered signals. If provided and longer than the corresponding channel acquisition, each signal stack is truncated to the channel length.
bkgds (sequence of ndarray or None, optional) – Optional background arrays to subtract before temporal filtering.
noise_corrections (sequence of float or None, optional) – Optional per-channel noise correction factors. If
None, they are initialized to1.0for each channel.cuda (bool, optional) – Whether to enable CUDA processing.
parallel (bool, optional) – Whether to enable parallel processing.
- Returns:
A tuple
(new_signals, noise_corrections, info)where:new_signalsis the list of temporally filtered signal stacks,noise_correctionsis the updated list of correction factors,infois a dictionary containing reusable intermediate results.
The dictionary contains the following keys:
'temporal_kernel'Temporal kernel used for the correlation.
'kernel_factor'Multiplicative noise-correction factor derived from the kernel norm.
- Return type:
tuple
Notes
The noise correction factor is updated using:
\[\sqrt{\sum k^2}\]where \(k\) is the temporal kernel.
Examples
>>> import numpy as np >>> channels = [np.random.rand(10, 8, 8).astype(np.float32)] >>> kernel = np.array([1.0, -1.0], dtype=np.float32) >>> signals, noise_corr, info = signal_temporal_filter(channels, kernel) >>> len(signals) 1 >>> "kernel_factor" in info True
>>> bkgds = [np.zeros_like(channels[0])] >>> signals, noise_corr, info = signal_temporal_filter( ... channels, ... kernel, ... bkgds=bkgds, ... noise_corrections=[np.float32(2.0)], ... ) >>> len(noise_corr) 1