AllenInstitute / AllenSDK

code for reading and processing Allen Institute for Brain Science data
https://allensdk.readthedocs.io/en/latest/
Other
343 stars 149 forks source link

KeyError: "'ndx-aibs-ecephys' not a namespace" when loading NWB files #2513

Open dervinism opened 2 years ago

dervinism commented 2 years ago

Describe the bug I get the following error when I try to read NWB files (Visual Coding Neuropixels experiment) after loading them with NWBHDF5IO function of pynwb package:

Traceback (most recent call last):
  File "f:\infraslow-dynamics\02_material_and_methods\02_code\allensdk\loadNWB.py", line 7, in <module>       
    nwbfile = io.read()
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\backends\hdf5\h5tools.py", line 447, in read
    return call_docval_func(super().read, kwargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\utils.py", line 434, in call_docval_func
    return func(*fargs, **fkwargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\utils.py", line 593, in func_call
    return func(args[0], **pargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\backends\io.py", line 42, in read
    container = self.__manager.construct(f_builder)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\utils.py", line 593, in func_call
    return func(args[0], **pargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\manager.py", line 280, in construct
    result = self.__type_map.construct(builder, self, None)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\utils.py", line 593, in func_call
    return func(args[0], **pargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\manager.py", line 794, in construct
    return obj_mapper.construct(builder, build_manager, parent)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\utils.py", line 593, in func_call
    return func(args[0], **pargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1218, in construct
    subspecs = self.__get_subspec_values(builder, self.spec, manager)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1147, in __get_subspec_values
    self.__get_sub_builders(groups, spec.groups, manager, ret)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1198, in __get_sub_builders
    ret.update(self.__get_subspec_values(sub_builder, subspec, manager))
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1147, in __get_subspec_values
    self.__get_sub_builders(groups, spec.groups, manager, ret)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1190, in __get_sub_builders
    sub_builder = self.__flatten(sub_builder, subspec, manager)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1203, in __flatten
    tmp = [manager.construct(b) for b in sub_builder]
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1203, in <listcomp>
    tmp = [manager.construct(b) for b in sub_builder]
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\utils.py", line 593, in func_call
    return func(args[0], **pargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\manager.py", line 276, in construct
    result = self.__type_map.construct(builder, self, parent)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\utils.py", line 593, in func_call
    return func(args[0], **pargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\manager.py", line 794, in construct
    return obj_mapper.construct(builder, build_manager, parent)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\utils.py", line 593, in func_call
    return func(args[0], **pargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1218, in construct
    subspecs = self.__get_subspec_values(builder, self.spec, manager)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1147, in __get_subspec_values
    self.__get_sub_builders(groups, spec.groups, manager, ret)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\build\objectmapper.py", line 1176, in __get_sub_builders
    for parent_dt in manager.namespace_catalog.get_hierarchy(ns, dt):
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\utils.py", line 593, in func_call
    return func(args[0], **pargs)
  File "C:\Users\3XS Admin\.conda\envs\nwb\lib\site-packages\hdmf\spec\namespace.py", line 329, in get_hierarchy
    raise KeyError("'%s' not a namespace" % namespace)
KeyError: "'ndx-aibs-ecephys' not a namespace"

To Reproduce Install pynwb in a separate conda environment and execute the script below on vscode

import numpy as np
from pynwb import NWBHDF5IO
# Open the file in read mode "r"
io = NWBHDF5IO('F:/infraslow-dynamics/03_data/003_allen_raw_derived/M766640955/session_766640955.nwb', mode="r")
nwbfile = io.read()

Expected behavior Expected not to get this error. There is no problem loading these files in HDFView.

Actual Behavior Error

Environment (please complete the following information):

Additional context None

Do you want to work on this issue? No

rly commented 2 years ago

Hi @dervinism , please add the argument load_namespaces=True when opening the file and let me know if that works:

io = NWBHDF5IO('F:/infraslow-dynamics/03_data/003_allen_raw_derived/M766640955/session_766640955.nwb', mode="r", load_namespaces=True)
nwbfile = io.read()

I think you can also use the allensdk to open the NWB file instead of pynwb: https://allensdk.readthedocs.io/en/latest/visual_coding_neuropixels.html

dervinism commented 2 years ago

Adding load_namespaces=True worked. However, I cannot load the same file in Matlab. Running the code line below

nwb2 = nwbRead('F:\infraslow-dynamics\03_data\003_allen_raw_derived\M766640955\session_766640955.nwb');

gives the following error:

Error using types.util.correctType (line 11)
Value of type `cell` could not be coerced into a logical value.

Error in types.util.checkDtype (line 111)
            val = types.util.correctType(val, type);

Error in types.ndx_aibs_ecephys.EcephysElectrodeGroup/validate_has_lfp_data (line
64)
        val = types.util.checkDtype('has_lfp_data', 'logical', val);

Error in types.ndx_aibs_ecephys.EcephysElectrodeGroup/set.has_lfp_data (line 35)
        obj.has_lfp_data = obj.validate_has_lfp_data(val);

Error in types.ndx_aibs_ecephys.EcephysElectrodeGroup (line 26)
        obj.has_lfp_data = p.Results.has_lfp_data;

Error in io.parseGroup (line 85)
    parsed = eval([Type.typename '(kwargs{:})']);

Error in io.parseGroup (line 38)
    subg = io.parseGroup(filename, group, Blacklist);

Error in io.parseGroup (line 38)
    subg = io.parseGroup(filename, group, Blacklist);

Error in io.parseGroup (line 38)
    subg = io.parseGroup(filename, group, Blacklist);

Error in nwbRead (line 59)
nwb = io.parseGroup(filename, h5info(filename), Blacklist);

Shouldn't NWB files be readabe both in Python and Matlab?

rly commented 2 years ago

That may be a bug in matnwb. Can you post an issue ticket there?