From ca7ddad9907dbd6fbb43563ece6090ebaee10c4e Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 9 Sep 2024 17:35:10 -0400 Subject: [PATCH 1/3] Use "cache_spec:False" in our copy_nwb_file helper while exporting NWB copy Stopped since ideally we should make it dependent on either original file contains the spec --- dandi/pynwb_utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dandi/pynwb_utils.py b/dandi/pynwb_utils.py index 3d0a8b3ec..a8dca3e31 100644 --- a/dandi/pynwb_utils.py +++ b/dandi/pynwb_utils.py @@ -518,7 +518,16 @@ def copy_nwb_file(src: str | Path, dest: str | Path) -> str: with pynwb.NWBHDF5IO(src, "r") as ior, pynwb.NWBHDF5IO(dest, "w") as iow: data = ior.read() data.generate_new_id() - iow.export(ior, nwbfile=data) + iow.export( + ior, + nwbfile=data, + # do not export spec since + **( + {"cache_spec": False} + if Version(pynwb.__version__) > Version("2.8.2.dev11") + else {} + ), + ) return str(dest) From 4061912f24a08135bdf131f4a2c74c0f2407ec57 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 12 Sep 2024 20:29:24 -0400 Subject: [PATCH 2/3] Use released version of pynwb in comparison Co-authored-by: Ryan Ly --- dandi/pynwb_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dandi/pynwb_utils.py b/dandi/pynwb_utils.py index a8dca3e31..92e3d4a9b 100644 --- a/dandi/pynwb_utils.py +++ b/dandi/pynwb_utils.py @@ -524,7 +524,7 @@ def copy_nwb_file(src: str | Path, dest: str | Path) -> str: # do not export spec since **( {"cache_spec": False} - if Version(pynwb.__version__) > Version("2.8.2.dev11") + if Version(pynwb.__version__) > Version("2.8.2") else {} ), ) From 8dba0108b8e8e0aee219d7cfff38caf880de5a3d Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 12 Sep 2024 20:36:59 -0400 Subject: [PATCH 3/3] Fix comparison but also make caching optional depending on either original file had it --- dandi/pynwb_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dandi/pynwb_utils.py b/dandi/pynwb_utils.py index 92e3d4a9b..e280c6ab7 100644 --- a/dandi/pynwb_utils.py +++ b/dandi/pynwb_utils.py @@ -515,18 +515,18 @@ def copy_nwb_file(src: str | Path, dest: str | Path) -> str: dest = op.join(dest, op.basename(src)) else: os.makedirs(op.dirname(dest), exist_ok=True) + kws = {} + if Version(pynwb.__version__) >= Version("2.8.2"): + # we might make it leaner by not caching the spec if original + # file did not have it. Possible only since 2.8.2.dev11 + kws["cache_spec"] = bool(pynwb.NWBHDF5IO.get_namespaces(src)) with pynwb.NWBHDF5IO(src, "r") as ior, pynwb.NWBHDF5IO(dest, "w") as iow: data = ior.read() data.generate_new_id() iow.export( ior, nwbfile=data, - # do not export spec since - **( - {"cache_spec": False} - if Version(pynwb.__version__) > Version("2.8.2") - else {} - ), + **kws, ) return str(dest)