Commit 4b1a868e authored by payno's avatar payno
Browse files

Merge branch 'fix_unit_0_2' into 'master'

[tomohdf5scan] fix units conversion from _get_value and return distance in meter now

See merge request !17
parents 096e85f7 46a98752
Pipeline #28312 passed with stages
in 2 minutes and 42 seconds
......@@ -482,10 +482,12 @@ class HDF5TomoScan(TomoScanBase):
@property
def pixel_size(self) -> typing.Union[None, float]:
"""return x pixel size in meter"""
return self.x_pixel_size
@property
def x_pixel_size(self) -> typing.Union[None, float]:
"""return x pixel size in meter"""
if (self._x_pixel_size is None and self.master_file and
os.path.exists(self.master_file)):
self._x_pixel_size, self._y_pixel_size = self._get_x_y_pixel_values()
......@@ -496,17 +498,17 @@ class HDF5TomoScan(TomoScanBase):
"""read x and y pixel values"""
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_size = self._get_value(x_pixel_dataset, default_unit='micrometer')
_x_pixel_size = self._get_value(x_pixel_dataset, default_unit='meter')
y_pixel_dataset = h5_file[self._entry][self._Y_PIXEL_SIZE_PATH]
_y_pixel_size = self._get_value(y_pixel_dataset, default_unit='micrometer')
_y_pixel_size = self._get_value(y_pixel_dataset, default_unit='meter')
return _x_pixel_size, _y_pixel_size
def _get_x_y_magnified_pixel_values(self):
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_size = self._get_value(x_m_pixel_dataset, default_unit='micrometer')
_x_m_pixel_size = self._get_value(x_m_pixel_dataset, default_unit='meter')
y_m_pixel_dataset = h5_file[self._entry][self._Y_PIXEL_MAG_SIZE_PATH]
_y_m_pixel_size = self._get_value(y_m_pixel_dataset, default_unit='micrometer')
_y_m_pixel_size = self._get_value(y_m_pixel_dataset, default_unit='meter')
return _x_m_pixel_size, _y_m_pixel_size
def _get_dim1_dim2(self):
......@@ -517,6 +519,7 @@ class HDF5TomoScan(TomoScanBase):
@property
def y_pixel_size(self) -> typing.Union[None, float]:
"""return y pixel size in meter"""
if (self._y_pixel_size is None and self.master_file and
os.path.exists(self.master_file)):
self._x_pixel_size, self._y_pixel_size = self._get_x_y_pixel_values()
......@@ -524,6 +527,7 @@ class HDF5TomoScan(TomoScanBase):
@property
def x_magnified_pixel_size(self) -> typing.Union[None, float]:
"""return x magnified pixel size in meter"""
if (self._x_magnified_pixel_size is None and self.master_file and
os.path.exists(self.master_file)):
self._x_magnified_pixel_size, self._y_magnified_pixel_size = self._get_x_y_magnified_pixel_values()
......@@ -531,6 +535,7 @@ class HDF5TomoScan(TomoScanBase):
@property
def y_magnified_pixel_size(self) -> typing.Union[None, float]:
"""return y magnified pixel size in meter"""
if (self._y_magnified_pixel_size is None and self.master_file and
os.path.exists(self.master_file)):
self._x_magnified_pixel_size, self._y_magnified_pixel_size = self._get_x_y_magnified_pixel_values()
......@@ -538,6 +543,7 @@ class HDF5TomoScan(TomoScanBase):
@property
def distance(self) -> typing.Union[None, float]:
"""return sample detector distance in meter"""
if (self._distance is None and self.master_file and
os.path.exists(self.master_file)):
self._check_hdf5scan_validity()
......@@ -548,6 +554,7 @@ class HDF5TomoScan(TomoScanBase):
@property
def energy(self) -> typing.Union[None, float]:
"""energy in keV"""
if (self._energy is None and self.master_file and
os.path.exists(self.master_file)):
self._check_hdf5scan_validity()
......@@ -650,7 +657,7 @@ class HDF5TomoScan(TomoScanBase):
value = node[()]
if 'unit' in node.attrs:
unit = node.attrs['unit']
if 'units' in node.attrs:
elif 'units' in node.attrs:
unit = node.attrs['units']
else:
unit = default_unit
......
......@@ -190,12 +190,12 @@ class TestHDF5Scan(HDF5TestBaseClass):
pixel_size = self.scan.pixel_size
self.assertTrue(pixel_size is not None)
self.assertTrue(numpy.isclose(self.scan.pixel_size,
0.05 * metricsystem.MetricSystem.MICROMETER.value))
self.assertTrue(numpy.isclose(self.scan.get_pixel_size(unit='micrometer'), 0.05))
0.05 * metricsystem.MetricSystem.MILLIMETER.value))
self.assertTrue(numpy.isclose(self.scan.get_pixel_size(unit='micrometer'), 50))
self.assertTrue(numpy.isclose(self.scan.x_pixel_size,
0.05 * metricsystem.MetricSystem.MICROMETER.value))
0.05 * metricsystem.MetricSystem.MILLIMETER.value))
self.assertTrue(numpy.isclose(self.scan.y_pixel_size,
0.05 * metricsystem.MetricSystem.MICROMETER.value))
0.05 * metricsystem.MetricSystem.MILLIMETER.value))
def testNabuUtil(self):
self.assertTrue(numpy.isclose(self.scan.distance, -19.9735))
......
Markdown is supported
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