Skip to content

Commit

Permalink
default load_namespace (#204)
Browse files Browse the repository at this point in the history
* default

* fix load_namespaces open

* gallery

* Update CHANGELOG.md
  • Loading branch information
mavaylon1 authored Jul 18, 2024
1 parent a508d58 commit 626341c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 7 additions & 3 deletions src/hdmf_zarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 7 additions & 10 deletions src/hdmf_zarr/nwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,22 @@ 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})
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:
Expand Down

0 comments on commit 626341c

Please sign in to comment.