Commit 05388877 authored by payno's avatar payno
Browse files

[HDF5Tomoscan] add {x/y/z}translation properties

parent 0ae22c45
......@@ -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,42 @@ 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:
_translations = h5_file[self._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:
_translations = h5_file[self._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:
_translations = h5_file[self._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 +777,9 @@ class HDF5TomoScan(TomoScanBase):
if self._frames is None:
image_keys = self.image_key
rotation_angles = self.rotation_angle
x_translation = self.x_translation
y_translation = self.y_translation
z_translation = self.z_translation
if len(image_keys) != len(rotation_angles):
raise ValueError(
"`rotation_angle` and `image_key` have "
......@@ -759,8 +810,9 @@ 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 +822,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 +920,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 +931,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 +963,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 +984,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,
)
)
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