osl_dynamics.analysis.static#

Functions to calculate static properties of time series data.

Note

This module is used in the following tutorials:

Module Contents#

Functions#

functional_connectivity(data[, conn_type])

Calculate functional connectivity (Pearson correlation).

welch_spectra(data, sampling_frequency[, ...])

Calculate spectra using Welch's method.

multitaper_spectra(data, sampling_frequency[, ...])

Calculate multitaper spectra.

Attributes#

_logger

osl_dynamics.analysis.static._logger[source]#
osl_dynamics.analysis.static.functional_connectivity(data, conn_type='corr')[source]#

Calculate functional connectivity (Pearson correlation).

Parameters:
  • data (np.ndarray) – Time series data. Shape must be (n_sessions, n_samples, n_channels) or (n_samples, n_channels).

  • conn_type (str, optional) – What metric should we use? "corr" (Pearson correlation) or "cov" (covariance).

Returns:

fc – Functional connectivity. Shape is (n_sessions, n_channels, n_channels) or (n_channels, n_channels).

Return type:

np.ndarray

osl_dynamics.analysis.static.welch_spectra(data, sampling_frequency, window_length=None, step_size=None, frequency_range=None, return_weights=False, standardize=True, calc_coh=False, keepdims=False, n_jobs=1)[source]#

Calculate spectra using Welch’s method.

Wrapper for spectral.welch_spectra assuming only one state is active for all time points.

Parameters:
  • data (np.ndarray or list) – Time series data. Must have shape (n_sessions, n_samples, n_channels) or (n_samples, n_channels).

  • sampling_frequency (float) – Sampling frequency in Hz.

  • window_length (int, optional) – Length of the data segment to use to calculate spectra. If None, we use 2 * sampling_frequency.

  • step_size (int, optional) – Step size for shifting the window. If None, we use window_length // 2.

  • frequency_range (list, optional) – Minimum and maximum frequency to keep.

  • standardize (bool, optional) – Should we standardize the data before calculating the spectra?

  • calc_coh (bool, optional) – Should we also return the coherence spectra?

  • return_weights (bool, optional) – Should we return the weights for session-specific spectra? This is useful for calculating a group average.

  • keepdims (bool, optional) – Should we enforce a (n_sessions, …) array is returned for psd and coh? If False, we remove any dimension of length 1.

  • n_jobs (int, optional) – Number of parallel jobs.

Returns:

  • f (np.ndarray) – Frequencies of the power spectra and coherences. Shape is (n_freq,).

  • psd (np.ndarray) – Power spectra. Shape is (n_sessions, n_channels, n_freq). Any axis of length 1 is removed if keepdims=False.

  • coh (np.ndarray) – Coherences. Shape is (n_sessions, n_channels, n_channels, n_freq). Any axis of length 1 is removed if keepdims=False. Only returned is calc_coh=True.

  • w (np.ndarray) – Weighting for session-specific spectra. Only returned if return_weights=True. Shape is (n_sessions,).

osl_dynamics.analysis.static.multitaper_spectra(data, sampling_frequency, window_length=None, time_half_bandwidth=4, n_tapers=7, frequency_range=None, standardize=True, calc_coh=False, return_weights=False, keepdims=False, n_jobs=1)[source]#

Calculate multitaper spectra.

Wrapper for spectral.multitaper_spectra assuming only one state is active for all time points.

Parameters:
  • data (np.ndarray or list) – Time series data. Must have shape (n_sessions, n_samples, n_channels) or (n_samples, n_channels).

  • sampling_frequency (float) – Sampling frequency in Hz.

  • window_length (int, optional) – Length of the data segement to use to calculate the multitaper.

  • time_half_bandwidth (float, optional) – Parameter to control the resolution of the spectra.

  • n_tapers (int, optional) – Number of tapers.

  • frequency_range (list, optional) – Minimum and maximum frequency to keep.

  • standardize (bool, optional) – Should we standardize the data before calculating the multitaper?

  • calc_coh (bool, optional) – Should we also return the coherence spectra?

  • return_weights (bool, optional) – Should we return the weights for session-specific PSDs? Useful for calculating the group average PSD.

  • keepdims (bool, optional) – Should we enforce a (n_sessions, n_states, …) array is returned for psd and coh? If False, we remove any dimension of length 1.

  • n_jobs (int, optional) – Number of parallel jobs.

Returns:

  • f (np.ndarray) – Frequencies of the power spectra and coherences. Shape is (n_freq,).

  • psd (np.ndarray) – Power spectra. Shape is (n_sessions, n_channels, n_freq). Any axis of length 1 is removed if keepdims=False.

  • coh (np.ndarray) – Coherences. Shape is (n_sessions, n_channels, n_channels, n_freq). Any axis of length 1 is removed if keepdims=False. Only returned is calc_coh=True.

  • w (np.ndarray) – Weighting for session-specific spectra. Only returned if return_weights=True. Shape is (n_sessions,).