Skip to content

Commit 6bfdd32

Browse files
committed
Fix MNE example to work with MNE 1.3, which has deprecated psd_welch function
1 parent 8d8cb96 commit 6bfdd32

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

examples/analyses/plot_mne_example.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
###################################################################################################
1818

19+
import os.path
20+
1921
# General imports
2022
import numpy as np
2123
import matplotlib.pyplot as plt
@@ -26,7 +28,6 @@
2628
from mne import io
2729
from mne.datasets import sample
2830
from mne.viz import plot_topomap
29-
from mne.time_frequency import psd_welch
3031

3132
# FOOOF imports
3233
from fooof import FOOOFGroup
@@ -52,8 +53,8 @@
5253
###################################################################################################
5354

5455
# 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'
56+
raw_fname = os.path.join(sample.data_path(), 'MEG', 'sample', 'sample_audvis_filt-0-40_raw.fif')
57+
event_fname = os.path.join(sample.data_path(), 'MEG', 'sample', 'sample_audvis_filt-0-40_raw-eve.fif')
5758

5859
# Load the example MNE data
5960
raw = mne.io.read_raw_fif(raw_fname, preload=True, verbose=False)
@@ -110,15 +111,16 @@ def check_nans(data, nan_policy='zero'):
110111
# frequency representations - meaning we have to calculate power spectra.
111112
#
112113
# 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.
114+
# in the `time_frequency` module. In particular, we can use the ``compute_psd``
115+
# method, that takes in MNE data objects and calculates and returns power spectra.
115116
#
116117

117118
###################################################################################################
118119

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)
120+
# Calculate power spectra across the continuous data
121+
psd = raw.compute_psd(method="welch", fmin=1, fmax=40, tmin=0, tmax=250,
122+
n_overlap=150, n_fft=300)
123+
spectra, freqs = psd.get_data(return_freqs=True)
122124

123125
###################################################################################################
124126
# Fitting Power Spectrum Models

0 commit comments

Comments
 (0)