[med-svn] [python-mne] 222/376: ENH : better handling of SSP projection in Epochs and Evoked
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:22:44 UTC 2015
This is an automated email from the git hooks/post-receive script.
yoh pushed a commit to annotated tag v0.1
in repository python-mne.
commit 39582d5450f990c4186ff8e90a6d7656ce0532b3
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Tue Apr 26 15:56:30 2011 -0400
ENH : better handling of SSP projection in Epochs and Evoked
---
examples/plot_read_epochs.py | 2 +-
examples/plot_read_evoked.py | 2 +-
mne/epochs.py | 28 +++++++++++++++++++---------
mne/fiff/evoked.py | 32 +++++++++++++++++++++++++++++++-
4 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/examples/plot_read_epochs.py b/examples/plot_read_epochs.py
index c1d3588..00d7297 100755
--- a/examples/plot_read_epochs.py
+++ b/examples/plot_read_epochs.py
@@ -37,7 +37,7 @@ picks = fiff.pick_types(raw.info, meg=True, eeg=False, stim=True, eog=True,
exclude=exclude)
# Read epochs
-epochs = mne.Epochs(raw, events, event_id, tmin, tmax,
+epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
picks=picks, baseline=(None, 0), preload=True,
reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))
evoked = epochs.average() # average epochs to get the evoked response
diff --git a/examples/plot_read_evoked.py b/examples/plot_read_evoked.py
index d81ebe3..f266f41 100755
--- a/examples/plot_read_evoked.py
+++ b/examples/plot_read_evoked.py
@@ -19,7 +19,7 @@ data_path = sample.data_path('.')
fname = data_path + '/MEG/sample/sample_audvis-ave.fif'
# Reading
-evoked = fiff.Evoked(fname, setno=0, baseline=(None, 0))
+evoked = fiff.Evoked(fname, setno=0, baseline=(None, 0), proj=True)
###############################################################################
# Show result
diff --git a/mne/epochs.py b/mne/epochs.py
index c61f205..68dab67 100755
--- a/mne/epochs.py
+++ b/mne/epochs.py
@@ -66,6 +66,9 @@ class Epochs(object):
Valid keys are 'grad' | 'mag' | 'eeg' | 'eog' | 'ecg'
If flat is None then no rejection is done.
+ proj : bool, optional
+ Apply SSP projection vectors
+
Methods
-------
get_epoch(i) : self
@@ -82,7 +85,7 @@ class Epochs(object):
def __init__(self, raw, events, event_id, tmin, tmax, baseline=(None, 0),
picks=None, name='Unknown', keep_comp=False, dest_comp=0,
- preload=False, reject=None, flat=None):
+ preload=False, reject=None, flat=None, proj=True):
self.raw = raw
self.event_id = event_id
self.tmin = tmin
@@ -113,28 +116,28 @@ class Epochs(object):
raise ValueError("Picks cannot be empty.")
# Set up projection
- if raw.info['projs'] is None:
+ if self.info['projs'] is None or not proj:
print 'No projector specified for these data'
- raw['proj'] = []
+ self.proj = None
else:
# Activate the projection items
- for proj in raw.info['projs']:
+ for proj in self.info['projs']:
proj['active'] = True
- print '%d projection items activated' % len(raw.info['projs'])
+ print '%d projection items activated' % len(self.info['projs'])
# Create the projector
- proj, nproj = fiff.proj.make_projector_info(raw.info)
+ proj, nproj = fiff.proj.make_projector_info(self.info)
if nproj == 0:
print 'The projection vectors do not apply to these channels'
- raw['proj'] = None
+ self.proj = None
else:
print ('Created an SSP operator (subspace dimension = %d)'
% nproj)
- raw['proj'] = proj
+ self.proj = proj
# Set up the CTF compensator
- current_comp = fiff.get_current_comp(raw.info)
+ current_comp = fiff.get_current_comp(self.info)
if current_comp > 0:
print 'Current compensation grade : %d' % current_comp
@@ -184,6 +187,9 @@ class Epochs(object):
self.info['nchan'] = len(idx)
self.ch_names = self.info['ch_names']
+ if self.proj is not None:
+ self.proj = self.proj[idx][:, idx]
+
if self.preload:
self._data = self._data[:, idx, :]
@@ -211,6 +217,10 @@ class Epochs(object):
stop = start + len(self.times)
epoch, _ = self.raw[self.picks, start:stop]
+ if self.proj is not None:
+ print "SSP projectors applied..."
+ epoch = np.dot(self.proj, epoch)
+
# Run baseline correction
times = self.times
baseline = self.baseline
diff --git a/mne/fiff/evoked.py b/mne/fiff/evoked.py
index aadd7a0..47d8b13 100755
--- a/mne/fiff/evoked.py
+++ b/mne/fiff/evoked.py
@@ -10,6 +10,7 @@ from .open import fiff_open
from .tag import read_tag
from .tree import dir_tree_find
from .meas_info import read_meas_info, write_meas_info
+from .proj import make_projector_info
from .write import start_file, start_block, end_file, end_block, \
write_int, write_string, write_float_matrix, \
@@ -43,7 +44,7 @@ class Evoked(object):
Evoked response.
"""
- def __init__(self, fname, setno=None, baseline=None):
+ def __init__(self, fname, setno=None, baseline=None, proj=True):
"""
Parameters
----------
@@ -54,6 +55,10 @@ class Evoked(object):
setno : int
Dataset ID number. Optional if there is only one data set
in file.
+
+ proj : bool, optional
+ Apply SSP projection vectors
+
"""
if fname is None:
@@ -206,6 +211,31 @@ class Evoked(object):
times = np.arange(first, last + 1, dtype=np.float) / info['sfreq']
+ # Set up projection
+ if info['projs'] is None or not proj:
+ print 'No projector specified for these data'
+ self.proj = None
+ else:
+ # Activate the projection items
+ for proj in info['projs']:
+ proj['active'] = True
+
+ print '%d projection items activated' % len(info['projs'])
+
+ # Create the projector
+ proj, nproj = make_projector_info(info)
+ if nproj == 0:
+ print 'The projection vectors do not apply to these channels'
+ self.proj = None
+ else:
+ print ('Created an SSP operator (subspace dimension = %d)'
+ % nproj)
+ self.proj = proj
+
+ if self.proj is not None:
+ print "SSP projectors applied..."
+ all_data = np.dot(self.proj, all_data)
+
# Run baseline correction
if baseline is not None:
print "Applying baseline correction ..."
--
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