55Parameterizing neural power spectra with MNE, doing a topographical analysis.
66
77This tutorial requires that you have `MNE <https://mne-tools.github.io/>`_
8- installed.
8+ installed. This tutorial needs mne >= 1.2.
99
1010If you don't already have MNE, you can follow instructions to get it
1111`here <https://mne-tools.github.io/stable/getting_started.html>`_.
2323
2424# Import MNE, as well as the MNE sample dataset
2525import mne
26- from mne import io
2726from mne .datasets import sample
28- from mne .viz import plot_topomap
29- from mne .time_frequency import psd_welch
3027
3128# FOOOF imports
3229from fooof import FOOOFGroup
5249###################################################################################################
5350
5451# Get the data path for the MNE example data
55- raw_fname = sample .data_path () + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
56- event_fname = sample .data_path () + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
52+ raw_fname = sample .data_path () / 'MEG' / 'sample' / 'sample_audvis_filt-0-40_raw.fif'
5753
5854# Load the example MNE data
5955raw = mne .io .read_raw_fif (raw_fname , preload = True , verbose = False )
6056
6157###################################################################################################
6258
6359# Select EEG channels from the dataset
64- raw = raw .pick_types ( meg = False , eeg = True , eog = False , exclude = 'bads' )
60+ raw = raw .pick ([ ' eeg' ] , exclude = 'bads' )
6561
6662###################################################################################################
6763
@@ -110,15 +106,16 @@ def check_nans(data, nan_policy='zero'):
110106# frequency representations - meaning we have to calculate power spectra.
111107#
112108# To do so, we will leverage the time frequency tools available with MNE,
113- # in the `time_frequency` module. In particular, we can use the ``psd_welch ``
114- # function , that takes in MNE data objects and calculates and returns power spectra.
109+ # in the `time_frequency` module. In particular, we can use the ``compute_psd ``
110+ # method , that takes in MNE data objects and calculates and returns power spectra.
115111#
116112
117113###################################################################################################
118114
119- # Calculate power spectra across the the continuous data
120- spectra , freqs = psd_welch (raw , fmin = 1 , fmax = 40 , tmin = 0 , tmax = 250 ,
121- n_overlap = 150 , n_fft = 300 )
115+ # Calculate power spectra across the continuous data
116+ psd = raw .compute_psd (method = "welch" , fmin = 1 , fmax = 40 , tmin = 0 , tmax = 250 ,
117+ n_overlap = 150 , n_fft = 300 )
118+ spectra , freqs = psd .get_data (return_freqs = True )
122119
123120###################################################################################################
124121# Fitting Power Spectrum Models
@@ -193,7 +190,7 @@ def check_nans(data, nan_policy='zero'):
193190###################################################################################################
194191
195192# Plot the topography of alpha power
196- plot_topomap (alpha_pw , raw .info , cmap = cm .viridis , contours = 0 );
193+ mne . viz . plot_topomap (alpha_pw , raw .info , cmap = cm .viridis , contours = 0 , size = 4 )
197194
198195###################################################################################################
199196#
@@ -214,8 +211,7 @@ def check_nans(data, nan_policy='zero'):
214211 band_power = check_nans (get_band_peak_fg (fg , band_def )[:, 1 ])
215212
216213 # Create a topomap for the current oscillation band
217- mne .viz .plot_topomap (band_power , raw .info , cmap = cm .viridis , contours = 0 ,
218- axes = axes [ind ], show = False );
214+ mne .viz .plot_topomap (band_power , raw .info , cmap = cm .viridis , contours = 0 , axes = axes [ind ])
219215
220216 # Set the plot title
221217 axes [ind ].set_title (label + ' power' , {'fontsize' : 20 })
@@ -268,7 +264,7 @@ def check_nans(data, nan_policy='zero'):
268264###################################################################################################
269265
270266# Plot the topography of aperiodic exponents
271- plot_topomap (exps , raw .info , cmap = cm .viridis , contours = 0 )
267+ mne . viz . plot_topomap (exps , raw .info , cmap = cm .viridis , contours = 0 , size = 4 )
272268
273269###################################################################################################
274270#
@@ -297,6 +293,3 @@ def check_nans(data, nan_policy='zero'):
297293# In this example, we have seen how to apply power spectrum models to data that is
298294# managed and processed with MNE.
299295#
300-
301- ###################################################################################################
302- #
0 commit comments