Commit 8a78d324 authored by payno's avatar payno
Browse files

[h5py] replace `[()]` by h5py_read_dataset

parent bee1c80b
Pipeline #36621 failed with stages
in 12 seconds
......@@ -43,6 +43,7 @@ from tomoscan.io import HDF5File
from silx.io.utils import get_data
from ..unitsystem import metricsystem
from .utils import get_compacted_dataslices
from silx.io.utils import h5py_read_dataset
import typing
import logging
......@@ -443,7 +444,9 @@ class HDF5TomoScan(TomoScanBase):
if self._rotation_angles is None:
self._check_hdf5scan_validity()
with HDF5File(self.master_file, "r", swmr=True) as h5_file:
_rotation_angles = h5_file[self._entry][self._ROTATION_ANGLE_PATH][()]
_rotation_angles = h5py_read_dataset(
h5_file[self._entry][self._ROTATION_ANGLE_PATH]
)
# cast in float
self._rotation_angles = tuple(
[float(angle) for angle in _rotation_angles]
......@@ -455,7 +458,9 @@ class HDF5TomoScan(TomoScanBase):
if self._entry and self._image_keys is None:
self._check_hdf5scan_validity()
with HDF5File(self.master_file, "r", swmr=True) as h5_file:
self._image_keys = h5_file[self._entry][self._IMG_KEY_PATH][()]
self._image_keys = h5py_read_dataset(
h5_file[self._entry][self._IMG_KEY_PATH]
)
return self._image_keys
@property
......@@ -464,9 +469,9 @@ class HDF5TomoScan(TomoScanBase):
self._check_hdf5scan_validity()
with HDF5File(self.master_file, "r", swmr=True) as h5_file:
if self._IMG_KEY_CONTROL_PATH in h5_file[self._entry]:
self._image_keys_control = h5_file[self._entry][
self._IMG_KEY_CONTROL_PATH
][()]
self._image_keys_control = h5py_read_dataset(
h5_file[self._entry][self._IMG_KEY_CONTROL_PATH]
)
else:
self._image_keys_control = None
return self._image_keys_control
......@@ -563,7 +568,7 @@ class HDF5TomoScan(TomoScanBase):
def _get_fov(self):
with HDF5File(self.master_file, "r", swmr=True, libver="latest") as h5_file:
if self._FOV_PATH in h5_file[self._entry]:
fov = h5_file[self._entry][self._FOV_PATH][()]
fov = h5py_read_dataset(h5_file[self._entry][self._FOV_PATH])
return _FOV.from_value(fov)
else:
return None
......@@ -571,7 +576,9 @@ class HDF5TomoScan(TomoScanBase):
def _get_estimated_cor_frm_motor(self):
with HDF5File(self.master_file, "r", swmr=True, libver="latest") as h5_file:
if self._ESTIMATED_COR_FRM_MOTOR_PATH in h5_file[self._entry]:
value = h5_file[self._entry][self._ESTIMATED_COR_FRM_MOTOR_PATH][()]
value = h5py_read_dataset(
h5_file[self._entry][self._ESTIMATED_COR_FRM_MOTOR_PATH]
)
return float(value)
else:
return None
......@@ -776,7 +783,7 @@ class HDF5TomoScan(TomoScanBase):
Unit can be defined in on of the group attributes. It it is the case
will pick this unit, otherwise will use the default unit
"""
value = node[()]
value = h5py_read_dataset(node)
if "unit" in node.attrs:
unit = node.attrs["unit"]
elif "units" in node.attrs:
......
......@@ -36,6 +36,7 @@ from xml.etree import cElementTree
import fabio
import fabio.edfimage
from .hdf5scan import ImageKey, HDF5TomoScan
from silx.io.utils import h5py_read_dataset
class _ScanMock:
......@@ -293,7 +294,7 @@ class MockHDF5(_ScanMock):
# add data
if "data" in detector_grp:
# read and remove data
current_dataset = detector_grp["data"][()]
current_dataset = h5py_read_dataset(detector_grp["data"])
new_dataset = numpy.append(current_dataset, data_)
del detector_grp["data"]
shape = list(current_dataset.shape)
......@@ -304,7 +305,7 @@ class MockHDF5(_ScanMock):
# add rotation angle
if "rotation_angle" in sample_grp:
new_rot_angle = sample_grp["rotation_angle"][()]
new_rot_angle = h5py_read_dataset(sample_grp["rotation_angle"])
new_rot_angle = numpy.append(new_rot_angle, rotation_angle)
del sample_grp["rotation_angle"]
else:
......@@ -314,7 +315,7 @@ class MockHDF5(_ScanMock):
# add image_key
if "image_key" in detector_grp:
new_image_key = detector_grp["image_key"][()]
new_image_key = h5py_read_dataset(detector_grp["image_key"])
new_image_key = numpy.append(new_image_key, image_key)
del detector_grp["image_key"]
else:
......@@ -324,7 +325,9 @@ class MockHDF5(_ScanMock):
# add image_key_control
if "image_key_control" in detector_grp:
new_image_key_control = detector_grp["image_key_control"][()]
new_image_key_control = h5py_read_dataset(
detector_grp["image_key_control"]
)
new_image_key_control = numpy.append(
new_image_key_control, image_key_control
)
......@@ -336,7 +339,7 @@ class MockHDF5(_ScanMock):
# add count_time
if "count_time" in detector_grp:
new_count_time = detector_grp["count_time"][()]
new_count_time = h5py_read_dataset(detector_grp["count_time"])
new_count_time = numpy.append(new_count_time, self._PROJ_COUNT)
del detector_grp["count_time"]
else:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment