[med-svn] [python-mne] 193/353: ENH : nicer plot of PSD in examples

Yaroslav Halchenko debian at onerussian.com
Fri Nov 27 17:24:56 UTC 2015


This is an automated email from the git hooks/post-receive script.

yoh pushed a commit to tag 0.4
in repository python-mne.

commit de823d0bc45c5722dedcffa8b5a783f6c2b644aa
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date:   Sun Jun 17 16:16:30 2012 +0300

    ENH : nicer plot of PSD in examples
---
 examples/time_frequency/plot_compute_raw_data_spectrum.py | 14 +++++++++-----
 mne/time_frequency/psd.py                                 | 10 ++++++++--
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/examples/time_frequency/plot_compute_raw_data_spectrum.py b/examples/time_frequency/plot_compute_raw_data_spectrum.py
index 2ad542b..20c6bd6 100644
--- a/examples/time_frequency/plot_compute_raw_data_spectrum.py
+++ b/examples/time_frequency/plot_compute_raw_data_spectrum.py
@@ -30,13 +30,17 @@ exclude = raw.info['bads'] + ['MEG 2443', 'EEG 053']  # bads + 2 more
 
 # picks MEG gradiometers
 picks = fiff.pick_types(raw.info, meg='grad', eeg=False, eog=False,
-                                                stim=False, exclude=exclude)
+                        stim=False, exclude=exclude)
 
 tmin, tmax = 0, 60  # use the first 60s of data
-fmin, fmax = 2, 70  # look at frequencies between 5 and 70Hz
+fmin, fmax = 2, 300  # look at frequencies between 5 and 70Hz
 NFFT = 2048 # the FFT size (NFFT). Ideally a power of 2
 psds, freqs = compute_raw_psd(raw, tmin=tmin, tmax=tmax, picks=picks,
-                              fmin=fmin, fmax=fmax, NFFT=NFFT, n_jobs=1)
+                              fmin=fmin, fmax=fmax, NFFT=NFFT, n_jobs=1,
+                              plot=False)
+
+# Convert PSDs to dB
+psds = 10 * np.log10(psds)
 
 ###############################################################################
 # Compute mean and standard deviation accross channels and then plot
@@ -46,10 +50,10 @@ psd_std = np.std(psds, axis=0)
 hyp_limits = (psd_mean - psd_std, psd_mean + psd_std)
 
 import pylab as pl
-pl.close('all')
+pl.figure()
 pl.plot(freqs, psd_mean)
 pl.fill_between(freqs, hyp_limits[0], y2=hyp_limits[1], color=(1, 0, 0, .3),
                 alpha=0.5)
 pl.xlabel('Freq (Hz)')
-pl.ylabel('PSD')
+pl.ylabel('Power Spectral Density (dB/Hz)')
 pl.show()
diff --git a/mne/time_frequency/psd.py b/mne/time_frequency/psd.py
index c1ffdae..efbd631 100644
--- a/mne/time_frequency/psd.py
+++ b/mne/time_frequency/psd.py
@@ -7,7 +7,8 @@ from ..parallel import parallel_func
 
 
 def compute_raw_psd(raw, tmin=0, tmax=np.inf, picks=None,
-                            fmin=0, fmax=np.inf,  NFFT=2048, n_jobs=1):
+                    fmin=0, fmax=np.inf, NFFT=2048, n_jobs=1,
+                    plot=False):
     """Compute power spectral density with multi-taper
 
     Parameters
@@ -38,6 +39,9 @@ def compute_raw_psd(raw, tmin=0, tmax=np.inf, picks=None,
     n_jobs: int
         Number of CPUs to use in the computation.
 
+    plot: bool
+        Plot each PSD estimates
+
     Return
     ------
     psd: array of float
@@ -58,8 +62,10 @@ def compute_raw_psd(raw, tmin=0, tmax=np.inf, picks=None,
     print "Effective window size : %s (s)" % (NFFT * Fs)
 
     parallel, my_psd, n_jobs = parallel_func(pl.psd, n_jobs, verbose=0)
+    fig = pl.figure()
     out = parallel(my_psd(d, Fs=Fs, NFFT=NFFT) for d in data)
-
+    if not plot:
+        pl.close(fig)
     freqs = out[0][1]
     psd = np.array(zip(*out)[0])
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git



More information about the debian-med-commit mailing list