[med-svn] [python-mne] 159/353: preproc: ecg_proj rework
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:24:50 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 46c676d67f66276d9c5383de679739b8ba27e937
Author: Martin Luessi <mluessi at nmr.mgh.harvard.edu>
Date: Thu Apr 26 14:18:36 2012 -0400
preproc: ecg_proj rework
---
bin/mne_compute_proj_ecg.py | 104 ++++++++++----------------------------------
mne/__init__.py | 1 +
mne/fiff/__init__.py | 3 +-
mne/preprocessing.py | 59 -------------------------
4 files changed, 25 insertions(+), 142 deletions(-)
diff --git a/bin/mne_compute_proj_ecg.py b/bin/mne_compute_proj_ecg.py
index e3c2712..a054aa1 100755
--- a/bin/mne_compute_proj_ecg.py
+++ b/bin/mne_compute_proj_ecg.py
@@ -7,91 +7,13 @@ $mne_compute_proj_ecg.py -i sample_audvis_raw.fif -c "MEG 1531" --l-freq 1 --h-f
"""
# Authors : Alexandre Gramfort, Ph.D.
+# Martin Luessi, Ph.D.
import sys
import os
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, avg_ref, bads):
- """Compute SSP/PCA projections for ECG artifacts
-
- Parameters
- ----------
- in_fif_fname: string
- Raw fif File
- XXX
- """
- # Reading fif File
- raw = mne.fiff.Raw(in_fif_fname, preload=preload)
-
- if in_fif_fname.endswith('_raw.fif') or in_fif_fname.endswith('-raw.fif'):
- prefix = in_fif_fname[:-8]
- else:
- prefix = in_fif_fname[:-4]
-
- ecg_event_fname = prefix + '_ecg-eve.fif'
-
- if average:
- ecg_proj_fname = prefix + '_ecg_avg_proj.fif'
- else:
- ecg_proj_fname = prefix + '_ecg_proj.fif'
-
- print 'Running ECG SSP computation'
-
- ecg_events, _, _ = mne.artifacts.find_ecg_events(raw, ch_name=ch_name)
- 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:
- del reject['mag']
- if len(mne.fiff.pick_types(raw.info, meg=False, eeg=True, eog=False)) == 0:
- del reject['eeg']
- if len(mne.fiff.pick_types(raw.info, meg=False, eeg=False, eog=True)) == 0:
- del reject['eog']
-
- picks = mne.fiff.pick_types(raw.info, meg=True, eeg=True, eog=True,
- 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:
- raw.low_pass_filter(picks, h_freq, filter_length, n_jobs)
- if l_freq is not None and h_freq is not None:
- raw.band_pass_filter(picks, l_freq, h_freq, filter_length, n_jobs)
-
- epochs = mne.Epochs(raw, ecg_events, None, tmin, tmax, baseline=None,
- picks=picks, reject=reject, proj=True)
-
- projs_init = raw.info['projs']
-
- if average:
- evoked = epochs.average()
- projs = mne.compute_proj_evoked(evoked, n_grad=n_grad, n_mag=n_mag,
- n_eeg=n_eeg)
- else:
- projs = mne.compute_proj_epochs(epochs, n_grad=n_grad, n_mag=n_mag,
- n_eeg=n_eeg)
-
- if preload is not None and os.path.exists(preload):
- os.remove(preload)
-
- print "Writing ECG projections in %s" % ecg_proj_fname
- mne.write_proj(ecg_proj_fname, projs + projs_init)
- print 'Done.'
-
-
if __name__ == '__main__':
from optparse import OptionParser
@@ -150,6 +72,9 @@ if __name__ == '__main__':
parser.add_option("--avg-ref", dest="avg_ref", action="store_true",
help="Add EEG average reference proj",
default=False)
+ parser.add_option("--existing", dest="include_existing", action="store_true",
+ help="Inlucde the SSP projectors currently in the fiff file",
+ default=True)
parser.add_option("--bad", dest="bad_fname",
help="Text file containing bad channels list (one per line)",
default=None)
@@ -179,6 +104,7 @@ if __name__ == '__main__':
eeg=1e-6 * float(options.rej_eeg),
eog=1e-6 * float(options.rej_eog))
avg_ref = options.avg_ref
+ include_existing = options.include_existing
bad_fname = options.bad_fname
if bad_fname is not None:
@@ -187,6 +113,20 @@ if __name__ == '__main__':
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,
- avg_ref, bads)
+ if raw_in.endswith('_raw.fif') or raw_in.endswith('-raw.fif'):
+ prefix = raw_in[:-8]
+ else:
+ prefix = raw_in[:-4]
+
+ ecg_event_fname = prefix + '_ecg-eve.fif'
+
+ if average:
+ ecg_proj_fname = prefix + '_ecg_avg_proj.fif'
+ else:
+ ecg_proj_fname = prefix + '_ecg_proj.fif'
+
+ mne.preprocessing.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, bads,
+ avg_ref, include_existing, ecg_proj_fname, ecg_event_fname)
+
diff --git a/mne/__init__.py b/mne/__init__.py
index 7ab8ac9..7cfab2e 100644
--- a/mne/__init__.py
+++ b/mne/__init__.py
@@ -26,3 +26,4 @@ from . import fiff
from . import artifacts
from . import stats
from . import viz
+from . import preprocessing
diff --git a/mne/fiff/__init__.py b/mne/fiff/__init__.py
index 138b22a..3418624 100644
--- a/mne/fiff/__init__.py
+++ b/mne/fiff/__init__.py
@@ -15,5 +15,6 @@ from .pick import pick_types, pick_channels, pick_types_evoked, \
pick_types_forward, pick_channels_cov
from .compensator import get_current_comp
-from .proj import compute_spatial_vectors, proj_equal
+from .proj import compute_spatial_vectors, proj_equal, \
+ make_eeg_average_ref_proj
from .cov import read_cov, write_cov
diff --git a/mne/preprocessing.py b/mne/preprocessing.py
deleted file mode 100644
index 0a8a6a8..0000000
--- a/mne/preprocessing.py
+++ /dev/null
@@ -1,59 +0,0 @@
-# import numpy as np
-#
-# from .fiff.proj import make_projector_info
-# from .fiff.compensator import get_current_comp
-# from .fiff.compensator import compensate_to, make_compensator
-
-# XXX
-
-# def cancel_noise(data, dest_comp=0):
-# """Do projection and compensation as needed
-#
-# Return the appropriate operators
-#
-# [res,proj,comp] = mne_ex_cancel_noise(data,dest_comp)
-#
-# res - Data after noise cancellation
-# proj - The projection operator applied
-# comp - The compensator which brings uncompensated data to the
-# desired compensation grade (will be useful in forward
-# calculations)
-#
-# """
-# #
-# # Compensate the data and make a compensator for forward modelling
-# #
-# comp = []
-# proj = []
-# comp_now = get_current_comp(data['info'])
-# if comp_now == dest_comp:
-# res = data
-# else:
-# res = compensate_to(data, dest_comp)
-# print 'The data are now compensated to grade %d.' % dest_comp
-#
-# if dest_comp > 0:
-# comp = make_compensator(res['info'], 0, dest_comp)
-# print 'Appropriate forward operator compensator created.'
-# else:
-# print 'No forward operator compensator needed.'
-#
-# # Do the projection
-# if data['info']['projs'] is None:
-# print 'No projector included with these data.'
-# else:
-# # Activate the projection items
-# for k in range(len(res['info']['projs'])):
-# res['info']['projs'][k]['active'] = True;
-#
-# # Create the projector
-# proj, nproj = make_projector_info(res['info'])
-# if nproj == 0:
-# print 'The projection vectors do not apply to these channels'
-# proj = []
-# else:
-# print 'Created an SSP operator (subspace dimension = %d)' % nproj
-# res['evoked']['epochs'] = np.dot(proj, res['evoked']['epochs'])
-# print 'Projector applied to the data'
-#
-# return res, proj, comp
--
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