Skip to content
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

Clarification on Timestamp Generation in Miniscope-DAQ-QT-Software #72

Open
Lucas10pm opened this issue May 7, 2024 · 2 comments
Open

Comments

@Lucas10pm
Copy link

Hello,

I am using the Aharoni-Lab Miniscope-DAQ-QT-Software for live calcium imaging recordings and have a question regarding the timestamp mechanism used by the software. Specifically, I am trying to understand the starting reference point for the timestamps that are generated when recording videos.

The initial timestamp in some of our recordings, such as 935,703,178 milliseconds, does not seem to align with standard UNIX epoch time. I need to synchronize these timestamps with another system that logs events using a standard time notation (hh:mm:ss on specific dates).

Could anyone provide details or direct me to documentation that explains the origin or reference point from which the timestamps start counting?

Thank you!

@sneakers-the-rat
Copy link
Contributor

Hello! Not the author of the software but let me see if I can help:

First question: which timestamps are you looking at? They are saved in a few places. Can you zip and attach an example json metadata/timestamp CSV file/whatever youre looking at?

When starting a recording, a QDateTime object is created with the current (system) time:

recordStartDateTime = QDateTime::currentDateTime();

That gets stored in the recording metadata here:

startTimeObject["year"] = recordStartDateTime.date().year();
startTimeObject["month"] = recordStartDateTime.date().month();
startTimeObject["day"] = recordStartDateTime.date().day();
startTimeObject["hour"] = recordStartDateTime.time().hour();
startTimeObject["minute"] = recordStartDateTime.time().minute();
startTimeObject["second"] = recordStartDateTime.time().second();
startTimeObject["msec"] = recordStartDateTime.time().msec();
startTimeObject["msecSinceEpoch"] = recordStartDateTime.toMSecsSinceEpoch();
metaData["recordingStartTime"] = startTimeObject;

I believe the timestamps come from here:

*csvStream[names[i]] << savedFrameCount[names[i]] << ","
<< (timeStampBuffer[names[i]][bufPosition] - recordStartDateTime.toMSecsSinceEpoch()) << ","
<< usedCount[names[i]]->available() << endl;

So the timestamps are taken from some timestamp buffer and then the time thats stored is the ms since the start time.

I believe the timestamp buffer times come from here:

timeStampBuffer[idx%frameBufferSize] = QDateTime().currentMSecsSinceEpoch();

So thats again just the current system time in ms since Unix epoch.

935,703,178ms is roughly 11 days - could it be the system time is off? Eg. A system without set time has been on for 10 days.

@daharoni
Copy link
Member

daharoni commented May 8, 2024

Hey! So as @sneakers-the-rat said, the start time of the recording is saved in the metadata Json file. The actual timestamps in the timestamp file for each data source is saved as the number of milliseconds since the start of the recording. The first timestamp can be a little funky as there is a chance that that particular frame was acquired and sitting in the frame buffer of the software right before the start of recording. This causes the calculation of the millisecond value to be negative but our software improperly converts it to an unsigned int, resulting in a nonsensical large positive number.

This is a bug that we haven't gotten around to fix. Current options are:

  1. Just set the first timestamp to 0
  2. Just throwaway the first frame
  3. Recover the negative millisecond value by converting the unsigned int timestamp back to a signed one

I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants