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 .nwb to known Zarr suffixes; add tests for NWB Zarr backend #1312

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dandi/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def urls(self) -> Iterator[str]:
VIDEO_FILE_EXTENSIONS = [".mp4", ".avi", ".wmv", ".mov", ".flv", ".mkv"]
VIDEO_FILE_MODULES = ["processing", "acquisition"]

ZARR_EXTENSIONS = [".ngff", ".zarr"]
ZARR_EXTENSIONS = [".ngff", ".zarr", ".nwb"]
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved

#: Maximum allowed depth of a Zarr directory tree
MAX_ZARR_DEPTH = 7
Expand Down
12 changes: 9 additions & 3 deletions dandi/pynwb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import os.path as op
from pathlib import Path
import re
from typing import IO, Any, Dict, List, Optional, Tuple, TypeVar, Union, cast
from typing import IO, Any, Dict, List, Literal, Optional, Tuple, TypeVar, Union, cast
import warnings

import dandischema
from fscacher import PersistentCache
import h5py
import hdmf
import hdmf_zarr
from packaging.version import Version
import pynwb
from pynwb import NWBHDF5IO
Expand Down Expand Up @@ -482,14 +483,19 @@ def get_object_id(path: str | Path | Readable) -> Any:


def make_nwb_file(
filename: StrPath, *args: Any, cache_spec: bool = False, **kwargs: Any
filename: StrPath,
*args: Any,
cache_spec: bool = False,
backend: Literal["hdf5", "zarr"] = "hdf5",
**kwargs: Any,
) -> StrPath:
"""A little helper to produce an .nwb file in the path using NWBFile

Note: it doesn't cache_spec by default
"""
backends = dict(hdf5=pynwb.NWBHDF5IO, zarr=hdmf_zarr.NWBZarrIO)
nwbfile = pynwb.NWBFile(*args, **kwargs)
with pynwb.NWBHDF5IO(filename, "w") as io:
with backends[backend](filename, "w") as io:
io.write(nwbfile, cache_spec=cache_spec)
return filename

Expand Down
11 changes: 11 additions & 0 deletions dandi/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@
),
**simple1_nwb_metadata,
)
make_nwb_file(

Check warning on line 232 in dandi/tests/fixtures.py

View check run for this annotation

Codecov / codecov/patch

dandi/tests/fixtures.py#L232

Added line #L232 was not covered by tests
tmp_path / "simple1_zarr.nwb",
backend="zarr",
subject=pynwb.file.Subject(
subject_id="lizard001",
date_of_birth=datetime(2016, 12, 1, tzinfo=tzutc()),
sex="F",
species="Gekko gecko",
),
**simple1_nwb_metadata,
)
(tmp_path / dandiset_metadata_file).write_text("{}\n")
r = CliRunner().invoke(organize, ["-f", "move", "--dandiset-path", str(tmp_path)])
assert r.exit_code == 0, r.stdout
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ install_requires =
fasteners
fscacher >= 0.3.0
hdmf != 3.5.0
hdmf_zarr
humanize
interleave ~= 0.1
joblib
Expand Down
Loading