smlmlp.detect_snr module

smlmlp.detect_snr(signals, bkgds, noise_corrections=None, channels_gains=0.25, *, cuda=False, parallel=False)[source]

Normalize signals into signal-to-noise ratio values.

This function converts each signal array into SNR units using the provided background, noise correction factor, and channel gain. The computation is performed in-place on each signal array, either on CPU or GPU.

Parameters:
  • signals (sequence of array-like) – Sequence of signal arrays, one per channel.

  • bkgds (sequence of array-like) – Sequence of background arrays matching signals.

  • noise_corrections (sequence of float or None, optional) – Optional per-channel noise correction factors. If None, a value of 1.0 is used for every channel.

  • channels_gains (float or sequence, optional) – Experimental gain value(s) used to normalize the backgrounds. This value is normalized through smlmlp.Config so that one gain is available for each channel.

  • cuda (bool, optional) – Whether to use GPU acceleration.

  • parallel (bool, optional) – Whether to enable CPU parallelization.

Returns:

A tuple (snrs, info) where:

  • snrs is the list of SNR arrays, one per channel,

  • info is a dictionary containing reusable intermediate results.

The dictionary contains the following keys:

'noise_corrections'

Per-channel noise correction factors effectively used.

'channels_gains'

Per-channel gain values effectively used.

Return type:

tuple

Notes

The normalization is performed in-place using:

\[\mathrm{SNR} = \frac{\mathrm{signal}} {\mathrm{noise\_correction} \times \sqrt{\mathrm{bkgd} / \mathrm{gain}}}\]

Examples

>>> import numpy as np
>>> signals = [np.array([[10., 20.], [30., 40.]], dtype=np.float32)]
>>> bkgds = [np.array([[4., 4.], [4., 4.]], dtype=np.float32)]
>>> snrs, info = detect_snr(signals, bkgds, channels_gains=1.0)
>>> len(snrs)
1
>>> snrs[0].shape
(2, 2)
>>> "channels_gains" in info
True
>>> signals = [
...     np.array([[10., 20.]], dtype=np.float32),
...     np.array([[5., 15.]], dtype=np.float32),
... ]
>>> bkgds = [
...     np.array([[4., 4.]], dtype=np.float32),
...     np.array([[9., 9.]], dtype=np.float32),
... ]
>>> snrs, info = detect_snr(
...     signals,
...     bkgds,
...     noise_corrections=[1.0, 2.0],
...     channels_gains=[0.5, 1.0],
... )
>>> len(snrs)
2