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

[Bug]: .specloc not saved in consolidated metadata #243

Open
3 tasks done
stephprince opened this issue Nov 22, 2024 · 0 comments
Open
3 tasks done

[Bug]: .specloc not saved in consolidated metadata #243

stephprince opened this issue Nov 22, 2024 · 0 comments
Labels
category: bug errors in the code or code behavior
Milestone

Comments

@stephprince
Copy link
Contributor

stephprince commented Nov 22, 2024

What happened?

For context, I was trying to update the ZarrIO.load_namespaces method to accept the ZarrIO.file property as an input. I planned to update these lines below to define f = io.file if a path was not provided:

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', storage_options=storage_options)

I thought the object returned from zarr.open would be the same as the one obtained from io.file. However, when trying to obtain the cached spec from the io.file object, there is no 'specifications' group in io.file and .specloc is not listed in the attrs. I think this may be because the io.file property can be set using zarr.open_consolidated, and looking at the file it seems .specloc is not saved in the consolidated metadata.

I wasn't sure if this was actually a bug or I may be misunderstanding how the consolidated metadata should work.

Steps to Reproduce

import zarr

from pynwb.testing.mock.ecephys import mock_Device, mock_ElectrodeGroup, mock_ElectrodeTable
from pynwb.testing.mock.file import mock_NWBFile

from hdmf.common import DynamicTableRegion
from hdmf_zarr.nwb import NWBZarrIO

# create nwb file
device = mock_Device()
group = mock_ElectrodeGroup(device=device)
electrodes_table = mock_ElectrodeTable(group=group)
electrodes = DynamicTableRegion(name="electrodes", data=list(range(5)), table=electrodes_table, description="electrodes")
nwbfile = mock_NWBFile(electrode_groups=[group], 
                       electrodes=electrodes_table, 
                       devices=[device])

path = "zarr_testing.nwb.zarr"
with NWBZarrIO(path=path, mode="w") as io:
    io.write(nwbfile)

with NWBZarrIO(path=path, mode="r") as io:
    # group from io.file
    print(f'{io.file.attrs.keys() = }')
    
    # group from zarr.open
    f = zarr.open(path, mode='r')
    print(f'{f.attrs.keys() = }')

    # group from zarr.open_consolidated
    f = zarr.open_consolidated(path, mode='r')
    print(f'{f.attrs.keys() = }')

Traceback

io.file.attrs.keys() = dict_keys(['namespace', 'neurodata_type', 'nwb_version', 'object_id'])

f.attrs.keys() = dict_keys(['.specloc', 'namespace', 'neurodata_type', 'nwb_version', 'object_id'])

f.attrs.keys() = dict_keys(['namespace', 'neurodata_type', 'nwb_version', 'object_id'])

Operating System

macOS

Python Executable

Conda

Python Version

3.11

Package Versions

No response

Code of Conduct

@rly rly added the category: bug errors in the code or code behavior label Nov 26, 2024
@rly rly added this to the Future milestone Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug errors in the code or code behavior
Projects
None yet
Development

No branches or pull requests

2 participants