spectral is a python software package that computes frequency-domain brain connectivity measures such as coherence, spectral granger causality, and the phase lag index using the multitaper Fourier transform. Although there are other python packages that do this (see nitime and MNE-Python), spectral has several differences:
- it is designed to handle multiple time series at once
- it caches frequently computed quantities such as the cross-spectral matrix and minimum-phase-decomposition, so that connectivity measures that use the same processing steps can be more quickly computed.
- it decouples the time-frequency transform and the connectivity measures so that if you already have a preferred way of computing Fourier coefficients (i.e. from a wavelet transform), you can use that instead.
- it implements the non-parametric version of the spectral granger causality in Python.
- it implements the canonical coherence, which can efficiently summarize brain-area level coherences from multielectrode recordings.
- easier user interface for the multitaper fourier transform
See the notebooks (#1, #2) for more information on how to use the package.
Functional
- coherency
- canonical_coherence
- imaginary_coherence
- phase_locking_value
- phase_lag_index
- weighted_phase_lag_index
- debiased_squared_phase_lag_index
- debiased_squared_weighted_phase_lag_index
- pairwise_phase_consistency
Directed
- directed_transfer_function
- directed_coherence
- partial_directed_coherence
- generalized_partial_directed_coherence
- direct_directed_transfer_function
- group_delay
- phase_lag_index
- pairwise_spectral_granger_prediction
- Install miniconda (or anaconda) if it isn't already installed. Type into bash (or install from the anaconda website):
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
hash -r- Go to the local repository (
.../spectral) and install the anaconda environment for the repository. Type into bash:
conda update -q conda
conda info -a
conda env create -f environment.yml
source activate spectral
python setup.py developfrom spectral import Multitaper, Connectivity
m = Multitaper(time_series=signals,
sampling_frequency=sampling_frequency,
time_halfbandwidth_product=time_halfbandwidth_product,
time_window_duration=0.060,
time_window_step=0.060,
start_time=time[0])
c = Connectivity.from_multitaper(m)
coherence = c.coherence_magnitude()
weighted_phase_lag_index = c.weighted_phase_lag_index()
canonical_coherence = c.canonical_coherence(brain_area_labels)We hope to take advantage of the labeled data of the xarray package.