Commit 2fdeb7c0 authored by payno's avatar payno
Browse files

Merge branch 'change_extra_params_names' into 'master'

h52nx: rename keys for extra parameters when provided by the configuration file

See merge request !78
parents 5cd24083 e1096e01
Pipeline #59935 passed with stages
in 6 minutes and 7 seconds
......@@ -538,18 +538,35 @@ class StandardAcquisition(BaseAcquisition):
)
return values, unit
def get_already_defined_params(self, key):
defined = self.__get_extra_param(key=key)
if len(defined) > 1:
raise ValueError("{} are aliases. Only one should be defined")
elif len(defined) == 0:
return None
else:
return list(defined.values())[0]
def __get_extra_param(self, key) -> dict:
"""return already defined parameters for one key.
A key as aliases so it returns a dict"""
aliases = list(TomoHDF5Config.EXTRA_PARAMS_ALIASES[key])
aliases.append(key)
res = {}
for alias in aliases:
if alias in self.configuration.param_already_defined:
res[alias] = self.configuration.param_already_defined[alias]
return res
def _write_beam(self, root_node, request_input, input_callback):
instrument_node = root_node.require_group("instrument")
beam_node = instrument_node.require_group("beam")
if (
TomoHDF5Config.EXTRA_PARAMS_ENERGY_DK
in self.configuration.param_already_defined
):
energy = float(
self.configuration.param_already_defined[
TomoHDF5Config.EXTRA_PARAMS_ENERGY_DK
]
)
already_defined = self.get_already_defined_params(
key=TomoHDF5Config.EXTRA_PARAMS_ENERGY_DK
)
if already_defined is not None:
energy = float(already_defined)
unit = "kev"
else:
energy, unit = self._get_energy(
......@@ -583,15 +600,11 @@ class StandardAcquisition(BaseAcquisition):
detector_node["count_time"] = self._acq_expo_time
detector_node["count_time"].attrs["unit"] = "s"
# write distance
if (
TomoHDF5Config.EXTRA_PARAMS_DISTANCE
in self.configuration.param_already_defined
):
distance = float(
self.configuration.param_already_defined[
TomoHDF5Config.EXTRA_PARAMS_DISTANCE
]
)
already_defined = self.get_already_defined_params(
key=TomoHDF5Config.EXTRA_PARAMS_DISTANCE
)
if already_defined is not None:
distance = float(already_defined)
unit = "m"
else:
distance, unit = self._get_distance()
......@@ -601,15 +614,11 @@ class StandardAcquisition(BaseAcquisition):
# write x and y pixel size
# if magnified pixel size is found then we right this value.
# otherwise will take pixel size (if found)
if (
TomoHDF5Config.EXTRA_PARAMS_X_PIXEL_SIZE_DK
in self.configuration.param_already_defined
):
x_pixel_size = float(
self.configuration.param_already_defined[
TomoHDF5Config.EXTRA_PARAMS_X_PIXEL_SIZE_DK
]
)
already_defined = self.get_already_defined_params(
key=TomoHDF5Config.EXTRA_PARAMS_X_PIXEL_SIZE_DK
)
if already_defined is not None:
x_pixel_size = float(already_defined)
unit = "m"
else:
x_pixel_size, unit = self._get_pixel_size("x")
......@@ -617,15 +626,11 @@ class StandardAcquisition(BaseAcquisition):
detector_node["x_pixel_size"] = x_pixel_size
detector_node["x_pixel_size"].attrs["unit"] = unit
if (
TomoHDF5Config.EXTRA_PARAMS_Y_PIXEL_SIZE_DK
in self.configuration.param_already_defined
):
y_pixel_size = float(
self.configuration.param_already_defined[
TomoHDF5Config.EXTRA_PARAMS_Y_PIXEL_SIZE_DK
]
)
already_defined = self.get_already_defined_params(
key=TomoHDF5Config.EXTRA_PARAMS_Y_PIXEL_SIZE_DK
)
if already_defined is not None:
y_pixel_size = float(already_defined)
unit = "m"
else:
y_pixel_size, unit = self._get_pixel_size("y")
......
......@@ -254,18 +254,33 @@ class TomoHDF5Config:
EXTRA_PARAMS_SECTION_DK = "EXTRA_PARAMS_SECTION"
EXTRA_PARAMS_ENERGY_DK = "energy"
EXTRA_PARAMS_X_PIXEL_SIZE_DK = "x_pixel_size"
EXTRA_PARAMS_Y_PIXEL_SIZE_DK = "y_pixel_size"
EXTRA_PARAMS_DISTANCE = "detector_sample_distance"
EXTRA_PARAMS_ENERGY_DK = "energy_kev"
EXTRA_PARAMS_ENERGY_DK_ALIASES = ("energy",)
EXTRA_PARAMS_X_PIXEL_SIZE_DK = "x_pixel_size_m"
EXTRA_PARAMS_X_PIXEL_SIZE_DK_ALIASES = ("x_pixel_size",)
EXTRA_PARAMS_Y_PIXEL_SIZE_DK = "y_pixel_size_m"
EXTRA_PARAMS_Y_PIXEL_SIZE_DK_ALIASES = ("y_pixel_size",)
EXTRA_PARAMS_DISTANCE = "detector_sample_distance_m"
EXTRA_PARAMS_DISTANCE_ALIASES = ("detector_sample_distance",)
EXTRA_PARAMS_ENERGY_VALID_KEYS = (
EXTRA_PARAMS_ENERGY_DK,
*EXTRA_PARAMS_ENERGY_DK_ALIASES,
EXTRA_PARAMS_X_PIXEL_SIZE_DK,
*EXTRA_PARAMS_X_PIXEL_SIZE_DK_ALIASES,
EXTRA_PARAMS_Y_PIXEL_SIZE_DK,
*EXTRA_PARAMS_Y_PIXEL_SIZE_DK_ALIASES,
EXTRA_PARAMS_DISTANCE,
*EXTRA_PARAMS_DISTANCE_ALIASES,
)
EXTRA_PARAMS_ALIASES = {
EXTRA_PARAMS_ENERGY_DK: EXTRA_PARAMS_ENERGY_DK_ALIASES,
EXTRA_PARAMS_X_PIXEL_SIZE_DK: EXTRA_PARAMS_X_PIXEL_SIZE_DK_ALIASES,
EXTRA_PARAMS_Y_PIXEL_SIZE_DK: EXTRA_PARAMS_Y_PIXEL_SIZE_DK_ALIASES,
EXTRA_PARAMS_DISTANCE: EXTRA_PARAMS_DISTANCE_ALIASES,
}
COMMENTS_EXTRA_PARAMS_SECTION = {
EXTRA_PARAMS_SECTION_DK: "optional section\n"
"# you can predefined values which are missing in the input .h5 file\n"
......
......@@ -50,12 +50,14 @@ SETTABLE_PARAMETERS_UNITS = {
"energy": "kev",
"x_pixel_size": "m",
"y_pixel_size": "m",
"detector_sample_distance": "m",
}
SETTABLE_PARAMETERS_TYPE = {
"energy": float,
"x_pixel_size": float,
"y_pixel_size": float,
"detector_sample_distance": float,
}
SETTABLE_PARAMETERS = SETTABLE_PARAMETERS_UNITS.keys()
......
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