diff --git a/httomo/transform_layer.py b/httomo/transform_layer.py index 74bbe3c1c..4226cb07d 100644 --- a/httomo/transform_layer.py +++ b/httomo/transform_layer.py @@ -73,15 +73,28 @@ def insert_data_reducer(self, pipeline: Pipeline) -> Pipeline: return Pipeline(loader, methods) def insert_save_images_after_sweep(self, pipeline: Pipeline) -> Pipeline: - """For sweep methods we add image saving method after. - In addition we also add saving the results of the reconstruction, - if the module is present""" + """For sweep methods we add image saving method after, and also a rescaling method to + rescale the data passed to the image saver. In addition we also add saving the results + of the reconstruction, if the module is present""" loader = pipeline.loader methods = [] sweep_before = False for m in pipeline: methods.append(m) if m.sweep or "recon" in m.module_path and sweep_before: + methods.append( + make_method_wrapper( + self._repo, + "httomolibgpu.misc.rescale", + "rescale_to_int", + comm=self._comm, + save_result=False, + task_id=f"rescale_sweep_{m.task_id}", + perc_range_min=0.0, + perc_range_max=100.0, + bits=8, + ) + ) methods.append( make_method_wrapper( self._repo, diff --git a/tests/test_transform_layer.py b/tests/test_transform_layer.py index 296a68bb7..1f16ca12f 100644 --- a/tests/test_transform_layer.py +++ b/tests/test_transform_layer.py @@ -179,14 +179,19 @@ def test_insert_image_save_after_sweep(mocker: MockerFixture, tmp_path: Path): trans = TransformLayer(comm, repo=repo, save_all=False, out_dir=tmp_path) pipeline = trans.insert_save_images_after_sweep(pipeline) - assert len(pipeline) == 4 - assert pipeline[3].method_name == "save_to_images" - assert pipeline[3].task_id == "saveimage_sweep_t3" + assert len(pipeline) == 5 + assert pipeline[3].method_name == "rescale_to_int" + assert pipeline[3].task_id == "rescale_sweep_t3" + assert pipeline[3].config_params["perc_range_min"] == 0.0 + assert pipeline[3].config_params["perc_range_max"] == 100.0 + assert pipeline[3].config_params["bits"] == 8 + assert pipeline[4].method_name == "save_to_images" + assert pipeline[4].task_id == "saveimage_sweep_t3" assert ( - pipeline[3].config_params["subfolder_name"] + pipeline[4].config_params["subfolder_name"] == "images_sweep_paganin_filter_tomopy" ) - assert pipeline[3].config_params["axis"] == 1 + assert pipeline[4].config_params["axis"] == 1 def test_insert_image_save_after_sweep2(mocker: MockerFixture, tmp_path: Path): @@ -233,15 +238,25 @@ def test_insert_image_save_after_sweep2(mocker: MockerFixture, tmp_path: Path): trans = TransformLayer(comm, repo=repo, save_all=False, out_dir=tmp_path) pipeline = trans.insert_save_images_after_sweep(pipeline) - assert len(pipeline) == 6 - assert pipeline[3].method_name == "save_to_images" - assert pipeline[3].task_id == "saveimage_sweep_t3" + assert len(pipeline) == 8 + assert pipeline[3].method_name == "rescale_to_int" + assert pipeline[3].task_id == "rescale_sweep_t3" + assert pipeline[3].config_params["perc_range_min"] == 0.0 + assert pipeline[3].config_params["perc_range_max"] == 100.0 + assert pipeline[3].config_params["bits"] == 8 + assert pipeline[4].method_name == "save_to_images" + assert pipeline[4].task_id == "saveimage_sweep_t3" assert ( - pipeline[3].config_params["subfolder_name"] + pipeline[4].config_params["subfolder_name"] == "images_sweep_paganin_filter_tomopy" ) - assert pipeline[3].config_params["axis"] == 1 - assert pipeline[5].method_name == "save_to_images" - assert pipeline[5].task_id == "saveimage_sweep_t4" - assert pipeline[5].config_params["subfolder_name"] == "images_sweep_FBP" - assert pipeline[5].config_params["axis"] == 1 + + assert pipeline[6].method_name == "rescale_to_int" + assert pipeline[6].task_id == "rescale_sweep_t4" + assert pipeline[6].config_params["perc_range_min"] == 0.0 + assert pipeline[6].config_params["perc_range_max"] == 100.0 + assert pipeline[6].config_params["bits"] == 8 + assert pipeline[7].method_name == "save_to_images" + assert pipeline[7].task_id == "saveimage_sweep_t4" + assert pipeline[7].config_params["subfolder_name"] == "images_sweep_FBP" + assert pipeline[7].config_params["axis"] == 1