-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Some files contain metadata fields, such as NXDetector's bit_depth_readout, in a 1D, length-1 dataset instead of a scalar. These could previously be read OK, but Numpy 2.4 is stricter about converting to a scalar, so code has started failing on files that worked before.
import sys
import h5py
import nxmx
with h5py.File(sys.argv[1]) as f:
nxmx_data = nxmx.NXmx(f)
nxdet = nxmx_data.entries[0].instruments[0].detectors[0]
nxdet.bit_depth_readoutTraceback (most recent call last):
File "/home/kluyvert/Code/instrument-geometry-info/Tools/nxmx-test.py", line 9, in <module>
nxdet.bit_depth_readout
File "/home/kluyvert/.conda/envs/dxtbx/lib/python3.11/functools.py", line 1001, in __get__
val = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/home/kluyvert/.conda/envs/dxtbx/lib/python3.11/site-packages/nxmx/__init__.py", line 887, in bit_depth_readout
return int(self._handle["bit_depth_readout"][()])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: only 0-dimensional arrays can be converted to Python scalars
The file I'm looking at is available from this Zenodo entry - the 'master' file, although the field in question is an external link pointing to the meta file.
I'm not sure if using a length-1 dataset instead of a scalar is strictly valid, but it worked until now, and neither of the Nexus validation tools I tried told me that it's wrong, so it seems reasonable to allow it. I encountered this through dxtbx, which tries to accommodate all the quirks of how real files get written, so if this is out of scope for nxmx, I can open an issue on that project instead.