Commit bdaf4d1b authored by payno's avatar payno
Browse files

[hdf5] read rotation motor from "technique/scan/motor"

- to activate this option the H5_ROT_ANGLE_KEYS should be set to None
- close #62
parent 28587dfd
Pipeline #46146 passed with stages
in 4 minutes and 55 seconds
......@@ -119,6 +119,8 @@ class BaseAcquisition:
_END_TIME_PATH = "end_time"
_TECHNIQUE_MOTOR_PATH = "technique/scan/motor"
def __init__(
self,
root_url: typing.Union[DataUrl, None],
......@@ -285,6 +287,35 @@ class BaseAcquisition:
raise TypeError("entry_node is expected to be a h5py.Group")
return BaseAcquisition._get_instrument_node(entry_node)["positioners"]
def _read_rotation_motor_name(self) -> typing.Union[str, None]:
"""read rotation motor from root_url/technique/scan/motor
:return: name of the motor used for rotation. None if cannot find
:rtype: Union[tuple, None]
"""
if self._root_url is None:
_logger.warning("no root url. Unable to read rotation motor")
return None
else:
with EntryReader(self._root_url) as entry:
if self._TECHNIQUE_MOTOR_PATH in entry:
try:
motor_and_aliases = h5py_read_dataset(
entry[self._TECHNIQUE_MOTOR_PATH]
)
rotation_motor = motor_and_aliases[0]
except Exception as e:
_logger.error(e)
else:
return rotation_motor
else:
_logger.warning(
"{} does not exists in {}".format(
self._TECHNIQUE_MOTOR_PATH, self._root_url
)
)
return None
def _get_rotation_angle(self, root_node, n_frame) -> tuple:
"""return the list of rotation angle for each frame"""
if not isinstance(root_node, h5py.Group):
......
......@@ -479,6 +479,14 @@ class StandardAcquisition(BaseAcquisition):
self._diode_unit = None
self._copied_dataset = {}
# if rotation motor is not defined try to deduce it from root_url/technique/scan/motor
if self.configuration.rotation_angle_keys is None:
rotation_motor = self._read_rotation_motor_name()
if rotation_motor is not None:
self.configuration.rotation_angle_keys = (rotation_motor,)
else:
self.configuration.rotation_angle_keys = tuple()
# list of data virtual source for the virtual dataset
for entry_url, type_ in self._registered_entries.items():
url = DataUrl(path=entry_url)
......
......@@ -201,6 +201,7 @@ class TestH5ToNxConverter(unittest.TestCase):
self.config.single_file = True
self.config.request_input = False
self.config.raises_error = True
self.config.rotation_angle_keys = ("hrsrot",)
converter.from_h5_to_nx(configuration=self.config)
# insure only one file is generated
self.assertTrue(os.path.exists(self.config.output_file))
......@@ -400,6 +401,7 @@ class TestXRDCTConversion(unittest.TestCase):
self.config.output_file = sample.sample_file.replace(".h5", ".nx")
self.config.single_file = True
self.config.request_input = False
self.config.rotation_angle_keys = ("hrsrot",)
converter.from_h5_to_nx(configuration=self.config)
# insure only one file is generated
......@@ -425,6 +427,7 @@ class TestStandardAcqConversionWithExternalUrls(unittest.TestCase):
self.folder = tempfile.mkdtemp()
self.config = HDF5Config()
self.config.output_file = os.path.join(self.folder, "output.nx")
self.config.rotation_angle_keys = ("hrsrot",)
def create_scan(self, n_projection_scans, n_flats, n_darks, output_dir):
"""
......
......@@ -40,17 +40,8 @@ H5_VALID_CAMERA_NAMES = None
# detector name (unix shell-style wildcards are managed) like
# ("pcolinux*", "basler", "frelon*", ...)
H5_ROT_ANGLE_KEYS = (
"rotm",
"mhsrot",
"hsrot",
"mrsrot",
"hrsrot",
"srot",
"diffrz",
"hrrz_trig",
"rot",
)
H5_ROT_ANGLE_KEYS = None
"""Keys used to find the rotation motor. If None will look for it on technique/scan/motor"""
H5_X_TRANS_KEYS = ("sx", "d3tx", "tfx", "px")
"""Keys used to find the x translation"""
......
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