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 a6a18189771f6c8306eb72fc449d20c66ce522ea Author: Alexandre Gramfort <[email protected]> Date: Tue Mar 29 14:29:30 2011 -0400 fix epoch rejection --- mne/epochs.py | 54 +++++++++++++++++++++++++-------------- mne/fiff/pick.py | 18 ++++++++++--- mne/fiff/tests/data/test-ave.fif | Bin 5546473 -> 5546473 bytes mne/tests/test_epochs.py | 32 +++++++++++++++-------- 4 files changed, 71 insertions(+), 33 deletions(-) diff --git a/mne/epochs.py b/mne/epochs.py index 2838039..ef167ee 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -227,16 +227,16 @@ class Epochs(object): Parameters ---------- grad : float - Max value for gradiometers. (about 5000e-13). + Max value for gradiometers. (about 4000 fT / cm = 4000e-13 T / m). If None do not reject based on gradiometers. mag : float - Max value for magnetometers. (about 6e-12) + Max value for magnetometers. (about 4000 fT = 4e-12 T) If None do not reject based on magnetometers. eeg : float - Max value for EEG. (about 40e-6) + Max value for EEG. (about 40e-6 uV) If None do not reject based on EEG. eog : float - Max value for EEG. (about 250e-6) + Max value for EEG. (about 250e-6 uV) If None do not reject based on EOG. Returns @@ -258,24 +258,40 @@ class Epochs(object): if eog is not None and channel_type(self.info, idx) == 'eog': eog_idx.append(idx) - if len(eog_idx) == 0: - print "No EOG channel found. Do not rejecting based on EOG." + if grad is not None and len(grad_idx) == 0: + raise ValueError("No GRAD channel found. Cannot reject based on GRAD.") + elif grad is not None: + print "grad reject : %s fT/cm" % (1e13*grad) + if mag is not None and len(mag_idx) == 0: + raise ValueError("No MAG channel found. Cannot reject based on MAG.") + elif mag is not None: + print "mag reject : %s fT" % (1e15*mag) + if eeg is not None and len(eeg_idx) == 0: + raise ValueError("No EEG channel found. Cannot reject based on EEG.") + elif eeg is not None: + print "EEG reject : %s uV" % (1e6*eeg) + if eog is not None and len(eog_idx) == 0: + raise ValueError("No EOG channel found. Cannot reject based on EOG.") + elif eog is not None: + print "EOG reject : %s uV" % (1e6*eog) good_epochs = [] for k, e in enumerate(self): - if len(grad_idx) > 0 and np.max(e[grad_idx]) > grad: - print 'Rejecting epoch based on gradiometers.' - continue - if len(mag_idx) > 0 and np.max(e[mag_idx]) > mag: - print 'Rejecting epoch based on magnetometers.' - continue - if len(eeg_idx) > 0 and np.max(e[eeg_idx]) > eeg: - print 'Rejecting epoch based on EEG.' - continue - if len(eog_idx) > 0 and np.max(e[eog_idx]) > eog: - print 'Rejecting epoch based on EOG.' - continue - good_epochs.append(k) + for thresh, idx, name in zip([grad, mag, eeg, eog], + [grad_idx, mag_idx, eeg_idx, eog_idx], + ['GRAD', 'MAG', 'EEG', 'EOG']): + if len(idx) > 0: + e_idx = e[idx] + deltas = np.max(e_idx, axis=1) - np.min(e_idx, axis=1) + idx_max_delta = np.argmax(deltas) + delta = deltas[idx_max_delta] + if delta > thresh: + ch_name = self.ch_names[idx[idx_max_delta]] + print '\tRejecting epoch based on %s : %s (%s > %s).' \ + % (name, ch_name, delta, thresh) + break + else: + good_epochs.append(k) n_good_epochs = len(good_epochs) print "Keeping %d epochs (%d bad)" % (n_good_epochs, diff --git a/mne/fiff/pick.py b/mne/fiff/pick.py index b25c544..2a045fa 100644 --- a/mne/fiff/pick.py +++ b/mne/fiff/pick.py @@ -72,22 +72,26 @@ def pick_channels(ch_names, include, exclude=[]): return sel -def pick_types(info, meg=True, eeg=False, stim=False, include=[], exclude=[]): +def pick_types(info, meg=True, eeg=False, stim=False, eog=False, ecg=False, + emg=False, include=[], exclude=[]): """Pick channels by type and names Parameters ---------- info : dict The measurement info - meg : bool or string Is True include MEG channels or False include None If string it can be 'mag' or 'grad' to select only gradiometers or magnetometers. - eeg : bool Is True include EEG channels - + eog : bool + Is True include EOG channels + ecg : bool + Is True include ECG channels + emg : bool + Is True include EMG channels stim : bool Is True include stimulus channels @@ -120,6 +124,12 @@ def pick_types(info, meg=True, eeg=False, stim=False, include=[], exclude=[]): pick[k] = True elif kind == FIFF.FIFFV_STIM_CH and stim: pick[k] = True + elif kind == FIFF.FIFFV_EOG_CH and eog: + pick[k] = True + elif kind == FIFF.FIFFV_ECG_CH and ecg: + pick[k] = True + elif kind == FIFF.FIFFV_EMG_CH and emg: + pick[k] = True myinclude = [info['ch_names'][k] for k in range(nchan) if pick[k]] myinclude += include diff --git a/mne/fiff/tests/data/test-ave.fif b/mne/fiff/tests/data/test-ave.fif index 0ff74c8..67a3db6 100644 Binary files a/mne/fiff/tests/data/test-ave.fif and b/mne/fiff/tests/data/test-ave.fif differ diff --git a/mne/tests/test_epochs.py b/mne/tests/test_epochs.py index 85ebc01..ee0c851 100644 --- a/mne/tests/test_epochs.py +++ b/mne/tests/test_epochs.py @@ -18,19 +18,31 @@ def test_read_epochs(): tmin = -0.2 tmax = 0.5 - # Setup for reading the raw data + # Setup for reading the raw data raw = fiff.Raw(raw_fname) events = mne.read_events(event_name) + picks = fiff.pick_types(raw.info, meg=True, eeg=False, stim=False, + eog=True, include=['STI 014']) + epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks, + baseline=(None, 0)) + epochs.average() - # Set up pick list: MEG + STI 014 - bad channels (modify to your needs) - include = ['STI 014']; - want_meg = True - want_eeg = False - want_stim = False - picks = fiff.pick_types(raw.info, want_meg, want_eeg, want_stim, - include, raw.info['bads']) +def test_reject_epochs(): + event_id = 1 + tmin = -0.2 + tmax = 0.5 + + # Setup for reading the raw data + raw = fiff.Raw(raw_fname) + events = mne.read_events(event_name) + + picks = fiff.pick_types(raw.info, meg=True, eeg=True, stim=True, + eog=True, include=['STI 014']) epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks, baseline=(None, 0)) - epochs.reject(grad=4000e-13, mag=4e-12, eeg=40e-6, eog=150e-6) - epochs.average() + n_epochs = len(epochs) + epochs.reject(grad=1000e-12, mag=4e-12, eeg=80e-6, eog=150e-6) + n_clean_epochs = len(epochs) + assert n_epochs > n_clean_epochs + assert n_clean_epochs == 3 -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
