[med-svn] [python-mne] 141/353: ENH : add average ref to mne_compute_proj_ecg.py and support for manual bad channels
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:24:46 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 70fc89b3e3a07b9661774b6b0a30dbb937e57496
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Thu Apr 12 13:13:26 2012 +0200
ENH : add average ref to mne_compute_proj_ecg.py and support for manual bad channels
---
bin/mne_compute_proj_ecg.py | 27 ++++++++++++++++++++++++---
mne/epochs.py | 12 +++---------
mne/fiff/proj.py | 30 ++++++++++++++++++++++++++++++
3 files changed, 57 insertions(+), 12 deletions(-)
diff --git a/bin/mne_compute_proj_ecg.py b/bin/mne_compute_proj_ecg.py
index 9ddb9fc..b30375c 100755
--- a/bin/mne_compute_proj_ecg.py
+++ b/bin/mne_compute_proj_ecg.py
@@ -15,7 +15,7 @@ import mne
def compute_proj_ecg(in_fif_fname, tmin, tmax, n_grad, n_mag, n_eeg, l_freq,
h_freq, average, preload, filter_length, n_jobs, ch_name,
- reject):
+ reject, avg_ref, bads):
"""Compute SSP/PCA projections for ECG artifacts
Parameters
@@ -45,8 +45,14 @@ def compute_proj_ecg(in_fif_fname, tmin, tmax, n_grad, n_mag, n_eeg, l_freq,
print "Writing ECG events in %s" % ecg_event_fname
mne.write_events(ecg_event_fname, ecg_events)
+ if avg_ref:
+ print "Adding average EEG reference projection."
+ eeg_proj = mne.fiff.proj.make_eeg_average_ref_proj(raw.info)
+ raw.info['projs'].append(eeg_proj)
+
print 'Computing ECG projector'
+ # Handler rejection parameters
if len(mne.fiff.pick_types(raw.info, meg='grad', eeg=False, eog=False)) == 0:
del reject['grad']
if len(mne.fiff.pick_types(raw.info, meg='mag', eeg=False, eog=False)) == 0:
@@ -57,7 +63,7 @@ def compute_proj_ecg(in_fif_fname, tmin, tmax, n_grad, n_mag, n_eeg, l_freq,
del reject['eog']
picks = mne.fiff.pick_types(raw.info, meg=True, eeg=True, eog=True,
- exclude=raw.info['bads'])
+ exclude=raw.info['bads'] + bads)
if l_freq is None and h_freq is not None:
raw.high_pass_filter(picks, h_freq, filter_length, n_jobs)
if l_freq is not None and h_freq is None:
@@ -141,6 +147,12 @@ if __name__ == '__main__':
parser.add_option("-o", "--rej-eog", dest="rej_eog",
help="EOG rejection parameter in uV (peak to peak amplitude)",
default=250)
+ parser.add_option("-v", "--avg-ref", dest="avg_ref", action="store_true",
+ help="Add EEG average reference proj",
+ default=False)
+ parser.add_option("-d", "--bad", dest="bad_fname",
+ help="Text file containing bad channels list (one per line)",
+ default=None)
options, args = parser.parse_args()
@@ -161,6 +173,15 @@ if __name__ == '__main__':
mag=1e-15 * float(options.rej_mag),
eeg=1e-6 * float(options.rej_eeg),
eog=1e-6 * float(options.rej_eog))
+ avg_ref = options.avg_ref
+ bad_fname = options.bad_fname
+
+ if bad_fname is not None:
+ bads = [w.rstrip().split()[0] for w in open(bad_fname).readlines()]
+ print 'Bad channels read : %s' % bads
+ else:
+ bads = []
compute_proj_ecg(raw_in, tmin, tmax, n_grad, n_mag, n_eeg, l_freq, h_freq,
- average, preload, filter_length, n_jobs, ch_name, reject)
+ average, preload, filter_length, n_jobs, ch_name, reject,
+ avg_ref, bads)
diff --git a/mne/epochs.py b/mne/epochs.py
index 9116241..5be55e1 100644
--- a/mne/epochs.py
+++ b/mne/epochs.py
@@ -9,7 +9,7 @@ import fiff
import warnings
from .fiff import Evoked
from .fiff.pick import pick_types, channel_indices_by_type
-from .fiff.proj import activate_proj
+from .fiff.proj import activate_proj, make_eeg_average_ref_proj
from .baseline import rescale
@@ -148,14 +148,8 @@ class Epochs(object):
# Add EEG ref reference proj
print "Adding average EEG reference projection."
eeg_sel = pick_types(self.info, meg=False, eeg=True)
- eeg_names = [self.ch_names[k] for k in eeg_sel]
- n_eeg = len(eeg_sel)
- if n_eeg > 0:
- vec = np.ones((1, n_eeg)) / n_eeg
- eeg_proj_data = dict(col_names=eeg_names, row_names=None,
- data=vec, nrow=1, ncol=n_eeg)
- eeg_proj = dict(active=True, data=eeg_proj_data,
- desc='Average EEG reference', kind=1)
+ if len(eeg_sel) > 0:
+ eeg_proj = make_eeg_average_ref_proj(self.info)
self.info['projs'].append(eeg_proj)
# Create the projector
diff --git a/mne/fiff/proj.py b/mne/fiff/proj.py
index 86ee892..0b0ca9c 100644
--- a/mne/fiff/proj.py
+++ b/mne/fiff/proj.py
@@ -11,6 +11,7 @@ from scipy import linalg
from .tree import dir_tree_find
from .constants import FIFF
from .tag import find_tag
+from .pick import pick_types
from ..utils import deprecated
@@ -349,3 +350,32 @@ def activate_proj(projs, copy=True):
print '%d projection items activated' % len(projs)
return projs
+
+
+def make_eeg_average_ref_proj(info):
+ """Create an EEG average reference SSP projection vector
+
+ Parameters
+ ----------
+ info: dict
+ Measurement info
+
+ Returns
+ -------
+ eeg_proj: instance of Projection
+ The SSP/PCA projector
+ """
+ print "Adding average EEG reference projection."
+ eeg_sel = pick_types(info, meg=False, eeg=True)
+ ch_names = info['ch_names']
+ eeg_names = [ch_names[k] for k in eeg_sel]
+ n_eeg = len(eeg_sel)
+ if n_eeg == 0:
+ raise ValueError('Cannot create EEG average reference projector '
+ '(no EEG data found)')
+ vec = np.ones((1, n_eeg)) / n_eeg
+ eeg_proj_data = dict(col_names=eeg_names, row_names=None,
+ data=vec, nrow=1, ncol=n_eeg)
+ eeg_proj = Projection(active=True, data=eeg_proj_data,
+ desc='Average EEG reference', kind=1)
+ return eeg_proj
--
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