Aharoni-Lab / miniscope-io

Data formatting, reading, and writing from miniscopes
https://miniscope-io.readthedocs.io
GNU Affero General Public License v3.0
6 stars 2 forks source link

Metadata handling, export, and real-time visualization #35

Closed t-sasatani closed 2 days ago

t-sasatani commented 1 month ago

Some updates for interfacing metadata and accompanying updates for the CLI.

Changes:

Notes:

coveralls commented 1 month ago

Coverage Status

coverage: 73.757% (+1.7%) from 72.069% when pulling 479363c47248d87dcb1c276edaecf2c7c81bcef9 on feat-metadata-handle into 22908743959a3a8b0d69a725928d07eb915db249 on main.

sneakers-the-rat commented 1 month ago

Ope sorry missed this when u opened it. I got some notes but like what yr thinkin here :)

t-sasatani commented 1 month ago

No problem. This isn't a hurry at all!

t-sasatani commented 1 week ago

Ok, the video hash seems to change if the queue size changes (I confirmed locally by changing the env variables). This might just mean that we're getting better videos, or it could mean some mystery is happening to video hashes.

t-sasatani commented 1 week ago

Actually, we get more video/metadata when the queues are smaller, so I assume this happens because of the termination order of the processes or something. Will look into this later.

t-sasatani commented 1 week ago

I added a metadata plotting feature because I need them for experiments next week. We might want a neater GUI soon, but this should work as a temporary solution. I included it in this PR because it is closely related, but I'm also happy to push this to a later one.

This feature runs by the following steps:

  1. Configure these runtime configs if necessary (specify metadata keys to be plotted).
    MINISCOPE_IO_STREAM_HEADER_PLOT_HISTORY=500
    MINISCOPE_IO_STREAM_HEADER_PLOT_UPDATE_MS=100
    MINISCOPE_IO_STREAM_HEADER_PLOT_KEY="timestamp,buffer_count,linked_list,frame_buffer_count"
  2. Use the -m option in mio.

This shows a real-time plot of metadata. metadataplot

sneakers-the-rat commented 1 week ago

ok @t-sasatani see my updates in the above commits, tried to split them up so they are a little easier to follow, but they are sorta intrinsically related to each other.

Basically i am trying to have as light of a touch as possible here bc i know y'all are under a deadline while trying to avoid this package getting too spaghettilike from that rush against deadline.

There are some test errors that are only showing up in CI on ubuntu that i'm gonna fix, but other than that i'll take one final look and approve

sneakers-the-rat commented 1 week ago

ok here's a fun one for you - for the csv writer test, where since i didn't know exactly what we would want there, i just did a simple shape test, where the header metadata that gets written should be the same every time (for a given test data file), but we are getting...

I'm not really sure what that value should be since idk the source data, but the video is 20fps, 5.5s long = 110 frames, and there should be 8 buffers per frame = 880 total, which is actually none of those values.

so... ya...

sneakers-the-rat commented 1 week ago

OK fixed those bugs, and fixed the early termination bugs - removed ability to exit with escape while displaying videos, now there are two ways to quit a capture:

but instead of prior behavior where all the loops quit immediately when getting the terminate event, refactored the top-level capture frame processing logic into a separate method so it was possible to call in two places, so now we explicitly wait for the queues to drain before fully quitting (it's also possible to force quit with a second ctrl+c).

very very strong need to break apart those inner methods so that we have better access to them for unit testing, bc we are gonna keep getting mystery errors as long as we only have end-to-end tests and can't directly test them as pure functions, given some expected input, get some expected output, separated from the rest of the acquisition process.

sneakers-the-rat commented 1 week ago

Added tests that confirm that varying buffer size doesn't change output to guard against the problems @t-sasatani was describing here: https://github.com/Aharoni-Lab/miniscope-io/pull/35#issuecomment-2293335064 which was because of the termination logic

sneakers-the-rat commented 2 days ago

Down with merging this btw :)

t-sasatani commented 2 days ago

Thanks sounds great. I'm thinking about making some changes to save more messed-up metadata, but I will bump up a minor version after I decide what to do with that.

sneakers-the-rat commented 2 days ago

Merge this then do that?

t-sasatani commented 2 days ago

The refactored version is running very slow compared to https://github.com/Aharoni-Lab/miniscope-io/pull/35/commits/5d33e3b13e30988169e04a9e951c59b65041b147, and I'm looking why. I assume it's blocking/non-blocking stuff in plots, and here is an example binary to see this. https://drive.google.com/open?id=1QoLB1F7HUau6TDrHQWxpivR48RhpTfWN&usp=drive_fs

t-sasatani commented 2 days ago

This was just the window refresh (cv2.waitKey(1)) getting deleted with the ESC key escape. Also, the plot window becomes unstable when moved (changing the GUI backends of matplotlib didn't fix it), but I guess I'll merge it with an experimental notice.

It might be worth considering GUI tests, but I'm unsure if there's a good way to do non-web GUI tests on GitHub actions.