diff --git a/CHANGELOG.md b/CHANGELOG.md index f188c2b..d0fa9cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.9.0 (Upcoming) ### Enhancements * Added support for appending a dataset of references. @mavaylon1 [#203]([https://github.com/hdmf-dev/hdmf-zarr/pull/172](https://github.com/hdmf-dev/hdmf-zarr/pull/203)) +* 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 diff --git a/src/hdmf_zarr/backend.py b/src/hdmf_zarr/backend.py index 309ada3..c0b94ea 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 ed3d831..582f1a6 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: