Repository: mne-tools/mne-python

Issue:
FIX: epochs decim is broken
after decim reading data seems impossible



Discussion:
gist to reproduce?

https://gist.github.com/dengemann/54b021b232760a73c5cb

I can take a look later today


Resolving patch:
diff --git a/mne/epochs.py b/mne/epochs.py
--- a/mne/epochs.py
+++ b/mne/epochs.py
@@ -1109,14 +1109,14 @@ def _get_data(self, out=True, verbose=None):
             for idx in range(n_events):
                 # faster to pre-allocate memory here
                 epoch_raw = self._get_epoch_from_raw(idx)
-                if idx == 0:
-                    data = np.empty((n_events, epoch_raw.shape[0],
-                                     epoch_raw.shape[1]),
-                                    dtype=epoch_raw.dtype)
                 if self._delayed_proj:
                     epoch_out = epoch_raw
                 else:
                     epoch_out = self._process_epoch_raw(epoch_raw)
+                if idx == 0:
+                    data = np.empty((n_events, epoch_out.shape[0],
+                                     epoch_out.shape[1]),
+                                    dtype=epoch_raw.dtype)
                 data[idx] = epoch_out
         else:
             # bads need to be dropped, this might occur after a preload


Test patch:
diff --git a/mne/tests/test_epochs.py b/mne/tests/test_epochs.py
--- a/mne/tests/test_epochs.py
+++ b/mne/tests/test_epochs.py
@@ -180,6 +180,7 @@ def test_decim():
         epochs = Epochs(raw, events, event_id, tmin, tmax, decim=decim,
                         preload=preload)
         assert_array_equal(epochs.get_data(), expected_data)
+        assert_array_equal(epochs.get_data(), expected_data)
         assert_equal(epochs.info['sfreq'], sfreq_new)
         assert_array_equal(epochs.times, expected_times)
 
@@ -187,11 +188,13 @@ def test_decim():
         epochs = Epochs(raw, events, event_id, tmin, tmax, decim=dec_1,
                         preload=preload).decimate(dec_2)
         assert_array_equal(epochs.get_data(), expected_data)
+        assert_array_equal(epochs.get_data(), expected_data)
         assert_equal(epochs.info['sfreq'], sfreq_new)
         assert_array_equal(epochs.times, expected_times)
         epochs = Epochs(raw, events, event_id, tmin, tmax, decim=dec_2,
                         preload=preload).decimate(dec_1)
         assert_array_equal(epochs.get_data(), expected_data)
+        assert_array_equal(epochs.get_data(), expected_data)
         assert_equal(epochs.info['sfreq'], sfreq_new)
         assert_array_equal(epochs.times, expected_times)
 
@@ -201,6 +204,7 @@ def test_decim():
         epochs.preload_data()
         epochs = epochs.decimate(dec_2)
         assert_array_equal(epochs.get_data(), expected_data)
+        assert_array_equal(epochs.get_data(), expected_data)
         assert_equal(epochs.info['sfreq'], sfreq_new)
         assert_array_equal(epochs.times, expected_times)
         epochs = Epochs(raw, events, event_id, tmin, tmax, decim=dec_2,
@@ -208,6 +212,7 @@ def test_decim():
         epochs.preload_data()
         epochs = epochs.decimate(dec_1)
         assert_array_equal(epochs.get_data(), expected_data)
+        assert_array_equal(epochs.get_data(), expected_data)
         assert_equal(epochs.info['sfreq'], sfreq_new)
         assert_array_equal(epochs.times, expected_times)
 
@@ -215,6 +220,7 @@ def test_decim():
         epochs = Epochs(raw, events, event_id, tmin, tmax,
                         preload=preload).decimate(decim)
         assert_array_equal(epochs.get_data(), expected_data)
+        assert_array_equal(epochs.get_data(), expected_data)
         assert_equal(epochs.info['sfreq'], sfreq_new)
         assert_array_equal(epochs.times, expected_times)
 
@@ -224,6 +230,7 @@ def test_decim():
         epochs.preload_data()
         epochs.decimate(decim)
         assert_array_equal(epochs.get_data(), expected_data)
+        assert_array_equal(epochs.get_data(), expected_data)
         assert_equal(epochs.info['sfreq'], sfreq_new)
         assert_array_equal(epochs.times, expected_times)