LongRecordingAnalyzer#
- class neurodent.core.LongRecordingAnalyzer(longrecording: LongRecordingOrganizer, fragment_len_s=10, apply_notch_filter=True)[source]#
Bases:
objectClass for analyzing LongRecordings by breaking them into smaller time windows (fragments).
- Parameters:
longrecording (
LongRecordingOrganizer) – The LongRecordingOrganizer instance to analyze.fragment_len_s (
int, optional) – Length of adjacent windows in seconds. Defaults to 10.apply_notch_filter (
bool, optional) – Whether to apply notch filter (constants.LINE_FREQ) to loaded fragments. Defaults to True.
- Variables:
LongRecording (
LongRecordingOrganizer) – The LongRecordingOrganizer instance being analyzed.fragment_len_s (
int) – Length of each analysis fragment/window in seconds.n_fragments (
int) – Total number of fragments in the recording.channel_names (
list[str]) – List of channel names.n_channels (
int) – Number of channels.mult_to_uV (
float) – Multiplier to convert raw data to microvolts.f_s (
int) – Sampling frequency in Hz.apply_notch_filter (
bool) – Whether notch filtering is applied to fragments.
- __init__(longrecording: LongRecordingOrganizer, fragment_len_s=10, apply_notch_filter=True) None[source]#
- get_fragment_rec(index) BaseRecording[source]#
Get window at index as a spikeinterface recording object
- Parameters:
index (
int) – Index of time window- Returns:
spikeinterface recording object with optional notch filtering applied
- Return type:
si.BaseRecording
- get_fragment_np(index, recobj=None) ndarray[source]#
Get window at index as a numpy array object
- Parameters:
index (
int) – Index of time windowrecobj (
si.BaseRecording, optional) – If not None, uses this recording object to get the numpy array. Defaults to None.
- Returns:
Numpy array with dimensions (N, M), N = number of samples, M = number of channels. Values in uV
- Return type:
np.ndarray
- get_fragment_mne(index, recobj=None) ndarray[source]#
Get window at index as a numpy array object, formatted for ease of use with MNE functions
- Parameters:
index (
int) – Index of time windowrecobj (
si.BaseRecording, optional) – If not None, uses this recording object to get the numpy array. Defaults to None.
- Returns:
- Numpy array with dimensions (1, M, N), M = number of channels, N = number of samples. 1st dimension corresponds
to number of epochs, which there is only 1 in a window. Values in uV
- Return type:
np.ndarray
- compute_rms(index, **kwargs)[source]#
Compute average root mean square amplitude
- Parameters:
index (
int) – Index of time window- Returns:
np.ndarray with shape (1, M), M = number of channels
- Return type:
result
- compute_ampvar(index, **kwargs)[source]#
Compute average amplitude variance
- Parameters:
index (
int) – Index of time window- Returns:
np.ndarray with shape (1, M), M = number of channels
- Return type:
result
- compute_psd(index, welch_bin_t=1, notch_filter=True, multitaper=False, **kwargs)[source]#
Compute PSD (power spectral density)
- Parameters:
index (
int) – Index of time windowwelch_bin_t (
float, optional) – Length of time bins to use in Welch’s method, in seconds. Defaults to 1.notch_filter (
bool, optional) – If True, applies notch filter at line frequency. Defaults to True.multitaper (
bool, optional) – If True, uses multitaper method instead of Welch’s method. Defaults to False.
- Returns:
Array of sample frequencies psd (np.ndarray): Array of PSD values at sample frequencies. (X, M), X = number of sample frequencies, M = number of channels. If sample window length is too short, PSD is interpolated
- Return type:
f (np.ndarray)
- compute_psdband(index, welch_bin_t=1, notch_filter=True, bands: list[tuple[float, float]] = {'alpha': (8, 13), 'beta': (13, 25), 'delta': (1, 4), 'gamma': (25, 40), 'theta': (4, 8)}, multitaper=False, **kwargs)[source]#
Compute power spectral density of the signal for each frequency band.
- Parameters:
index (
int) – Index of time windowwelch_bin_t (
float, optional) – Length of time bins to use in Welch’s method, in seconds. Defaults to 1.notch_filter (
bool, optional) – If True, applies notch filter at line frequency. Defaults to True.bands (
list[tuple[float, float]], optional) – List of frequency bands to compute PSD for. Defaults to constants.FREQ_BANDS.multitaper (
bool, optional) – If True, uses multitaper method instead of Welch’s method. Defaults to False.
- Returns:
Dictionary mapping band names to PSD values for each channel
- Return type:
dict
- compute_logpsdband(index, welch_bin_t=1, notch_filter=True, bands: list[tuple[float, float]] = {'alpha': (8, 13), 'beta': (13, 25), 'delta': (1, 4), 'gamma': (25, 40), 'theta': (4, 8)}, multitaper=False, **kwargs)[source]#
Compute the log of the power spectral density of the signal for each frequency band.
- compute_psdtotal(index, welch_bin_t=1, notch_filter=True, band: tuple[float, float] = (1, 40), multitaper=False, **kwargs)[source]#
Compute total power over PSD (power spectral density) plot within a specified frequency band
- Parameters:
index (
int) – Index of time windowwelch_bin_t (
float, optional) – Length of time bins to use in Welch’s method, in seconds. Defaults to 1.notch_filter (
bool, optional) – If True, applies notch filter at line frequency. Defaults to True.band (
tuple[float, float], optional) – Frequency band to calculate over. Defaults to constants.FREQ_BAND_TOTAL.multitaper (
bool, optional) – If True, uses multitaper method instead of Welch’s method. Defaults to False.
- Returns:
(M,) long array, M = number of channels. Each value corresponds to sum total of PSD in that band at that channel
- Return type:
psdtotal (np.ndarray)
- compute_logpsdtotal(index, welch_bin_t=1, notch_filter=True, band: tuple[float, float] = (1, 40), multitaper=False, **kwargs)[source]#
Compute the log of the total power over PSD (power spectral density) plot within a specified frequency band
- compute_psdfrac(index, welch_bin_t=1, notch_filter=True, bands: list[tuple[float, float]] = {'alpha': (8, 13), 'beta': (13, 25), 'delta': (1, 4), 'gamma': (25, 40), 'theta': (4, 8)}, total_band: tuple[float, float] = (1, 40), multitaper=False, **kwargs)[source]#
Compute the power spectral density in each band as a fraction of the total power.
- compute_logpsdfrac(index, welch_bin_t=1, notch_filter=True, bands: list[tuple[float, float]] = {'alpha': (8, 13), 'beta': (13, 25), 'delta': (1, 4), 'gamma': (25, 40), 'theta': (4, 8)}, total_band: tuple[float, float] = (1, 40), multitaper=False, **kwargs)[source]#
Compute the log of the power spectral density in each band as a fraction of the total power.
- compute_psdslope(index, welch_bin_t=1, notch_filter=True, band: tuple[float, float] = (1, 40), multitaper=False, **kwargs)[source]#
Compute the slope of the power spectral density of the signal.
- Parameters:
index (
int) – Index of time windowwelch_bin_t (
float, optional) – Length of time bins to use in Welch’s method, in seconds. Defaults to 1.notch_filter (
bool, optional) – If True, applies notch filter at line frequency. Defaults to True.band (
tuple[float, float], optional) – Frequency band to calculate over. Defaults to constants.FREQ_BAND_TOTAL.multitaper (
bool, optional) – If True, uses multitaper method instead of Welch’s method. Defaults to False.
- Returns:
Array of shape (M,2) where M is number of channels. Each row contains [slope, intercept] of log-log fit.
- Return type:
np.ndarray
- convert_idx_to_timebound(index: int) tuple[float, float][source]#
Convert fragment index to timebound (start time, end time)
- Parameters:
index (
int) – Fragment index- Returns:
Timebound in seconds
- Return type:
tuple[float, float]
- compute_cohere(index, freq_res: float = 1, mode: Literal['cwt_morlet', 'multitaper'] = 'multitaper', geomspace: bool = False, cwt_n_cycles_max: float = 7.0, mt_bandwidth: float = 4.0, downsamp_q: int = 4, epsilon: float = 0.01, **kwargs) ndarray[source]#
- compute_zcohere(index, z_epsilon: float = 1e-06, **kwargs) ndarray[source]#
Compute the Fisher z-transformed coherence of the signal.
- Parameters:
index (
int) – Index of time windowz_epsilon (
float) – Small value to prevent arctanh(1) = inf. Values are clipped to [-1+z_epsilon, 1-z_epsilon]**kwargs – Additional arguments passed to compute_zcohere
- compute_zpcorr(index, z_epsilon: float = 1e-06, **kwargs) ndarray[source]#
Compute the Fisher z-transformed Pearson correlation coefficient of the signal.
- Parameters:
index (
int) – Index of time windowz_epsilon (
float) – Small value to prevent arctanh(1) = inf. Values are clipped to [-1+z_epsilon, 1-z_epsilon]**kwargs – Additional arguments passed to compute_zpcorr