Skip to main content

features.csd

features.csd(
    data,
    fs,
    geometry,
    bands=None,
    decimate=10,
    scale=True,
    denoise=True,
    cadzow_kwargs=None,
)

Compute CSD and BPR features from a numpy array.

Computes the current source density (CSD, second spatial difference) and the bipolar referencing (BPR, first spatial difference) features from electrophysiological data, including RMS values and power spectral density across different frequency bands.

Args: data (np.ndarray): Data array with shape (channels, samples). fs (float): Sampling frequency in Hz. geometry (dict): Dictionary with channel geometry containing ‘x’, ‘y’, ‘col’ and ‘row’ arrays. bands (dict, optional): Dictionary with frequency bands to compute. Defaults to BANDS constant. decimate (int, optional): Decimation factor for CSD calculation. Defaults to 10. 1 skips scipy.signal.decimate entirely (passed through unchanged) rather than calling it with a no-op factor: scipy.signal.decimate(..., q=1, ...) designs an anti-aliasing filter with cutoff exactly at the Nyquist boundary, which scipy.signal.firwin rejects. scale (bool, optional): Forwarded to current_source_density. If True, scale the finite difference by the intercontact distance and tissue conductivity; if False, return the raw numerical finite difference. Defaults to True. denoise (bool, optional): Apply ibldsp.cadzow.cadzow_denoiser to the decimated data before the finite differences. Defaults to True. Set False when data has already been Cadzow-denoised upstream (e.g. combined with decimate=1 for a source that is already at the target rate), so it isn’t denoised a second time on top of a lossy reconstruction. cadzow_kwargs (dict, optional): Overrides of the Cadzow parameters, see :func:cadzow_lfp_kwargs for the defaults. Ignored if denoise is False. fs and h cannot be overridden: they are always fs / decimate and geometry, and passing either raises a TypeError.

Returns: pd.DataFrame: DataFrame with columns [‘channel’, ‘rms_lf_csd’, ‘psd_delta_csd’, ‘psd_theta_csd’, ‘psd_alpha_csd’, ‘psd_beta_csd’, ‘psd_gamma_csd’, ‘psd_lfp_csd’] and the same with the _bpr suffix.