stores the start times and durations of my annotations.
Iām curious to know if thereās a command line tool for obtaining this information from the window in its current state without having to close the window itself. This would be similar to retrieving axis information in matplotlib using a command such as ax.get_xticks()
I assume by ācommand-line toolā you mean some Python code?
raw.plot() returns a figure object which will have all the information youāre looking for. Weāre actually making use of this in the MNE-BIDS Inspector:
So what you can do in your concrete example is:
fig = raw.plot()
# ... interact with the figure ā¦
# retrieve current selection of bad channels and Annotations
# while the figure window is still open
bads = fig.mne.info['bads']
annotations = fig.mne.inst.annotations
This wonāt work with block=True, as that will halt code execution until the window is closed.
I forgot to mention that the code example I posted relies on plotting functionality introduced with MNE 0.22. So once you update to this version, it should work
MNE .22 with Python 3.92 on a Mac with OS 10.15.4.
I wasnāt sure if I should start a new thread, but Iām also wondering if I can update raw itself based upon annotations I make when the plot window is open. I have a tkinter GUI in which the user plots, selects bad channels, and annotates. When they press a button, I want raw to be updated to reflect the removal of both bad channels and annotations. Your previous advice shows how to find the bad channels and remove them:
Did you create this tkinter GUI yourself, or do you mean you are using the tkinter backend of matplotlib? By default raw.plot() uses whatever matplotlib GUI backend is currently set, and when you plot a raw object with fig = raw.plot() and then do some bad channel marking, annotation, etc., then when you close the figure window all of your annotations and bad channels will automatically be updated on the raw object in-place. So after the plot is closed, the original raw object should give you access to everything you want (if Iāve understood correctly what you want).
If you want to access the updated bads, annotations, etc while the plot is still open then Richard is correct that fig.mne.info['bads'] or fig.mne.inst.annotations is where those things are stored. It should be perfectly safe to read those values, however, note that the structure of fig.mne.* is fairly new, undocumented, and not yet guaranteed to be stable. In particular, we havenāt rigorously tested what happens if users edit the values in fig.mne.* while the plot is still open, so itās possible that it might not behave the way you want it to.
If for your workflow you need fig.mne.* to be documented and stable and user-editable then please open a GitHub issue and tag @drammock on it and we can discuss further.
The GUI is one Iāve created myself. The idea is that the user can have both the GUI and the plot open in adjacent windows. Currently, when they mark bad channels in the plot and hit a button on my GUI, raw is updated to include only the good channels. The plot window stays open though. (This I accomplished with Richardās help a week or so ago.)
I am aware of the āautomatic updatingā of raw you refer to when the window is closed, but for workflow purposes Iād like to use a button in my GUI to do it with the window open. So perhaps I should open the GitHub issue as you suggest.