Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions examples/analyses/plot_mne_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Parameterizing neural power spectra with MNE, doing a topographical analysis.

This tutorial requires that you have `MNE <https://mne-tools.github.io/>`_
installed.
installed. This tutorial needs mne >= 1.2.

If you don't already have MNE, you can follow instructions to get it
`here <https://mne-tools.github.io/stable/getting_started.html>`_.
Expand All @@ -23,10 +23,7 @@

# Import MNE, as well as the MNE sample dataset
import mne
from mne import io
from mne.datasets import sample
from mne.viz import plot_topomap
from mne.time_frequency import psd_welch

# FOOOF imports
from fooof import FOOOFGroup
Expand All @@ -52,16 +49,15 @@
###################################################################################################

# Get the data path for the MNE example data
raw_fname = sample.data_path() + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
event_fname = sample.data_path() + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
raw_fname = sample.data_path() / 'MEG' / 'sample' / 'sample_audvis_filt-0-40_raw.fif'

# Load the example MNE data
raw = mne.io.read_raw_fif(raw_fname, preload=True, verbose=False)

###################################################################################################

# Select EEG channels from the dataset
raw = raw.pick_types(meg=False, eeg=True, eog=False, exclude='bads')
raw = raw.pick(['eeg'], exclude='bads')

###################################################################################################

Expand Down Expand Up @@ -110,15 +106,16 @@ def check_nans(data, nan_policy='zero'):
# frequency representations - meaning we have to calculate power spectra.
#
# To do so, we will leverage the time frequency tools available with MNE,
# in the `time_frequency` module. In particular, we can use the ``psd_welch``
# function, that takes in MNE data objects and calculates and returns power spectra.
# in the `time_frequency` module. In particular, we can use the ``compute_psd``
# method, that takes in MNE data objects and calculates and returns power spectra.
#

###################################################################################################

# Calculate power spectra across the the continuous data
spectra, freqs = psd_welch(raw, fmin=1, fmax=40, tmin=0, tmax=250,
n_overlap=150, n_fft=300)
# Calculate power spectra across the continuous data
psd = raw.compute_psd(method="welch", fmin=1, fmax=40, tmin=0, tmax=250,
n_overlap=150, n_fft=300)
spectra, freqs = psd.get_data(return_freqs=True)

###################################################################################################
# Fitting Power Spectrum Models
Expand Down Expand Up @@ -193,7 +190,7 @@ def check_nans(data, nan_policy='zero'):
###################################################################################################

# Plot the topography of alpha power
plot_topomap(alpha_pw, raw.info, cmap=cm.viridis, contours=0);
mne.viz.plot_topomap(alpha_pw, raw.info, cmap=cm.viridis, contours=0, size=4)

###################################################################################################
#
Expand All @@ -214,8 +211,7 @@ def check_nans(data, nan_policy='zero'):
band_power = check_nans(get_band_peak_fg(fg, band_def)[:, 1])

# Create a topomap for the current oscillation band
mne.viz.plot_topomap(band_power, raw.info, cmap=cm.viridis, contours=0,
axes=axes[ind], show=False);
mne.viz.plot_topomap(band_power, raw.info, cmap=cm.viridis, contours=0, axes=axes[ind])

# Set the plot title
axes[ind].set_title(label + ' power', {'fontsize' : 20})
Expand Down Expand Up @@ -268,7 +264,7 @@ def check_nans(data, nan_policy='zero'):
###################################################################################################

# Plot the topography of aperiodic exponents
plot_topomap(exps, raw.info, cmap=cm.viridis, contours=0)
mne.viz.plot_topomap(exps, raw.info, cmap=cm.viridis, contours=0, size=4)

###################################################################################################
#
Expand Down Expand Up @@ -297,6 +293,3 @@ def check_nans(data, nan_policy='zero'):
# In this example, we have seen how to apply power spectrum models to data that is
# managed and processed with MNE.
#

###################################################################################################
#
2 changes: 1 addition & 1 deletion requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ matplotlib
tqdm

# Requirements for running the examples
mne
mne > 1.2

# Requirements for running the motivations
neurodsp >= 2.0.0