-
Notifications
You must be signed in to change notification settings - Fork 100
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
Enhancing NWB support #853
Comments
Sounds great, and it was nice meeting you all today! I just wanted to mention some technical details about operating on an NWBFile in append mode that we've learned from many past experiences... The approach of if Path(filename).exists() and not overwrite:
with NWBHDF5IO(filename, mode="r") as io:
nwb_file = io.read()
else:
nwb_file = NWBFile(
session_description=session_description,
identifier=identifier,
session_start_time=session_start_time,
)
# ...
with NWBHDF5IO(path, mode="w" if overwrite else "a") as io:
io.write(nwb_file) when Instead, the way we've successfully performed appending is to do so from within the respective context that that Here are some code snippets that have evolved over the years for this purpose... The oldest, probably least fancy way: https://github.com/catalystneuro/neuroconv/blob/cc1c2fb9b175eeabe026066901d2a8344585343a/src/nwb_conversion_tools/nwbconverter.py#L168-L181 which is basically what you have now except everything is combined into a single context and the The newer/fancier way we have is through our own custom designed context for making the 'append' vs. 'make a fresh NWBFile' decision behind the scenes: https://github.com/catalystneuro/neuroconv/blob/main/src/neuroconv/nwbconverter.py#L173-L184 + https://github.com/catalystneuro/neuroconv/blob/main/src/neuroconv/tools/nwb_helpers.py#L118-L177 Of course another alternative is to simply not use a context at all and just remember to call Oh, and another design principle I'd strongly suggest is making whatever the steps are within that Anyway, looking forward to meeting some of you at Janelia next week! |
Yet another detail that I just recalled - any call to |
Excellent, thanks for the pointers @CodyCBakerPhD!! We'll be mindful of how we work with the IO handles. |
Added in v1.2.5. |
We should support the features mentioned by @bendichter in our NWB I/O.
Make the adapter more flexible.
sleap/sleap/io/format/ndx_pose.py
Line 167 in d522f1d
This should accept a couple more things to look like:
Create a high-level export API as a instance-level method on
Labels
with signature:Discussed in #851
Originally posted by bendichter July 21, 2022
I see you have made a lot of progress in supporting NWB lately! It looks like you are using the ndx-pose extension as intended. A few points I want to bring up
Currently, a user is not able to set required metadata such as the
session_start_time
,identifier
, andsession_description
. Instead, placeholder values are used here:sleap/sleap/io/format/ndx_pose.py
Lines 218 to 222 in d522f1d
with no way to overwrite them. This creates NWB files that are valid, but contains incorrect data. There are two ways to solve this. The first is to allow a user to pass in this metadata to the
write
function. The second would be to allow a user to create an NWB file on their own with the proper metadata and then append the sleap data to that file.The second approach, allowing a user to append to an existing NWB file, also solves a different problem. NWB files are meant to store all of the streams of data in a single file, e.g. behavior + optical physiology or electrophysiology. If I wanted to put sleap and ephys data in an NWB file, since this is currently written without an append option, I'd be forced to first write the sleap data and then append the ephys data. This is technically doable but becomes a problem if any other data writer or converter has the same limitation of not being able to append. Because of this, it is best practice to allow for appending to an existing NWB file.
We keep track of software that can read and write NWB here. Would you mind submitting a PR here next to the entry for DeepLabCut so our users know that sleap is part of the NWB ecosystem?
We are developing NWB Conversion Tools which provide automated conversions from a large number of proprietary formats. It would be great if we could use this library to convert data that has already been written to NWB. It seems like your adapter system with read and write for several formats could be helpful. Does sleap have a standard output format?
The text was updated successfully, but these errors were encountered: