8000 Enhancing NWB support · Issue #853 · talmolab/sleap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Enhancing NWB support #853
Closed
Closed
@talmo

Description

@talmo

We should support the features mentioned by @bendichter in our NWB I/O.

  1. Make the adapter more flexible.

    def write(self, filename: str, labels: Labels):

    This should accept a couple more things to look like:

    write(
        self,
        filename: str,
        overwrite: bool = False,
        session_description: str = "sleap",
        identifier: Optional[str] = None,  # if None, use a GUID like str(uuid.uuid4())
        session_start_time: Optional[datetime.datetime] = None,  # if None, use datetime.datetime.now()
    ):
        if session_start_time is None:
            session_start_time = datetime.datetime.now(datetime.timezone.utc)
        if identifier is None:
            identifier = uuid.uuid4()
        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)
  2. Create a high-level export API as a instance-level method on Labels with signature:

    def export_nwb(self, filename: str, overwrite: bool = False, session_description: str = "sleap", identifier: Optional[str] = None, session_start_time: Optional[datetime.datetime] = None):
        # Call the adapter to write self

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

  1. Add append feature

Currently, a user is not able to set required metadata such as the session_start_time, identifier, and session_description. Instead, placeholder values are used here:

nwb_file = NWBFile(
session_description="session_description",
identifier="identifier",
session_start_time=datetime.datetime.now(datetime.timezone.utc),
)

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.

  1. Adding sleap to NWB software documentation

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?

  1. NWB Conversion Tools

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?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0