G-Node / nixpy

Python library for NIX
https://readthedocs.org/projects/nixpy
Other
20 stars 26 forks source link

Catch exception for old boolean type #483

Open achilleas-k opened 4 years ago

achilleas-k commented 4 years ago

Since v1.2 (2016) the file representation for boolean types has changed. Files created before this version can't be read using h5py; the old representation is not compatible with h5py at all. This hasn't been an issue in general, but it came up recently (https://github.com/G-Node/nix-odML-converter/issues/26) during some old file conversions. The way to fix these would be to use NIX (C++) or HDF5 directly to change the format of older files. Since we can't automate that with NIXPy, we should catch the exception and provide a more useful error message.

achilleas-k commented 4 years ago

Since h5py 2.10, bitfields can be read but the type needs to be explicitly set: https://docs.h5py.org/en/latest/whatsnew/2.10.html#new-features

with dset.astype(numpy.bool):
    arr = dset[:]