diff --git a/dandi/pynwb_utils.py b/dandi/pynwb_utils.py index 3d0a8b3ec..6d3faf09c 100644 --- a/dandi/pynwb_utils.py +++ b/dandi/pynwb_utils.py @@ -7,13 +7,14 @@ import os.path as op from pathlib import Path import re -from typing import IO, Any, TypeVar, cast +from typing import IO, Any, TypeVar, cast, Literal 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 @@ -479,14 +480,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 diff --git a/dandi/tests/fixtures.py b/dandi/tests/fixtures.py index 2981ddd62..e7fe3139a 100644 --- a/dandi/tests/fixtures.py +++ b/dandi/tests/fixtures.py @@ -234,6 +234,17 @@ def organized_nwb_dir2( ), **simple1_nwb_metadata, ) + make_nwb_file( + 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 diff --git a/setup.cfg b/setup.cfg index 6f806b9f0..e38088202 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,6 +38,7 @@ install_requires = fasteners fscacher >= 0.3.0 hdmf != 3.5.0 + hdmf_zarr humanize interleave ~= 0.1 joblib