diff --git a/CHANGELOG.md b/CHANGELOG.md index e15428bd..8d9745d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # HDMF-ZARR Changelog +## 0.9.0 (Upcoming) +### Enhancements +* NWBZarrIO load_namespaces=True by default. @mavaylon1 [#204](https://github.com/hdmf-dev/hdmf-zarr/pull/204) + ## 0.8.0 (June 4, 2024) ### Bug Fixes * Fixed bug when opening a file in with `mode=r+`. The file will open without using the consolidated metadata. @mavaylon1 [#182](https://github.com/hdmf-dev/hdmf-zarr/issues/182) diff --git a/src/hdmf_zarr/backend.py b/src/hdmf_zarr/backend.py index df95a2e6..b5c35552 100644 --- a/src/hdmf_zarr/backend.py +++ b/src/hdmf_zarr/backend.py @@ -197,13 +197,17 @@ def is_remote(self): {'name': 'path', 'type': (str, *SUPPORTED_ZARR_STORES), 'doc': 'the path to the Zarr file or a supported Zarr store'}, - {'name': 'namespaces', 'type': list, 'doc': 'the namespaces to load', 'default': None}) - def load_namespaces(cls, namespace_catalog, path, namespaces=None): + {'name': 'storage_options', 'type': dict, + 'doc': 'Zarr storage options to read remote folders', + 'default': None}, + {'name': 'namespaces', 'type': list, 'doc': 'the namespaces to load', 'default': None} + ) + def load_namespaces(cls, namespace_catalog, path, storage_options, namespaces=None): ''' Load cached namespaces from a file. ''' # TODO: how to use storage_options here? - f = zarr.open(path, mode='r') + f = zarr.open(path, mode='r', storage_options=storage_options) if SPEC_LOC_ATTR not in f.attrs: msg = "No cached namespaces found in %s" % path warnings.warn(msg) diff --git a/src/hdmf_zarr/nwb.py b/src/hdmf_zarr/nwb.py index ed3d831c..582f1a63 100644 --- a/src/hdmf_zarr/nwb.py +++ b/src/hdmf_zarr/nwb.py @@ -22,7 +22,7 @@ class NWBZarrIO(ZarrIO): @docval(*get_docval(ZarrIO.__init__), {'name': 'load_namespaces', 'type': bool, 'doc': 'whether or not to load cached namespaces from given path - not applicable in write mode', - 'default': False}, + 'default': True}, {'name': 'extensions', 'type': (str, TypeMap, list), 'doc': 'a path to a namespace, a TypeMap, or a list consisting paths to namespaces and TypeMaps', 'default': None}) @@ -30,17 +30,14 @@ def __init__(self, **kwargs): path, mode, manager, extensions, load_namespaces, synchronizer, storage_options = \ popargs('path', 'mode', 'manager', 'extensions', 'load_namespaces', 'synchronizer', 'storage_options', kwargs) - if load_namespaces: - if manager is not None: - warn("loading namespaces from file - ignoring 'manager'") - if extensions is not None: - warn("loading namespaces from file - ignoring 'extensions' argument") - # namespaces are not loaded when creating an NWBZarrIO object in write mode - if 'w' in mode or mode == 'x': - raise ValueError("cannot load namespaces from file when writing to it") + io_modes_that_create_file = ['w', 'w-', 'x'] + if mode in io_modes_that_create_file or manager is not None or extensions is not None: + load_namespaces = False + + if load_namespaces: tm = get_type_map() - super(NWBZarrIO, self).load_namespaces(tm, path) + super(NWBZarrIO, self).load_namespaces(tm, path, storage_options) manager = BuildManager(tm) else: if manager is not None and extensions is not None: