Thanks a lot for the fast response!
The block=True argument seems to work fine (don’t know why it crashed/halted my script last time i tried).
In any case, yes, I agree that it would be great to have the opportunity to revise the selection of bad epochs just like channels. If nothing else, in order to maintain the integrity of the data for as long as possible.
Will report back if I run into issues.
Bjørn
EDIT quick follow-up:
it is a bit unstable, unfortunately. Sometimes, the kernel just freezes. There seems to be open issues relating to the same functionailty, and it seems it is matplotlib-related (probably not pure MNE). See here for example: raw.plot(block=True) freezes the jupyter kernel forever · Issue #6528 · mne-tools/mne-python · GitHub
Anyways, for me, the kernel freezes some times, and leaves the output like this:
test.plot(n_epochs=10, n_channels=21, block=True)
Opening epochs-browser...
Closing epochs-browser...
Dropped 1 epoch: 5
The following epochs were marked as bad and are dropped:
[5]
Channels marked as bad:
['O2']
In other words, the mne-part seems to work to select bad epochs and channels, but closing the figure leads to kernel freezing.
it is still unclear whether the solution proposed by mvonflotow solves the issue. But initial tests seem promising.
EDIT 2:
it seems the solution only transiently solves the problem. On the first 2-3 calls to epochs.plot(block=True), the behavior is as expected, but on subsequent calls the kernel still freezes. I cannot even ctrl+c to stop the process, and I’m forced to restart the kernel.
Any insights would be much appreciated!
EDIT 3:
After testing some more, I have made the following observations (see below for minimal code used):
- The first time I run through the code below, it behaves as expected
- If i try to run the little loop with epochs.plot() call, the kernel freezes after the first iteration
- However, I also notice that when I kill the kernel to try again, the mne “epochs browser” briefly shows up, so it seems like the next iteration’s call to “epochs.plot()” is somehow cached and just doesnt show up.
- If I run epoch.plot() (without the block=True kwarg) the kernel does not freeze after closing the browser.
In other words, it seems like I can safely use the looping strategy as long as I only run one loop, and do not call the epochs.plot(block=True) again later in the script
from oscillation_functions import *
import pickle as pkl
save_folder = r'\\hypatia.uio.no\lh-med-imb-jstormlab\Data\Wada_Data_Swiss\etomidate_both_sides\derivatives\pipeline_2'
file_names = [save_folder+'\\'+f for f in ['sub-01_left_ica-cleaned.pkl','sub-01_right_ica-cleaned.pkl']]
# load sample data
epochs = []
for file in file_names:
with open(file, 'rb') as f:
epochs.append(pkl.load(f)['data'])
# inspect data
inspected = []
for epoch in epochs:
aux = epoch.copy()
aux.plot(n_epochs=10, n_channels=21, block=True)
inspected.append(aux)