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

Add support for Blackrock NSx files with per-sample PTP nanosecond timestamps #1338

Merged
merged 6 commits into from
May 7, 2024
Merged

Add support for Blackrock NSx files with per-sample PTP nanosecond timestamps #1338

merged 6 commits into from
May 7, 2024

Conversation

cboulay
Copy link
Contributor

@cboulay cboulay commented Oct 20, 2023

Fixes #1332

Blackrock's newest signal acquisition devices use nanosecond timestamps from clocks synchronized with PTP. This allows synchronization between devices that might have slightly different clock rates and not capture exactly 30_000 samples per reference second.

Individual per-sample timestamps are stored in a data header, per sample.

Previously, the presence of a header in the data block would indicate the start of a new segment, and methods would look for the header to start a new memmap. That previous solution, when applied to millions of headers in the PTP-enabled files, led to OS-level problems by creating too many memmaps.

This PR allows the new PTP-enabled NSx files to be loaded.

Note: the time range of data files no longer start at 0! They start at whatever the monotonic clock was when the NSx file was recorded. We can't simply re-zero the timestamps per file because there might be multiple sets of files that were recorded simultaneously (i.e., from different pieces of hardware) but didn't start at the exact same time. We could re-zero with the common minimum across all devices, but the BlackrockRawIO loader doesn't support multi-device ns6 files. For now, it's best to leave it to the user to load the K files manually then find their own common t-zero among those K files.

@pep8speaks
Copy link

pep8speaks commented Oct 20, 2023

Hello @cboulay! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 1015:100: E501 line too long (106 > 99 characters)

Line 209:100: E501 line too long (111 > 99 characters)

Comment last updated at 2023-10-28 18:00:59 UTC

@cboulay
Copy link
Contributor Author

cboulay commented Oct 23, 2023

OK this is ready for review. If you want a sample data file then that will have to wait until Friday when I'm in front of the hardware needed to produce the 3.0-ptp variant file spec.

@samuelgarcia
Copy link
Contributor

Hi Chadwick.
An enormous thanks for figthing with this new version of blackrock.
I will have a look soon. Lets wait friday to get the the test file that corresponf to this.
Can you try to make a very very short one ?

@cboulay
Copy link
Contributor Author

cboulay commented Oct 28, 2023

I found and fixed a bug in my previous implementation thanks to unit tests I just added.

Here's a zip of the test files. If you can provide me instructions on how to created a pull request on GIN then I can go ahead and do that, but I'm also totally satisfied having someone else do it if you're already setup for that.

blackrock_3_0_ptp.zip

@apdavison apdavison added this to the 0.14.0 milestone Jan 26, 2024
@apdavison apdavison modified the milestones: 0.14.0, 0.13.1 Feb 23, 2024
@samuelgarcia
Copy link
Contributor

samuelgarcia commented Apr 5, 2024

@zm711
Copy link
Contributor

zm711 commented May 2, 2024

@cboulay, test files were merged, but now you have some merge conflicts 1) we've run black on the code base and 2) we switched over to f-strings rather than % or .format. Did you want to try to touch those up?

@cboulay
Copy link
Contributor Author

cboulay commented May 2, 2024

OK I've rebased and fixed the conflicts along the way. Let's hope the tests pass. BTW, I don't mind if you squash the commits when merging... there was some back and forth on quotes that become obsolete when you adopted PEP8.

@cboulay
Copy link
Contributor Author

cboulay commented May 2, 2024

Actually I went ahead and squashed into 1 commit.

The unit test isn't running because it can't find the file. I guess I'm not providing its path correctly. Can anyone help me out with that part?

Copy link
Contributor

@zm711 zm711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cboulay see my comment and see if it looks reasonable.

See test structure here:
https://gin.g-node.org/NeuralEnsemble/ephy_testing_data/src/master/blackrock/blackrock_3_0_ptp

neo/test/rawiotest/test_blackrockrawio.py Show resolved Hide resolved
… nanosecond timestamps

blackrockrawio - fix backwards compatibility by retrieving 'timestamp_resolution' from another location for older file spec.

blackrockrawio - fix calculation of clk threshold to identify segment breaks.

blackrockrawio - add unit test for filespec 3.0 ptp
@cboulay
Copy link
Contributor Author

cboulay commented May 3, 2024

I'm pretty lost trying to figure out what's going on the with file loading. I'm happy to yield to someone else.

@zm711
Copy link
Contributor

zm711 commented May 3, 2024

@cboulay,

We are planning on including this in the next release which will go out in the next few days so if you have the time to either implement my commit fix or give us access we will include otherwise we will plan on this for the next release.

@cboulay
Copy link
Contributor Author

cboulay commented May 3, 2024

I don't see the option to allow edits from maintainers. I found the GH docs that explains it but the option isn't on this page.

@zm711
Copy link
Contributor

zm711 commented May 3, 2024

Normally there is a little check box on the right side of the page just below all the info. When I first looked at your PR you had it turned on but it got switched off at some point. Either way we will see if tests pass now!

@zm711
Copy link
Contributor

zm711 commented May 3, 2024

Seems like it failed. Could you doublecheck the gin link I gave you and make sure it has all the files necessary for blackrock?

@cboulay
Copy link
Contributor Author

cboulay commented May 3, 2024

Ah, it's because I made the PR from the lab org. sigh

@zm711
Copy link
Contributor

zm711 commented May 3, 2024

So I think there are two paths that need to be fixed. One at the top and one at the bottom. Since I can't push stuff here do you want a PR on your branch with the two file path fixes I think we need and we can test?

@cboulay
Copy link
Contributor Author

cboulay commented May 3, 2024

I tried copying the pattern of the other files (blackrock_2_1, blackrock_3_0). It works locally but not on the runner.

Your suggested changes break from that pattern and don't work locally nor on the runner.

I'll make a new PR from my user account then grant edit permissions.

@zm711
Copy link
Contributor

zm711 commented May 3, 2024

That's cool. One last check:

could you try this as the filename? Previously you didn't have the -001 right? so maybe it needs the full file name for the .nev file?

20231027-125608-001

@zm711
Copy link
Contributor

zm711 commented May 3, 2024

Perfect that worked! thanks for bearing with me! The dirname messed with me! We should really call that filename in the tests for this IO (not your fault, something we've been discussing #1455 recently).

@cboulay
Copy link
Contributor Author

cboulay commented May 3, 2024

Seems to be working. Thanks for your help!

@zm711
Copy link
Contributor

zm711 commented May 3, 2024

@samuelgarcia tests are passing here, but you also said you would look over the code. Did you want to read this over first before we merge?

EDIT: Just pinging @samuelgarcia again since I sent the first message later on Friday evening.

@samuelgarcia
Copy link
Contributor

Thanks a lot for this new add Chadwick.
And thanks a lot to wait for me.
this looks good to me.

@apdavison apdavison merged commit 0071e4e into NeuralEnsemble:master May 7, 2024
2 checks passed
@cboulay cboulay deleted the cboulay/1332_blackrock_too_many_files branch June 14, 2024 15:48
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

Successfully merging this pull request may close these issues.

BlackRock data format 3.0
6 participants