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

Enh/detect nwb1 #1086

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ def __init__(self, **kwargs):
manager = get_manager()
super(NWBHDF5IO, self).__init__(path, manager=manager, mode=mode, file=file_obj, comm=comm)

@docval(*get_docval(_HDF5IO.read))
def read(self, **kwargs):
try:
return super(NWBHDF5IO, self).read(**kwargs)
except ValueError as e:
built = next(iter(self._HDF5IO__built.values()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajtritt and I suggest checking for neurodata_type. If it does not exist, then the file is not 2.0+.

To report the NWB 1.x version, it would be better to open the h5py.File and look for the root-level dataset 'nwb_version' (around 1.0.4) or the root-level dataset 'neurodata_version' (1.0.0).

if '/nwb_version' in built:
raise Exception('File is version {} and is not supported by PyNWB. '
'h5py is recommended as an alternative.'.
format(built['/nwb_version'].data))
bendichter marked this conversation as resolved.
Show resolved Hide resolved
else:
raise e


from . import io as __io # noqa: F401,E402
from .core import NWBContainer, NWBData # noqa: F401,E402
Expand Down