Commit 9d829a57 authored by payno's avatar payno Committed by Henri Payno
Browse files

normalization: one more round of bug fix

parent 57b1194c
......@@ -51,6 +51,8 @@ from tomwer.core.process.reconstruction.normalization import (
)
from tomwer.core import settings
from tomwer.core import utils
from tomoscan.normalization import Method as NormMethod
from tomwer.core.process.reconstruction.normalization.params import _ValueSource
import functools
_logger = logging.getLogger(__name__)
......@@ -217,7 +219,9 @@ class NormIOW(WidgetLongProcessing, SuperviseOW):
# save processing result for the one with interaction. Otherwise
# this will be saved in the processing thread
extra_infos = scan.intensity_normalization.get_extra_infos()
tomwer_processing_res_code = extra_infos.get("tomwer_processing_res_code")
tomwer_processing_res_code = extra_infos.pop(
"tomwer_processing_res_code", "unprocessed"
)
IntensityNormalizationTask._register_process(
process_file=scan.process_file,
process=IntensityNormalizationTask,
......@@ -234,8 +238,28 @@ class NormIOW(WidgetLongProcessing, SuperviseOW):
self.notify_succeed(scan=scan)
elif tomwer_processing_res_code is False:
self.notify_failed(scan=scan)
else:
elif tomwer_processing_res_code is None:
self.notify_skip(scan=scan)
elif tomwer_processing_res_code == "unprocessed":
# if validate manually we must set current method + value
scan.intensity_normalization = self.getCurrentMethod()
if self.getCurrentMethod() in (
NormMethod.NONE,
NormMethod.CHEBYSHEV,
NormMethod.LSQR_SPLINE,
):
extra_infos = {}
elif self.getCurrentSource() is _ValueSource.DATASET:
extra_infos = {
"dataset_url": self._window._optsWidget._datasetWidget.getDatasetUrl().path(),
}
else:
extra_infos = {"value": self.getCurrentlyDefinedValues()}
self.notify_succeed(scan=scan)
# clear flag
scan.intensity_normalization.set_extra_infos(extra_infos)
self.Outputs.data_out.send(scan)
......@@ -255,6 +279,9 @@ class NormIOW(WidgetLongProcessing, SuperviseOW):
self.notify_skip(scan=scan, details=details)
self.Outputs.data_out.send(scan)
def getCurrentlyDefinedValues(self):
return self._window._crtWidget.getResult()
def validateCurrentScan(self):
scan = self._window.getScan()
self._validate(scan)
......
......@@ -169,13 +169,6 @@ class TestProcessing(TestCaseQt):
),
DatasetState.SUCCEED,
)
# insure a normalization has been registered
self.assertTrue(
self.scan_3.intensity_normalization.get_extra_infos().get(
"tomwer_processing_res_code"
),
True,
)
def testTestLbsram(self):
"""Test scan are all validated if 'low memory on lbsram' scenario is
......
......@@ -488,7 +488,7 @@ class _NabuBaseReconstructor:
)
os.makedirs(nabu_cfg_folders, exist_ok=True)
serving_hatch_file = os.path.join(
nabu_cfg_folders, "nabu_tomwer_serving_hatch.h5"
nabu_cfg_folders, settings.NABU_TOMWER_SERVING_HATCH
)
source = extra_infos.get("source", INormSource.NONE)
......@@ -520,9 +520,11 @@ class _NabuBaseReconstructor:
[entry_path, str(uuid.uuid1())]
)
h5f[serving_hatch_data_path] = extra_infos["value"]
file_path = os.path.join(
settings.NABU_CFG_FILE_FOLDER, settings.NABU_TOMWER_SERVING_HATCH
)
serving_hatch_url = DataUrl(
file_path="nabu_tomwer_serving_hatch.h5", # configuration file and nabu_tomwer_serving_hatch are in the same folder
file_path=file_path, # configuration file and nabu_tomwer_serving_hatch are in the same folder
data_path=serving_hatch_data_path,
scheme="silx",
)
......
......@@ -38,6 +38,10 @@ NABU_FILE_PER_GROUP = 100
NABU_CONFIG_FILE_EXTENSION = ".cfg"
NABU_CFG_FILE_FOLDER = "nabu_cfg_files"
# foler where nabu configuraiton will be saved
NABU_TOMWER_SERVING_HATCH = "nabu_tomwer_serving_hatch.h5"
# file used to insure some passing from tomwer to nabu like providing normalization values
try:
import nabu.app.reconstruct # noqa: F401
......
......@@ -112,7 +112,7 @@ class IntensityNormalizationTask(
scan.intensity_normalization.method = params.method
# after this processing the source
try:
if params.method is NormMethod.NONE:
if params.method in (NormMethod.NONE, NormMethod.CHEBYSHEV):
final_norm_info = {}
elif params.source is _ValueSource.MANUAL_ROI:
value = self._compute_from_manual_roi(scan)
......
......@@ -642,9 +642,6 @@ class _NormIntensityOptions(qt.QWidget):
}
elif source is _ValueSource.DATASET:
return {
"calc_fct": self._intensityCalcOpts.getCalculationFct().value,
"calc_area": self._intensityCalcOpts.getCalculationArea().value,
"calc_method": self._intensityCalcOpts.getCalculationMethod().value,
"dataset_url": self._datasetWidget.getDatasetUrl().path(),
}
else:
......@@ -740,6 +737,7 @@ class _NormIntensityControl(ControlWidget):
ControlWidget.__init__(self, parent)
self._resultWidget = qt.QWidget(self)
self._resultWidget.setLayout(qt.QFormLayout())
self._result = None
self._resultQLE = qt.QLineEdit("", self)
self._resultWidget.layout().addRow("value:", self._resultQLE)
......@@ -749,10 +747,14 @@ class _NormIntensityControl(ControlWidget):
self._computeBut.hide()
def setResult(self, result):
self._result = result
if isinstance(result, tuple):
result = ",".join([str(element) for element in result])
self._resultQLE.setText(str(result))
def getResult(self):
return self._result
def clear(self):
self._resultQLE.clear()
......
......@@ -105,9 +105,6 @@ class TestNormIntensityWindow(TestCaseQt):
output_configuration = self._widget.getConfiguration()
assert output_configuration["method"] == "division"
assert output_configuration["source"] == "from dataset"
assert "calc_area" in output_configuration
assert "calc_fct" in output_configuration
assert "calc_method" in output_configuration
assert "dataset_url" in output_configuration
self._widget.setCurrentMethod(NormalizationMethod.DIVISION)
......
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