Commit 59d53b1b authored by payno's avatar payno Committed by Henri Payno
Browse files

normalization: fix providing a scalar value

parent 80b55ad0
......@@ -233,8 +233,10 @@ class NormIOW(WidgetLongProcessing, SuperviseOW):
},
process_index=scan.pop_process_index(),
)
if tomwer_processing_res_code is True:
# if defined by manual scalar we need to set the value
if extra_infos.get("source", None) == _ValueSource.MANUAL_SCALAR.value:
extra_infos["value"] = self.getCurrentlyDefinedValues()
self.notify_succeed(scan=scan)
elif tomwer_processing_res_code is False:
self.notify_failed(scan=scan)
......@@ -255,9 +257,11 @@ class NormIOW(WidgetLongProcessing, SuperviseOW):
"dataset_url": self._window._optsWidget._datasetWidget.getDatasetUrl().path(),
}
else:
extra_infos = {"value": self.getCurrentlyDefinedValues()}
extra_infos = {
"value": self.getCurrentlyDefinedValues(),
"source": self.getCurrentSource(),
}
self.notify_succeed(scan=scan)
# clear flag
scan.intensity_normalization.set_extra_infos(extra_infos)
......
......@@ -579,10 +579,12 @@ class _NabuBaseReconstructor:
def dump_normalization_array_for_nabu(
scan: TomwerScanBase, output_file: str, array: numpy.ndarray
scan: TomwerScanBase, output_file: str, array: Union[numpy.ndarray, float, int]
) -> DataUrl:
if not isinstance(array, numpy.ndarray):
raise TypeError(f"array is expected to be a numpy array and not {type(array)}")
if not isinstance(array, (numpy.ndarray, float, int)):
raise TypeError(
f"array is expected to be a numpy array or a scalar and not {type(array)}"
)
# save the value to a dedicated path in "nabu_tomwer_serving_hatch"
if isinstance(scan, HDF5TomoScan):
entry_path = scan.entry
......@@ -596,11 +598,18 @@ def dump_normalization_array_for_nabu(
while serving_hatch_data_path is None or serving_hatch_data_path in h5f:
serving_hatch_data_path = "/".join([entry_path, str(uuid.uuid1())])
# adapt value to what nabues expects.
if (isinstance(array, numpy.ndarray) and array.ndim == 1) or isinstance(
array, (tuple, list)
if isinstance(array, (float, int)) or (
isinstance(array, numpy.ndarray) and array.ndim == 1 and len(array) == 1
):
dim_1 = scan.dim_1
array = numpy.asarray(
numpy.asarray([array] * len(scan.projections) * dim_1)
)
array = array.reshape(len(scan.projections), dim_1)
elif isinstance(array, numpy.ndarray) and array.ndim == 1:
dim_1 = scan.dim_1
array = numpy.repeat(array, dim_1).reshape(len(array), dim_1)
h5f[serving_hatch_data_path] = array
file_path = os.path.join(
settings.NABU_CFG_FILE_FOLDER, settings.NABU_TOMWER_SERVING_HATCH
......
......@@ -151,6 +151,7 @@ class NormIntensityWindow(qt.QMainWindow):
extra_info.update(
{
"tomwer_processing_res_code": True,
"source": source.value,
}
)
scan.intensity_normalization.set_extra_infos(extra_info)
......
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