From 6bfdd32aa1d1c44f77ea0a813119e8469b878eae Mon Sep 17 00:00:00 2001 From: Charles Guan Date: Thu, 6 Apr 2023 15:42:29 -0700 Subject: [PATCH 1/3] Fix MNE example to work with MNE 1.3, which has deprecated psd_welch function --- examples/analyses/plot_mne_example.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/analyses/plot_mne_example.py b/examples/analyses/plot_mne_example.py index 1e46dafb9..a9fd6975c 100644 --- a/examples/analyses/plot_mne_example.py +++ b/examples/analyses/plot_mne_example.py @@ -16,6 +16,8 @@ ################################################################################################### +import os.path + # General imports import numpy as np import matplotlib.pyplot as plt @@ -26,7 +28,6 @@ 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 @@ -52,8 +53,8 @@ ################################################################################################### # 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 = os.path.join(sample.data_path(), 'MEG', 'sample', 'sample_audvis_filt-0-40_raw.fif') +event_fname = os.path.join(sample.data_path(), 'MEG', 'sample', 'sample_audvis_filt-0-40_raw-eve.fif') # Load the example MNE data raw = mne.io.read_raw_fif(raw_fname, preload=True, verbose=False) @@ -110,15 +111,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 From 3bf4a0077d62e40ac965158a254d3fd42731da23 Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Wed, 28 Jun 2023 17:17:08 -0700 Subject: [PATCH 2/3] add new min version for MNE example --- requirements-docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-docs.txt b/requirements-docs.txt index 1f36fc9f5..e43038411 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -10,7 +10,7 @@ matplotlib tqdm # Requirements for running the examples -mne +mne > 1.2 # Requirements for running the motivations neurodsp >= 2.0.0 \ No newline at end of file From d9f321816301a6dd94b7def510d12c271b321049 Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Wed, 28 Jun 2023 21:37:39 -0700 Subject: [PATCH 3/3] update mne example --- examples/analyses/plot_mne_example.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/examples/analyses/plot_mne_example.py b/examples/analyses/plot_mne_example.py index a9fd6975c..deef1f7a4 100644 --- a/examples/analyses/plot_mne_example.py +++ b/examples/analyses/plot_mne_example.py @@ -5,7 +5,7 @@ Parameterizing neural power spectra with MNE, doing a topographical analysis. This tutorial requires that you have `MNE `_ -installed. +installed. This tutorial needs mne >= 1.2. If you don't already have MNE, you can follow instructions to get it `here `_. @@ -16,8 +16,6 @@ ################################################################################################### -import os.path - # General imports import numpy as np import matplotlib.pyplot as plt @@ -25,9 +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 # FOOOF imports from fooof import FOOOFGroup @@ -53,8 +49,7 @@ ################################################################################################### # Get the data path for the MNE example data -raw_fname = os.path.join(sample.data_path(), 'MEG', 'sample', 'sample_audvis_filt-0-40_raw.fif') -event_fname = os.path.join(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) @@ -62,7 +57,7 @@ ################################################################################################### # Select EEG channels from the dataset -raw = raw.pick_types(meg=False, eeg=True, eog=False, exclude='bads') +raw = raw.pick(['eeg'], exclude='bads') ################################################################################################### @@ -195,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) ################################################################################################### # @@ -216,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}) @@ -270,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) ################################################################################################### # @@ -299,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. # - -################################################################################################### -#