Skip to content

Commit

Permalink
Auto-insert rescaler with image saver in sweep pipeline
Browse files Browse the repository at this point in the history
The `save_to_images` method no longer provides rescaling of the input
data. This means that auto-insertion of the image saver method also
requires auto-insertion of the rescaler method before the image saver,
in order to rescale the data before it's passed to the image saver.
  • Loading branch information
yousefmoazzam committed Oct 1, 2024
1 parent 6030435 commit e20c553
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
19 changes: 16 additions & 3 deletions httomo/transform_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
43 changes: 29 additions & 14 deletions tests/test_transform_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit e20c553

Please sign in to comment.