question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

problem dropping epochs by visual inspection

See original GitHub issue

Found a problem regarding dropping epochs. You can try it with the data of the read epochs example. Plotting epochs and selecting bad epochs by hand results in a reduction of the total number of epochs. This does not work plotting only the epochs corresponding to a certain event_id.

Doing it for the whole set:

epochs
Out[2]: <Epochs  |  n_events : 55 (all good), tmin : -0.199795213158 (s), tmax : 0.499488032896 (s), baseline : (None, 0), ~17.5 MB, data loaded>

epochs.plot()
Out[3]: <matplotlib.figure.Figure at 0xc8afda0>Dropped 5 epochs
Channels marked as bad: []


epochs
Out[4]: <Epochs  |  n_events : 50 (all good), tmin : -0.199795213158 (s), tmax : 0.499488032896 (s), baseline : (None, 0), ~16.3 MB, data loaded>

5 epochs are marked as bad -> the total number of epochs is reduced by five

Plotting only epochs corresponding to an event_id:

epochs['1']
Out[2]: <Epochs  |  n_events : 55 (all good), tmin : -0.199795213158 (s), tmax : 0.499488032896 (s), baseline : (None, 0), ~17.5 MB, data loaded>

epochs['1'].plot()
Out[3]: <matplotlib.figure.Figure at 0xa250978>Dropped 5 epochs
Channels marked as bad: []


epochs['1']
Out[4]: <Epochs  |  n_events : 55 (all good), tmin : -0.199795213158 (s), tmax : 0.499488032896 (s), baseline : (None, 0), ~17.5 MB, data loaded>

5 epochs are marked as bad -> the total number of epochs stays the same

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
larsonercommented, Nov 9, 2017

Argh yes selection gets restricted. Fortunately we can use event numbers, though. See if this makes sense:

import numpy as np
import mne
raw = mne.io.read_raw_fif(mne.datasets.sample.data_path() +
                          '/MEG/sample/sample_audvis_raw.fif')
events = mne.find_events(raw, 'STI 014')
epochs = mne.Epochs(raw, events, event_id=dict(foo=1, bar=2), preload=True)
epochs.drop([1])
epochs_foo = epochs['foo']
# we can get indices back to the original using np.searchsorted
# based on the epoch sample numbers (because they're in order):
orig_idx = np.searchsorted(epochs.events[:, 0], epochs_foo.events[:, 0])
assert (epochs.events[orig_idx, 2] == 1).all()  # sanity check
# let's drop some in our copy
epochs_foo.drop([0, 1, 2])
# figure out which ones are still there
orig_idx_good = np.searchsorted(epochs.events[:, 0], epochs_foo.events[:, 0])
assert len(orig_idx_good) == len(orig_idx) - 3  # we removed 3
# figure out which ones we removed (in the original)
orig_idx_bad = np.setdiff1d(orig_idx, orig_idx_good)
assert len(orig_idx_bad) == 3
epochs.drop(orig_idx_bad)
# Did we drop the correct ones?
assert np.array_equal(epochs['foo'].events, epochs_foo.events)
0reactions
larsonercommented, Apr 4, 2018

Closing since the main problem can by solved by a NumPy-based workflow. @stfnrpplngr if you are still interested in the other features you mention in your last post, feel free to open new issues for discussion

Read more comments on GitHub >

github_iconTop Results From Across the Web

mne.Epochs — MNE 1.2.2 documentation - MNE-Python
Reject epochs based on maximum peak-to-peak signal amplitude (PTP), i.e. the absolute difference between the lowest and the highest signal value ...
Read more >
Epochs - Mainak Jas
You can also inspect the reason why epochs were dropped. The indices from the original set of events are stored in epochs. selection...
Read more >
Use Early Stopping to Halt the Training of Neural Networks At ...
Too many epochs can lead to overfitting of the training dataset, whereas too few may result in an underfit model. Early stopping is...
Read more >
The Epochs data structure - | notebook.community
Selecting epochs by index · Selecting, dropping, and reordering channels · Changing channel name and type · Selection in the time domain ·...
Read more >
Check for ICA (toward Epochs Rejection) - MNE Forum
Also you should drop this line – you only have EEG data, so specifying rejection thresholds on MEG channels doesn't make much sense....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found