error with interactive annotations

hi everyone,

iā€™m trying to manually annotate parts of my data that are noisy. iā€™m importing my data and am going in interactive annotations as per the tutorial:

raw = mne.io.read_raw_fif(fifpath, allow_maxshield=True, preload=True, verbose=None)
raw_lowpass = raw.filter(h_freq=40, l_freq=None)
fig3 = raw_lowpass.plot(duration=30, n_channels=75, title='lowpass filter at 40hz', event_color='red', remove_dc=True, block=True, show=True)
fig3.fake_keypress('a')

i drag and drop to create a new annotation, but when i close the interactive figure i get an error:

AttributeError: ā€˜BrowserParamsā€™ object has no attribute ā€˜keyboard_shortcutsā€™

alternatively, if i try to edit an annotation while in the interactive window, i get another error:

AttributeError: ā€˜AnnotationDockā€™ object has no attribute ā€˜mainā€™

iā€™m using dataspell 2022.3 on a mac os 12.3.1 and my mne-base package is 1.2.3

thanks for your advice (:

1 Like

Hello,

From the code snippet, fig3.fake_keypress('a') is used in the tutorial to demonstrate the functionality.
In practice, you have to press on the A key of your keyboard to display the annotation menu. In an interactive python shell, after raw.plot(), the figure will open (using the old matplotlib backend if you donā€™t have mne-qt-browser installed, using the modern qt backend if you have it), and then you need to press on the A key of your keyboard and it will display the annotation menu.
Next step is to create an annotation by adding a description and finally mark the segments by click/drag on the traces.

Mathieu

Hi Mathieu,

Thanks for the reply. Yes, i should have taken this bit out. I do actually press the ā€˜aā€™ key once the figure comes up and go into annotation mode where i click and drag to create the annotations. However the first error doesnā€™t come until i click on the X to close the figure (from annotation mode) and the second error comes up when i try to click on ā€˜edit descriptionā€™ from the annotation menu. Itā€™s ok to ā€˜add descriptionā€™, but not to edit one.

bissera

From the text description, nothing that could explain this behavior comes to mind.
If possible, you could join the next Office Hours on January 6th (every 2 weeks usually) and share your screen on Discord.

Mathieu

Thanks, just joined discord. See you next year and enjoy the holidays (:

based on the error messages it sounds like the errors are coming from mne-qt-browser. I donā€™t know much about DataSpell, but if itā€™s capturing the plot into a panel of its UI that could be part of the issue. You could try using the matplotlib browser backend instead: add mne.viz.set_browser_backend('matplotlib') somewhere early in your script (before any calls to raw.plot()). Thereā€™s a chance that the matplotlib backend will integrate better with DataSpell.

Another option is running the script from a terminal instead of through your IDE; that can help us track down the source of the error too. So in a terminal, running something like ipython -i my_script.py (without making the browser_backend change suggested above) could also be informative.

1 Like

Hi Dan,

Happy new year!!

Thanks for your message. I tried to set the backend to matplotlib in which case the visualisation just didnā€™t show up. I wasnā€™t able to run my code via the terminal, because my packages are installed on conda virtual environment and my computer didnā€™t know how to find them and i didnā€™t know how to explain it via the terminal. However, i really donā€™t know whatā€™s changed, since i didnā€™t do any work over the holidays, but the qt gui is now not crashing when i add a new annotation. Sorry i couldnā€™t help you find the source of the problem, but iā€™m happy the problem is gone.

Best,
bissera

1 Like