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 all 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
12 changes: 9 additions & 3 deletions dandi/pynwb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

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

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

View check run for this annotation

Codecov / codecov/patch

dandi/tests/fixtures.py#L237

Added line #L237 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