Commit 9c0fcf0d authored by payno's avatar payno
Browse files

[hdf5scan] add swrm option active

parent 3ffd534e
Pipeline #24739 passed with stages
in 2 minutes and 7 seconds
...@@ -232,7 +232,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -232,7 +232,7 @@ class HDF5TomoScan(TomoScanBase):
if not os.path.isfile(file_path): if not os.path.isfile(file_path):
raise ValueError('given file path should be a file') raise ValueError('given file path should be a file')
with h5py.File(file_path, 'r') as h5f: with h5py.File(file_path, 'r', swmr=True) as h5f:
for root_node in h5f.keys(): for root_node in h5f.keys():
node = h5f[root_node] node = h5f[root_node]
if HDF5TomoScan.node_is_nxtomo(node) is True: if HDF5TomoScan.node_is_nxtomo(node) is True:
...@@ -400,7 +400,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -400,7 +400,7 @@ class HDF5TomoScan(TomoScanBase):
def rotation_angle(self) -> typing.Union[None, list]: def rotation_angle(self) -> typing.Union[None, list]:
if self._rotation_angles is None: if self._rotation_angles is None:
self._check_hdf5scan_validity() self._check_hdf5scan_validity()
with h5py.File(self.master_file, 'r') as h5_file: with h5py.File(self.master_file, 'r', swmr=True) as h5_file:
_rotation_angles = h5_file[self._entry][self._ROTATION_ANGLE_PATH][()] _rotation_angles = h5_file[self._entry][self._ROTATION_ANGLE_PATH][()]
# cast in float # cast in float
self._rotation_angles = tuple([float(angle) for angle in _rotation_angles]) self._rotation_angles = tuple([float(angle) for angle in _rotation_angles])
...@@ -410,7 +410,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -410,7 +410,7 @@ class HDF5TomoScan(TomoScanBase):
def image_key(self) -> typing.Union[list, None]: def image_key(self) -> typing.Union[list, None]:
if self._entry and self._image_keys is None: if self._entry and self._image_keys is None:
self._check_hdf5scan_validity() self._check_hdf5scan_validity()
with h5py.File(self.master_file, 'r') as h5_file: with h5py.File(self.master_file, 'r', swmr=True) as h5_file:
self._image_keys = h5_file[self._entry][self._IMG_KEY_PATH][()] self._image_keys = h5_file[self._entry][self._IMG_KEY_PATH][()]
return self._image_keys return self._image_keys
...@@ -418,7 +418,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -418,7 +418,7 @@ class HDF5TomoScan(TomoScanBase):
def image_key_control(self) -> typing.Union[list, None]: def image_key_control(self) -> typing.Union[list, None]:
if self._entry and self._image_keys_control is None: if self._entry and self._image_keys_control is None:
self._check_hdf5scan_validity() self._check_hdf5scan_validity()
with h5py.File(self.master_file, 'r') as h5_file: with h5py.File(self.master_file, 'r', swmr=True) as h5_file:
if self._IMG_KEY_CONTROL_PATH in h5_file[self._entry]: 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 = h5_file[self._entry][self._IMG_KEY_CONTROL_PATH][()]
else: else:
...@@ -489,7 +489,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -489,7 +489,7 @@ class HDF5TomoScan(TomoScanBase):
def _get_x_y_pixel_values(self): def _get_x_y_pixel_values(self):
"""read x and y pixel values""" """read x and y pixel values"""
with h5py.File(self.master_file, 'r') as h5_file: with h5py.File(self.master_file, 'r', swmr=True) as h5_file:
x_pixel_dataset = h5_file[self._entry][self._X_PIXEL_SIZE_PATH] x_pixel_dataset = h5_file[self._entry][self._X_PIXEL_SIZE_PATH]
_x_pixel_size = self._get_value(x_pixel_dataset, default_unit='micrometer') _x_pixel_size = self._get_value(x_pixel_dataset, default_unit='micrometer')
y_pixel_dataset = h5_file[self._entry][self._Y_PIXEL_SIZE_PATH] y_pixel_dataset = h5_file[self._entry][self._Y_PIXEL_SIZE_PATH]
...@@ -497,7 +497,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -497,7 +497,7 @@ class HDF5TomoScan(TomoScanBase):
return _x_pixel_size, _y_pixel_size return _x_pixel_size, _y_pixel_size
def _get_x_y_magnified_pixel_values(self): def _get_x_y_magnified_pixel_values(self):
with h5py.File(self.master_file, 'r') as h5_file: with h5py.File(self.master_file, 'r', swmr=True) as h5_file:
x_m_pixel_dataset = h5_file[self._entry][self._X_PIXEL_MAG_SIZE_PATH] x_m_pixel_dataset = h5_file[self._entry][self._X_PIXEL_MAG_SIZE_PATH]
_x_m_pixel_size = self._get_value(x_m_pixel_dataset, default_unit='micrometer') _x_m_pixel_size = self._get_value(x_m_pixel_dataset, default_unit='micrometer')
y_m_pixel_dataset = h5_file[self._entry][self._Y_PIXEL_MAG_SIZE_PATH] y_m_pixel_dataset = h5_file[self._entry][self._Y_PIXEL_MAG_SIZE_PATH]
...@@ -536,7 +536,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -536,7 +536,7 @@ class HDF5TomoScan(TomoScanBase):
if (self._distance is None and self.master_file and if (self._distance is None and self.master_file and
os.path.exists(self.master_file)): os.path.exists(self.master_file)):
self._check_hdf5scan_validity() self._check_hdf5scan_validity()
with h5py.File(self.master_file, 'r') as h5_file: with h5py.File(self.master_file, 'r', swmr=True) as h5_file:
distance_dataset = h5_file[self._entry][self._DISTANCE_PATH] distance_dataset = h5_file[self._entry][self._DISTANCE_PATH]
self._distance = self._get_value(distance_dataset, default_unit='m') self._distance = self._get_value(distance_dataset, default_unit='m')
return self._distance return self._distance
...@@ -546,7 +546,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -546,7 +546,7 @@ class HDF5TomoScan(TomoScanBase):
if (self._energy is None and self.master_file and if (self._energy is None and self.master_file and
os.path.exists(self.master_file)): os.path.exists(self.master_file)):
self._check_hdf5scan_validity() self._check_hdf5scan_validity()
with h5py.File(self.master_file, 'r') as h5_file: with h5py.File(self.master_file, 'r', swmr=True) as h5_file:
energy_dataset = h5_file[self._entry][self._ENERGY_PATH] energy_dataset = h5_file[self._entry][self._ENERGY_PATH]
self._energy = self._get_value(energy_dataset, default_unit='keV') self._energy = self._get_value(energy_dataset, default_unit='keV')
return self._energy return self._energy
...@@ -656,7 +656,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -656,7 +656,7 @@ class HDF5TomoScan(TomoScanBase):
raise ValueError('No master file provided') raise ValueError('No master file provided')
if self.entry is None: if self.entry is None:
raise ValueError('No entry provided') raise ValueError('No entry provided')
with h5py.File(self.master_file, 'r') as h5_file: with h5py.File(self.master_file, 'r', swmr=True) as h5_file:
if self._entry not in h5_file: if self._entry not in h5_file:
raise ValueError('Given entry %s is not in the master ' raise ValueError('Given entry %s is not in the master '
'file %s' % (self._entry, self.master_file)) 'file %s' % (self._entry, self.master_file))
......
...@@ -246,7 +246,7 @@ class MockHDF5(_ScanMock): ...@@ -246,7 +246,7 @@ class MockHDF5(_ScanMock):
def _append_frame(self, data_, rotation_angle, image_key, def _append_frame(self, data_, rotation_angle, image_key,
image_key_control): image_key_control):
with h5py.File(self.scan_master_file, 'r+') as h5_file: with h5py.File(self.scan_master_file, 'r+', swmr=True) as h5_file:
entry_one = h5_file.require_group(self.scan_entry) entry_one = h5_file.require_group(self.scan_entry)
instrument_grp = entry_one.require_group('instrument') instrument_grp = entry_one.require_group('instrument')
detector_grp = instrument_grp.require_group('detector') detector_grp = instrument_grp.require_group('detector')
...@@ -297,7 +297,7 @@ class MockHDF5(_ScanMock): ...@@ -297,7 +297,7 @@ class MockHDF5(_ScanMock):
else: else:
new_count_time = [self._PROJ_COUNT, ] new_count_time = [self._PROJ_COUNT, ]
with h5py.File(self.scan_master_file, 'a') as h5_file: with h5py.File(self.scan_master_file, 'a', swmr=True) as h5_file:
entry_one = h5_file.require_group(self.scan_entry) entry_one = h5_file.require_group(self.scan_entry)
instrument_grp = entry_one.require_group('instrument') instrument_grp = entry_one.require_group('instrument')
if 'NX_class' not in instrument_grp.attrs: if 'NX_class' not in instrument_grp.attrs:
...@@ -317,7 +317,7 @@ class MockHDF5(_ScanMock): ...@@ -317,7 +317,7 @@ class MockHDF5(_ScanMock):
sample_grp['rotation_angle'] = new_rot_angle sample_grp['rotation_angle'] = new_rot_angle
def write_metadata(self, n_radio, scan_range, ref_n, dark_n): def write_metadata(self, n_radio, scan_range, ref_n, dark_n):
with h5py.File(self.scan_master_file, 'a') as h5_file: with h5py.File(self.scan_master_file, 'a', swmr=True) as h5_file:
entry_one = h5_file.require_group(self.scan_entry) entry_one = h5_file.require_group(self.scan_entry)
instrument_grp = entry_one.require_group('instrument') instrument_grp = entry_one.require_group('instrument')
detector_grp = instrument_grp.require_group('detector') detector_grp = instrument_grp.require_group('detector')
......
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