visbrain icon indicating copy to clipboard operation
visbrain copied to clipboard

interactive annotations on graph

Open noelbk opened this issue 1 year ago • 9 comments

Hi and thanks for visbrain! We're using it to mark events on our long sleep signals: 6 channels, 70 sps, about 8 hours durarion. We'd like to visually mark regions and validate them from different sources like human experts or algorithms.

I'd like to be able to mark and drag annotations on the signal graph. I'm looking at adding this feature myself, and just wanted to check if anyone else is interested in it, or has already implemented something. Any suggestions?

noelbk avatar Mar 29 '23 09:03 noelbk

Hi Noel, maybe check out our fork? https://github.com/TomBugnon/visbrain/

It implements a click-and-drag style scoring window. This is hypnogram, not annotations as you requested, but maybe close enough. Best

TomBugnon avatar Mar 29 '23 10:03 TomBugnon

Thanks @TomBugnon! I'll check it out right now.

noelbk avatar Mar 29 '23 10:03 noelbk

btw, I don't think it's specified, but I think you need to use python 3.9 and not 3.10

TomBugnon avatar Mar 29 '23 10:03 TomBugnon

Thanks @TomBugnon. I'm using Python 3.8 with your develop branch at 31b14b64. Have I got the configuration right? What do I click and drag on here? I tried clicking and dragging on all the graph panels. My data's a little weird, not in uV, fs=72... I'll dig into the code to see if I can find the click event .

Sleep(data=data, sf=72, channels=channels, hypno=None).show()

image

noelbk avatar Mar 29 '23 12:03 noelbk

It works for us on the develop branch at github/TomBugnon/visbrain...

If you debug you can check if you enter this block when clicking and dragging on the signal, and hit this function with the correct value for xlim_scor.

The red vertical bars should be redrawn when you click and drag

TomBugnon avatar Mar 29 '23 12:03 TomBugnon

Found the problem. Wrong version installed in my venv. :man_facepalming: click and drag works. Now I'll work on:

  • [] colour annotation backgrounds
  • [] make annotation regions edges editable (drag to adjust)

Thanks!

noelbk avatar Mar 29 '23 12:03 noelbk

bug: Start (seconds) and End (seconds) in Annotations tab show the same value (the end position?).

line 1341 in visuals.py: self._fcn_annotate_add('', (cursor, cursor), title)

@TomBugnon thank you for this drag-click version, very handy to use. how to fix this bug?

mitometa avatar Apr 05 '23 08:04 mitometa

solved the annotation problem for mouse release:

edit on_mouse_release(event) in visuals.py:

' nano +1435 /Path_to/visbrain/gui/sleep/visuals/visuals.py '

Quit mouse-scoring mode if no window was drawn/we clicked

Add annotation for the dragged window

'

        self._mouse_pressed = False
        mouse_xlim = self._mouse_scorwin_xlim
        min_xdrag = 0.05
        # without drag
        if (
            None in mouse_xlim
            or abs(mouse_xlim[1] - mouse_xlim[0]) <= min_xdrag  # noqa
        ):
            self._mousescoring_active = False
        # with drag
        if (
            self._mousescoring_active == True
        ):
            is_sp_hyp = canvas.title in ['Hypnogram', 'Spectrogram']
            title = canvas.title if is_sp_hyp else canvas.title.split('_')[1]
            self._fcn_annotate_add('', (mouse_xlim[0], mouse_xlim[1]), title)
        self._update_scorwin_indicator()
        self._video.set_video_time(self._xlim_scor[0])

'

mitometa avatar Apr 09 '23 04:04 mitometa

Hi @noelbk can you keep me posted regarding the features you're adding? Not sure I understand what they mean but they could be useful for us as well

TomBugnon avatar May 02 '23 10:05 TomBugnon