Commit bf3ea398 authored by payno's avatar payno
Browse files

Merge branch 'add_z_translation' into 'master'

Add z translation on HDF5TomoScan

See merge request !32
parents 0ae22c45 2c750012
Pipeline #43125 passed with stages
in 14 minutes and 13 seconds
......@@ -170,6 +170,21 @@ class EDFTomoScan(TomoScanBase):
self.__dim1, self.__dim2 = EDFTomoScan.get_dim1_dim2(scan=self.path)
return self.__dim2
@property
@docstring(TomoScanBase.x_translation)
def x_translation(self) -> Union[None, tuple]:
raise NotImplementedError("Not supported for EDF")
@property
@docstring(TomoScanBase.y_translation)
def y_translation(self) -> Union[None, tuple]:
raise NotImplementedError("Not supported for EDF")
@property
@docstring(TomoScanBase.z_translation)
def z_translation(self) -> Union[None, tuple]:
raise NotImplementedError("Not supported for EDF")
@property
@docstring(TomoScanBase.ff_interval)
def ff_interval(self) -> Union[None, int]:
......
......@@ -89,6 +89,12 @@ class HDF5TomoScan(TomoScanBase):
_ROTATION_ANGLE_PATH = "sample/rotation_angle"
_X_TRANS_PATH = "sample/x_translation"
_Y_TRANS_PATH = "sample/y_translation"
_Z_TRANS_PATH = "sample/z_translation"
_IMG_KEY_PATH = "instrument/detector/image_key"
_IMG_KEY_CONTROL_PATH = "instrument/detector/image_key_control"
......@@ -184,6 +190,9 @@ class HDF5TomoScan(TomoScanBase):
self._estimated_cor_frm_motor = None
self._start_time = None
self._end_time = None
self._x_translations = None
self._y_translations = None
self._z_translations = None
@staticmethod
def get_master_file(scan_path):
......@@ -221,6 +230,9 @@ class HDF5TomoScan(TomoScanBase):
self._distance = None
self._fov = None
self._image_keys_control = None
self._x_translations = None
self._y_translations = None
self._z_translations = None
@staticmethod
def _get_entry_at(index: int, file_path: str) -> str:
......@@ -465,7 +477,7 @@ class HDF5TomoScan(TomoScanBase):
return None
@property
def rotation_angle(self) -> typing.Union[None, list]:
def rotation_angle(self) -> typing.Union[None, tuple]:
if self._rotation_angles is None:
self._check_hdf5scan_validity()
with HDF5File(self.master_file, "r", swmr=True) as h5_file:
......@@ -478,6 +490,48 @@ class HDF5TomoScan(TomoScanBase):
)
return self._rotation_angles
@property
def x_translation(self) -> typing.Union[None, tuple]:
if self._x_translations is None:
self._check_hdf5scan_validity()
with HDF5File(self.master_file, "r", swmr=True) as h5_file:
entry = h5_file[self._entry]
if self._X_TRANS_PATH in entry:
translations = h5py_read_dataset(entry[self._X_TRANS_PATH])
# cast in float
self._x_translations = tuple(
[float(trans) for trans in translations]
)
return self._x_translations
@property
def y_translation(self) -> typing.Union[None, tuple]:
if self._y_translations is None:
self._check_hdf5scan_validity()
with HDF5File(self.master_file, "r", swmr=True) as h5_file:
entry = h5_file[self._entry]
if self._Y_TRANS_PATH in entry:
translations = h5py_read_dataset(entry[self._Y_TRANS_PATH])
# cast in float
self._y_translations = tuple(
[float(trans) for trans in translations]
)
return self._y_translations
@property
def z_translation(self) -> typing.Union[None, tuple]:
if self._z_translations is None:
self._check_hdf5scan_validity()
with HDF5File(self.master_file, "r", swmr=True) as h5_file:
entry = h5_file[self._entry]
if self._Z_TRANS_PATH in entry:
translations = h5py_read_dataset(entry[self._Z_TRANS_PATH])
# cast in float
self._z_translations = tuple(
[float(trans) for trans in translations]
)
return self._z_translations
@property
def image_key(self) -> typing.Union[list, None]:
if self._entry and self._image_keys is None:
......@@ -729,6 +783,15 @@ class HDF5TomoScan(TomoScanBase):
if self._frames is None:
image_keys = self.image_key
rotation_angles = self.rotation_angle
x_translation = self.x_translation
if x_translation is None:
x_translation = [None] * len(image_keys)
y_translation = self.y_translation
if y_translation is None:
y_translation = [None] * len(image_keys)
z_translation = self.z_translation
if z_translation is None:
z_translation = [None] * len(image_keys)
if len(image_keys) != len(rotation_angles):
raise ValueError(
"`rotation_angle` and `image_key` have "
......@@ -759,8 +822,13 @@ class HDF5TomoScan(TomoScanBase):
delta_angle = None
last_proj_frame = None
return_already_reach = False
for i_frame, rot_a, img_key in zip(
range(len(rotation_angles)), rotation_angles, image_keys
for i_frame, rot_a, img_key, x_tr, y_tr, z_tr in zip(
range(len(rotation_angles)),
rotation_angles,
image_keys,
x_translation,
y_translation,
z_translation,
):
url = DataUrl(
file_path=self.master_file,
......@@ -770,7 +838,13 @@ class HDF5TomoScan(TomoScanBase):
)
frame = Frame(
index=i_frame, url=url, image_key=img_key, rotation_angle=rot_a
index=i_frame,
url=url,
image_key=img_key,
rotation_angle=rot_a,
x_translation=x_tr,
y_translation=y_tr,
z_translation=z_tr,
)
if self.image_key_control is not None:
is_control_frame = (
......@@ -862,6 +936,9 @@ class Frame:
image_key: typing.Union[None, ImageKey, int] = None,
rotation_angle: typing.Union[None, float] = None,
is_control_proj: bool = False,
x_translation: typing.Union[None, float] = None,
y_translation: typing.Union[None, float] = None,
z_translation: typing.Union[None, float] = None,
):
assert type(index) is int
self._index = index
......@@ -870,6 +947,9 @@ class Frame:
self._url = url
self._is_control_frame = is_control_proj
self._data = None
self._x_translation = x_translation
self._y_translation = y_translation
self._z_translation = z_translation
@property
def index(self) -> int:
......@@ -899,6 +979,18 @@ class Frame:
def is_control(self) -> bool:
return self._is_control_frame
@property
def x_translation(self):
return self._x_translation
@property
def y_translation(self):
return self._y_translation
@property
def z_translation(self):
return self._z_translation
@is_control.setter
def is_control(self, is_return: bool):
self._is_control_frame = is_return
......@@ -908,11 +1000,17 @@ class Frame:
"Frame {index},: image_key: {image_key},"
"is_control: {is_control},"
"rotation_angle: {rotation_angle},"
"x_translation: {x_translation},"
"y_translation: {y_translation},"
"z_translation: {z_translation},"
"url: {url}".format(
index=self.index,
image_key=self.image_key,
is_control=self.is_control,
rotation_angle=self.rotation_angle,
url=self.url.path(),
x_translation=self.x_translation,
y_translation=self.y_translation,
z_translation=self.z_translation,
)
)
......@@ -272,6 +272,18 @@ class TomoScanBase:
"""
raise NotImplementedError("Base class")
@property
def x_translation(self) -> typing.Union[None, tuple]:
raise NotImplementedError("Base class")
@property
def y_translation(self) -> typing.Union[None, tuple]:
raise NotImplementedError("Base class")
@property
def z_translation(self) -> typing.Union[None, tuple]:
raise NotImplementedError("Base class")
def get_distance(self, unit="m") -> Union[None, float]:
"""
......
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