NeurodataWithoutBorders / pynwb

A Python API for working with Neurodata stored in the NWB Format
https://pynwb.readthedocs.io
Other
174 stars 85 forks source link

Help opening an NWB file #1675

Open dom-linkevicius opened 1 year ago

dom-linkevicius commented 1 year ago

Hello all,

I am new to the NWB ecosystem, I am trying to use some open access electrophysiological data found here as follows:

import pynwb
io = pynwb.NWBHDF5IO("rCell19521.nwb", "r")
nwb_file = io.read() 

But get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\utils.py", line 645, in func_call
    return func(args[0], **pargs)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pynwb\__init__.py", line 282, in read
    raise TypeError("Missing NWB version in file. The file is not a valid NWB file.")
TypeError: Missing NWB version in file. The file is not a valid NWB file.

If I instead do

import pynwb
io = pynwb.NWBHDF5IO("rCell19521.nwb", "r")
nwb_file = io.read(skip_version_check=True) 

I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\utils.py", line 645, in func_call
    return func(args[0], **pargs)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pynwb\__init__.py", line 287, in read
    return super().read(**kwargs)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\backends\hdf5\h5tools.py", line 453, in read
    return super().read(**kwargs)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\utils.py", line 645, in func_call
    return func(args[0], **pargs)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\backends\io.py", line 42, in read
    container = self.__manager.construct(f_builder)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\utils.py", line 645, in func_call
    return func(args[0], **pargs)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\build\manager.py", line 280, in construct
    result = self.__type_map.construct(builder, self, None)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\utils.py", line 645, in func_call
    return func(args[0], **pargs)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\build\manager.py", line 786, in construct
    obj_mapper = self.get_map(builder)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\utils.py", line 645, in func_call
    return func(args[0], **pargs)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\build\manager.py", line 705, in get_map
    container_cls = self.get_cls(obj)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\utils.py", line 645, in func_call
    return func(args[0], **pargs)
  File "C:\Users\domli\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\hdmf\build\manager.py", line 630, in get_cls
    raise ValueError("No data_type found for builder %s" % builder.path)
ValueError: No data_type found for builder root

How would I go about diagnosing whether the issue is with the file or my installation of the relevant libraries? Any help greatly appreciated!

Running on Windows, Python 3.9.13, PyNWB 2.3.1.

t-b commented 1 year ago

I can't download the file without registering...

Are you sure this is a NWBv2 file? They do seem to provide their own API, see https://channelpedia.epfl.ch/expdata/help/19521, and as it is also a long running project, this could be an NWBv1 file. pynwb can only ready v2 files.

dom-linkevicius commented 1 year ago

I see, thank you for the information. Is it at all possible to read NWBv1 files in any way with previous versions of pynwb or convert v1 to v2?

oruebel commented 1 year ago

Is it at all possible to read NWBv1 files in any way with previous versions of pynwb or convert v1 to v2?

PyNWB supports only NWB v2. Version 1 files also used HDF5 so you should be able to open the file h5py (or any other HDF5 tool directly, e.g., the tools listed here https://nwb-overview.readthedocs.io/en/latest/tools/hdftools/hdftools.html) or you could use channelpedia's custom API. I know the channelpedia team was working on publishing at least some of their data in NWB 2, i.e., they may already have the data in NWB2 or have tools to convert the data from 1 to 2. It may be worth reaching out the channelpedia team directly.