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 8f985c10224a13fa767772b23beb6c6094a2d9a0 Author: Daniel Strohmeier <[email protected]> Date: Thu Jul 12 18:48:51 2012 +0200 ENH : new stim artifact rejection function --- mne/artifacts/stim.py | 56 ++++++++++++++++++++++++++++++++++++++++ mne/artifacts/tests/test_stim.py | 21 +++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/mne/artifacts/stim.py b/mne/artifacts/stim.py new file mode 100644 index 0000000..01af320 --- /dev/null +++ b/mne/artifacts/stim.py @@ -0,0 +1,56 @@ +import numpy as np +from scipy import signal, interpolate + + +def eliminate_stim_artifact(raw, events, event_id, tmin=-0.005, + tmax=0.01, mode='linear'): + """Eliminates stimulations artifacts from raw data + + The raw object will be modified in place (no copy) + + Parameters + ---------- + raw: Raw object + raw data object + events: array, shape (n_events, 3) + The list of events + event_id: int + The id of the events generating the stimulation artifacts. + tmin : float + Start time before event in seconds + tmax : float + End time after event in seconds + mode : 'linear' | 'window' + way to fill the artifacted time interval + 'linear' does linear interpolation + 'window' applies a (1 - hanning) window + + Returns + ------- + raw: Raw object + raw data object + """ + events_sel = (events[:, 2] == event_id) + event_start = events[events_sel, 0] + s_start = np.ceil(raw.info['sfreq'] * np.abs(tmin))[0] + s_end = np.ceil(raw.info['sfreq'] * tmax)[0] + if mode == 'linear': + for k in range(len(event_start)): + x = np.array([event_start[k] - raw.first_samp - s_start, \ + event_start[k] - raw.first_samp + s_end]) + data = raw._data[:, [event_start[k] - raw.first_samp - s_start, \ + event_start[k] - raw.first_samp + s_end]] + f = interpolate.interp1d(x, data) + xnew = np.arange(event_start[k] - raw.first_samp - s_start, \ + event_start[k] - raw.first_samp + s_end) + interp_data = f(xnew) + raw._data[:, event_start[k] - raw.first_samp - s_start:\ + event_start[k] - raw.first_samp + s_end] = interp_data + if mode == 'window': + window = 1 - np.r_[signal.hann(4)[:2], np.ones(s_end + s_start - 4), \ + signal.hann(4)[-2:]].T + for k in range(len(event_start)): + raw._data[:, event_start[k] - raw.first_samp - s_start:\ + event_start[k] - raw.first_samp + s_end] *= \ + window[np.newaxis, :] + return raw diff --git a/mne/artifacts/tests/test_stim.py b/mne/artifacts/tests/test_stim.py new file mode 100644 index 0000000..8cbdc85 --- /dev/null +++ b/mne/artifacts/tests/test_stim.py @@ -0,0 +1,21 @@ +import os.path as op + +from nose.tools import assert_true +from numpy.testing import assert_array_almost_equal + +from ...fiff import Raw +from ...event import read_events +from ..stim import eliminate_stim_artifact + +data_path = op.join(op.dirname(__file__), '..', '..', 'fiff', 'tests', 'data') +raw_fname = op.join(data_path, 'test_raw.fif') +event_fname = op.join(data_path, 'test-eve.fif') + + +def test_find_ecg(): + """Test eliminate stim artifact""" + raw = Raw(raw_fname, preload=True) + events = read_events(event_fname) + n_events = len(events) + raw = eliminate_stim_artifact(raw, events, event_id=1, tmin=-0.005, + tmax=0.01, mode='linear') -- 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
