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

normalization: more test fix

parent 87473b37
......@@ -181,6 +181,12 @@ class NormIOW(WidgetLongProcessing, SuperviseOW):
def getCurrentMethod(self):
return self._window.getCurrentMethod()
def setCurrentSource(self, source):
self._window.setCurrentSource(source)
def getCurrentSource(self):
return self._window.getCurrentSource()
@Inputs.data_in
def process(self, scan: TomwerScanBase):
if not isinstance(scan, (TomwerScanBase, type(None))):
......@@ -210,6 +216,8 @@ 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")
IntensityNormalizationTask._register_process(
process_file=scan.process_file,
process=IntensityNormalizationTask,
......@@ -217,14 +225,14 @@ class NormIOW(WidgetLongProcessing, SuperviseOW):
configuration=self.getConfiguration(),
results={
"method": scan.intensity_normalization.method.value,
"extra_infos": scan.intensity_normalization.get_extra_infos(),
"extra_infos": extra_infos,
},
process_index=scan.pop_process_index(),
)
if scan.intensity_normalization.tomwer_processing_res_code is True:
if tomwer_processing_res_code is True:
self.notify_succeed(scan=scan)
elif scan.intensity_normalization.tomwer_processing_res_code is False:
elif tomwer_processing_res_code is False:
self.notify_failed(scan=scan)
else:
self.notify_skip(scan=scan)
......
......@@ -121,7 +121,9 @@ class TestProcessing(TestCaseQt):
self.widget.setLocked(False)
def process_scalar_manually():
self.widget.setCurrentMethod("manual ROI")
self.widget.setCurrentMethod("division")
self.widget.setCurrentSource("manual ROI")
self.qapp.processEvents()
self.widget.setROI(start_x=0, end_x=10, start_y=0, end_y=10)
self.qapp.processEvents()
......@@ -169,7 +171,10 @@ class TestProcessing(TestCaseQt):
)
# insure a normalization has been registered
self.assertTrue(
self.scan_3.intensity_normalization.tomwer_processing_res_code, True
self.scan_3.intensity_normalization.get_extra_infos().get(
"tomwer_processing_res_code"
),
True,
)
def testTestLbsram(self):
......
......@@ -101,21 +101,6 @@ class NormIntensityWindow(_NormIntensityWindow):
self._processingThread.start()
def _threadedProcessEnded(self):
logging.getLogger("tomoscan.normalization").setLevel(logging.DEBUG)
try:
self.setResult(str(self._processingThread.result))
from tomoscan.normalization import Method
# all processing are converted to tomoscan "SCALAR method"
self.getScan().intensity_normalization.method = Method.SCALAR
self.getScan().intensity_normalization.set_extra_infos(
{
"value": self._processingThread.result,
}
)
except Exception as e:
_logger.error(e)
qt.QApplication.restoreOverrideCursor()
def close(self) -> None:
......
......@@ -171,7 +171,9 @@ def test_normalization(norm_setting, expected_nabu_conf, tmp_path):
# insure the method is style valid
assert scan.intensity_normalization.method.value == norm_setting.method
assert hasattr(scan.intensity_normalization, "tomwer_processing_res_code")
assert (
"tomwer_processing_res_code" in scan.intensity_normalization.get_extra_infos()
)
process = NabuSlices(
inputs={
......@@ -195,4 +197,6 @@ def test_normalization(norm_setting, expected_nabu_conf, tmp_path):
assert url.is_valid()
else:
assert sino_normalization_file == ""
assert hasattr(scan.intensity_normalization, "tomwer_processing_res_code")
assert (
"tomwer_processing_res_code" in scan.intensity_normalization.get_extra_infos()
)
......@@ -42,6 +42,7 @@ from .params import (
_ValueCalculationFct,
_ValueSource,
)
from tomoscan.normalization import Method as NormMethod
from processview.core.superviseprocess import SuperviseProcess
from silx.io.url import DataUrl
from silx.io.utils import get_data
......@@ -99,13 +100,21 @@ class IntensityNormalizationTask(
scan = self.inputs.data
if scan is None:
return
scan.intensity_normalization.tomwer_processing_res_code = None
extra_infos = scan.intensity_normalization.get_extra_infos()
extra_infos.update(
{
"tomwer_processing_res_code": None,
}
)
scan.intensity_normalization.set_extra_infos(extra_infos)
params = IntensityNormalizationParams.from_dict(self._settings)
# define the method used to the scan
scan.intensity_normalization.method = params.method
# after this processing the source
try:
if params.source is _ValueSource.MANUAL_ROI:
if params.method is NormMethod.NONE:
final_norm_info = {}
elif params.source is _ValueSource.MANUAL_ROI:
value = self._compute_from_manual_roi(scan)
# need_conversion_to_tomoscan = True
# insure this could be hashable (for caches)
......@@ -139,14 +148,10 @@ class IntensityNormalizationTask(
raise ValueError("method {} is not handled".format(params.method))
except Exception as e:
_logger.error(e)
tomwer_processing_res_code = False
final_norm_info = {}
final_norm_info = {"tomwer_processing_res_code": False}
else:
tomwer_processing_res_code = True
final_norm_info.update({"tomwer_processing_res_code": True})
scan.intensity_normalization.set_extra_infos(final_norm_info)
scan.intensity_normalization.tomwer_processing_res_code = (
tomwer_processing_res_code
)
self.outputs.data = scan
def _compute_from_manual_roi(self, scan):
......
......@@ -103,7 +103,9 @@ class TestNormalization(unittest.TestCase):
}
)
process.run()
res = process.results.intensity_normalization.tomwer_processing_res
res = self.scan.intensity_normalization.get_extra_infos().get(
"value"
)
if isinstance(res, numpy.ndarray):
numpy.testing.assert_array_equal(
res, expected_results[calc_fct][calc_method]
......
......@@ -147,8 +147,13 @@ class NormIntensityWindow(qt.QMainWindow):
# if the normed sinogram can be obtained `directly`
if source in (_ValueSource.MANUAL_SCALAR, _ValueSource.DATASET):
scan.intensity_normalization = self.getCurrentMethod().value
scan.intensity_normalization.set_extra_infos(self.getExtraArgs())
scan.intensity_normalization.tomwer_processing_res_code = True
extra_info = self.getExtraArgs()
extra_info.update(
{
"tomwer_processing_res_code": True,
}
)
scan.intensity_normalization.set_extra_infos(extra_info)
self._centralWidget._updateSinogramROI()
def getScan(self):
......@@ -179,12 +184,6 @@ class NormIntensityWindow(qt.QMainWindow):
)
def setResult(self, result):
# once computed update scan normalization values (
# update scalar value for example)
scan = self.getScan()
if scan and self.getCurrentMethod().value in Method.values():
scan.intensity_normalization = self.getCurrentMethod().value
scan.intensity_normalization.set_extra_infos(self.getExtraArgs())
self._crtWidget.setResult(result)
def clear(self):
......
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