How to retrieve vertical guide location from open plot window

  • MNE 0.24.0
  • Mac 11.6.1

Just wondering if there is a way of retrieving the location of a vertical guide from an open plot window, as one could retrieve the current list of bad channels and current annotations via

fig=raw.plot()
fig.mne.info['bads']
annotations = fig.mne.inst.annotations

respectively. I typed fig.mne.info and fig.mne.inst but didn’t see attributes of either that give me what I need.

I think I can accomplish what I need using a button_press_event but wondered if there’s a way to retrieve the location in a manner similar to the above.

Update:

I see that on line 722 of _mpl_figure, the vertical line is drawn using

self._show_vline(event.xdata)

which is a method in the MNEBrowseFigure class.

Perhaps there is a way of retrieving xdata when the plot window is open?

Update 2: I’ve edited my copy of _mpl_figure, to add a new attribute to the MNEFigure class. At the end of __init__ I inserted the following:

setattr(self.mne,'segment_loc',0)

(This is immediately after line 96 in the code at mne-python/_mpl_figure.py at main · mne-tools/mne-python · GitHub). I simply used 0 as the attribute’s default value.

Then, inside the class method

def _buttonpress(self, event)

right after line 722 I inserted

self.mne.segment_loc=event.xdata

In my main function, I tried to retrieve the location of my vertical segment using fig.mne.segment_loc where fig=raw.plot()

Unfortunately, the returned value of fig.mne.segment_loc always comes back as the default value.

I feel like I’m very close to achieving my goal and I’m overlooking something regarding how the various classes are set up. Please let me know if I should post this on github instead.

It is probably buried in fig.mne.<something> but this isn’t really public / documented / stable yet (as alluded to in your issue Request for documentation of fig.mne.* · Issue #10344 · mne-tools/mne-python · GitHub). Potentially complicating things further is that the Qt backend (which uses mne-qt-browser under the hood) will interact to these differently.

Is it an option for you to make an annotation instead of using the green cursor line? That should tell you where you clicked in a way that is API stable

Using an annotation works, but having the ability to retrieve the location of the green cursor line with the plot window open would be preferable, if at all possible, for my intended use.

A little background on what I’m trying to accomplish:

The epileptologist for whom I’m writing my software would like to have the option of marking a spike in a recording and visualizing the coherence values between various channels “at” that instant in time.

In my GUI, once they marked a green segment, they could immediately go to a pull-down menu and select an option that would compute coherence values over a time window centered at the location of the green segment and having a very small fixed width. (The values would also be averaged over some frequency band of interest.) The result would be a heatplot depicting the various coherence strengths.

I’ve been able to successfully create a heatplot animation showing how coherence (or some other connectivity measure) varies over an entire recording, but my current goal would permit the doctor to focus more on what’s happening at an “instant” in time. In particular, having the segment locations would prevent them from having to use the annotations pop-up.

The software itself utilizes mne and tkinter and is packaged in Mac and Windows versions using pyinstaller.

I hope this background helps.