-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: mismatch between timestamps and frames in miniscope video #376
Comments
@weiglszonja. @alessandratrapani (tagging both of you as we have worked on this) I discussed this with @laurelrr it seems that one of the sessions for the Tye lab has a session where the timestamps do not match the number of frames. So there is an error here: roiextractors/src/roiextractors/imagingextractor.py Lines 189 to 198 in 2cf9235
The timestamps are obtained from a csv that is specific to miniscope and aggregated here: And the frames are the sum of the frames of each individual extractor here: roiextractors/src/roiextractors/multiimagingextractor.py Lines 40 to 47 in 2cf9235
Which in turn are obtained from the video directly using OpenCV. roiextractors/src/roiextractors/extractors/miniscopeimagingextractor/miniscopeimagingextractor.py Lines 105 to 107 in 2cf9235
So I think that either the timestamps in the csv are wrong or there are some drop frames in some videos. @laurelrr will see how he can share the data with us so we can verify that. Meanwhile, what should we do in the case there are dropped frames? I think dropping frames is somehow common in acquisition systems that involve video so I think we should handle that case gracefully but I am not sure how. |
The miniscope TimeStamps.csv has a dedicated column "Buffer_Index" to signal problems with frame acquisition, e.g., dropped frames. We can start by looking at this piece of data. |
OK, this happens because there are some files that match the *.avi wildcard but not in the intended way in one of the segments: ├── 13_59_04
│ ├── BehavCam_2
│ │ ├── 0.avi
│ │ ├── 1.avi
│ │ ├── 2.avi
│ │ ├── 3.avi
│ │ ├── 4.avi
│ │ ├── 5.avi
│ │ ├── 6.avi
│ │ ├── 7.avi
│ │ ├── 8.avi
│ │ ├── metaData.json
│ │ └── timeStamps.csv
│ ├── metaData.json
│ ├── Miniscope
│ │ ├── 0.avi
│ │ ├── 0_corrected.avi
│ │ ├── 1.avi
│ │ ├── 2.avi
│ │ ├── 3.avi
│ │ ├── 4.avi
│ │ ├── metaData.json
│ │ └── timeStamps.csv
│ └── notes.csv
└── G2B4_C5-6852_L_yeti_DISC6UNP+TONES_msCamAll_ffd.mat
See the 0_corrected.avi Can/should we improve the extractor to not match things with letters? |
OK, my fix for this was to make a copy of the data folder and |
OK, my idea did not seem to fix the issue. I will confer with my lab mates and see what else might have been affected. |
After conferring with the team, it looks like we need only the 0.avi behavCam and the 0_corrected.avi miniscope file (which I have renamed to 0.avi). I set this up in my copy of the original folder. it now looks like this:
I am trying to run pulling from the updated miniscope folder, but still see the same error message:
Is there something else that should be updated, beyond just deleting extraneous files? |
I also tried cropping the timeStamps.csv file to the correct length and tried running again but this also gives the same error:
|
Is your code making use of the metaData.json information when loading in the files? |
Yes, we are extracting the information from "recordingStartTime". But I don't see how that would affect the mismatch in frames. Can you share this session in its current form? |
OK, I think I have figured out the issue. For some unknown reason, the Miniscope reset its frame rate from 15 fps to 60 fps partway through the recording. To correct this aberrant recording, my colleague used ffmpeg to change frame rate of the video but had not updated the timestamps file. I corrected the timestamps to match the video (and frame rate) and this now processes as expected. If you wanted to make a more interpretable error message, listing the folder where the first instance of mismatch between the timestamps file and video frame rates would be helpful for your users. As always, thanks for the help! |
Very interesting, I'm glad to hear it works now! Thank you for the feedback! |
I'm getting a different error with our second dataset that seems related to the timestamps issue (subject had same framerate of 15 fps switching to 60 fps and was corrected post-processing). The miniscope dataset associated with this subject is about 6GB. Is there a way for me to share with you? |
What happened?
I am working with this repo: https://github.com/catalystneuro/tye-lab-to-nwb/tree/main/src/tye_lab_to_nwb/ast_ophys
and attempting to convert Miniscope calcium recordings but got the same error on 2 subjects.
Steps to Reproduce
Traceback
Operating System
Linux
Python Executable
Conda
Python Version
3.11
Package Versions
environment_for_issue.txt
Code of Conduct
Yes
Duplicated Issue Check
Yes
The text was updated successfully, but these errors were encountered: