[med-svn] [python-mne] 41/52: First commit of my branch with my fixes.

Yaroslav Halchenko debian at onerussian.com
Fri Nov 27 17:23:49 UTC 2015


This is an automated email from the git hooks/post-receive script.

yoh pushed a commit to annotated tag v0.2
in repository python-mne.

commit 5252c42a0717895bdadd446cdcf5763713932bb9
Author: Manfred Kitzbichler <manfredg at nmr.mgh.harvard.edu>
Date:   Fri Nov 4 17:44:27 2011 -0400

    First commit of my branch with my fixes.
---
 mne/artifacts/ecg.py   | 18 ++++++++++++------
 mne/epochs.py          | 25 ++++++++++++++-----------
 mne/source_estimate.py |  1 +
 3 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/mne/artifacts/ecg.py b/mne/artifacts/ecg.py
index ede3990..b9756d0 100644
--- a/mne/artifacts/ecg.py
+++ b/mne/artifacts/ecg.py
@@ -29,7 +29,7 @@ def qrs_detector(sfreq, ecg, thresh_value=0.6, levels=2.5, n_thresh=3):
     """
     win_size = round((60.0 * sfreq) / 120.0)
 
-    filtecg = band_pass_filter(ecg, sfreq, 5, 35)
+    filtecg = band_pass_filter(ecg, sfreq, 10, 35)
     n_points = len(filtecg)
 
     absecg = np.abs(filtecg)
@@ -53,7 +53,7 @@ def qrs_detector(sfreq, ecg, thresh_value=0.6, levels=2.5, n_thresh=3):
         if window[0] > thresh1:
             maxTime = np.argmax(window)
             time.append(i + maxTime)
-            numcross.append(np.sum(np.diff(window > thresh1) == 1))
+            numcross.append(np.sum(np.diff(1*(window > thresh1)) == 1))
             rms.append(np.sqrt(np.mean(window ** 2)))
             i += win_size
         else:
@@ -92,8 +92,14 @@ def find_ecg_events(raw, event_id=999):
                                  eog=False, ecg=True, emg=False)
 
     if len(ch_ECG) == 0:
-        # closest to the heart normally, In future we can search for it.
-        ch_ECG = fiff.pick_channels(raw.ch_names, include='MEG 1531')
+        ch_ECG = fiff.pick_types(info, meg=False, eeg=True, stim=False,
+                                 eog=False, ecg=False, emg=False)
+        if len(ch_ECG) != 0:
+            ch_ECG = ch_ECG[2:3]
+        else:
+            # closest to the heart normally, In future we can search for it.
+            ch_ECG = fiff.pick_channels(raw.ch_names, include='MEG 1511')
+
         print 'Using channel index %d to identify heart beats' % ch_ECG
     else:
         print 'ECG channel index for this subject is: %s' % ch_ECG
@@ -104,10 +110,10 @@ def find_ecg_events(raw, event_id=999):
     # detecting QRS and generating event file
     ecg_events = qrs_detector(info['sfreq'], ecg.ravel())
     n_events = len(ecg_events)
-    average_pulse = 60.0 * (times[-1] - times[0]) / n_events
+    average_pulse = n_events * 60.0 / (times[-1] - times[0])
     print ("Number of ECG events detected : %d (average pulse %d / min.)"
                                            % (n_events, average_pulse))
 
     ecg_events = np.c_[ecg_events + raw.first_samp, np.zeros(n_events),
                        event_id * np.ones(n_events)]
-    return ecg_events
+    return ecg_events, ch_ECG, average_pulse
diff --git a/mne/epochs.py b/mne/epochs.py
index b726985..30ca4a3 100644
--- a/mne/epochs.py
+++ b/mne/epochs.py
@@ -259,6 +259,8 @@ class Epochs(object):
         first_samp = self.raw.first_samp
         start = int(round(event_samp + self.tmin * sfreq)) - first_samp
         stop = start + len(self.times)
+        if start < 0:
+            return np.zeros((len(self.picks),len(self.times)))
         epoch, _ = self.raw[self.picks, start:stop]
 
         if self.proj is not None:
@@ -384,7 +386,7 @@ class Epochs(object):
 
         return epochs
 
-    def average(self):
+    def average(self, dropCh=True):
         """Compute average of epochs
 
         Returns
@@ -413,17 +415,18 @@ class Epochs(object):
         evoked.last = int(np.sum(self.times > 0))
 
         # dropping EOG, ECG and STIM channels. Keeping only data
-        data_picks = pick_types(evoked.info, meg=True, eeg=True,
-                                stim=False, eog=False, ecg=False,
-                                emg=False)
-        if len(data_picks) == 0:
-            raise ValueError('No data channel found when averaging.')
-
-        evoked.info['chs'] = [evoked.info['chs'][k] for k in data_picks]
-        evoked.info['ch_names'] = [evoked.info['ch_names'][k]
+        if(dropCh):
+            data_picks = pick_types(evoked.info, meg=True, eeg=True,
+                                          stim=False, eog=False, ecg=False,
+                                          emg=False)
+            if len(data_picks) == 0:
+                raise ValueError('No data channel found when averaging.')
+
+            evoked.info['chs'] = [evoked.info['chs'][k] for k in data_picks]
+            evoked.info['ch_names'] = [evoked.info['ch_names'][k]
                                     for k in data_picks]
-        evoked.info['nchan'] = len(data_picks)
-        evoked.data = evoked.data[data_picks]
+            evoked.info['nchan'] = len(data_picks)
+            evoked.data = evoked.data[data_picks]
         return evoked
 
 
diff --git a/mne/source_estimate.py b/mne/source_estimate.py
index f5076b6..5edd92d 100644
--- a/mne/source_estimate.py
+++ b/mne/source_estimate.py
@@ -446,6 +446,7 @@ def morph_data(subject_from, subject_to, stc_from, grade=5, smooth=None,
         n_vertices = e.shape[0]
         e = e + sparse.eye(n_vertices, n_vertices)
         idx_use = stc_from.vertno[hemi]
+        if len(idx_use)==0: continue
         n_iter = 100  # max nb of smoothing iterations
         for k in range(n_iter):
             e_use = e[:, idx_use]

-- 
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