From 26cbebfb8026f0cc9672016438846d1f32276460 Mon Sep 17 00:00:00 2001 From: algol Date: Thu, 28 May 2026 16:03:54 +0100 Subject: [PATCH 1/3] adds a possibility of running find_center from tomopy --- httomo/method_wrappers/rotation.py | 4 ++++ httomo/runner/task_runner.py | 1 + 2 files changed, 5 insertions(+) diff --git a/httomo/method_wrappers/rotation.py b/httomo/method_wrappers/rotation.py index 172b27af3..7fde86eeb 100644 --- a/httomo/method_wrappers/rotation.py +++ b/httomo/method_wrappers/rotation.py @@ -75,6 +75,8 @@ def _build_kwargs( updated_params = {**dict_params, "ind": (dataset.shape[1] - 1) // 2} if "average_radius" not in dict_params: updated_params.update({"average_radius": 0}) + if self.method_name == "find_center": + updated_params.update({"theta": dataset.angles_radians}) return super()._build_kwargs(updated_params, dataset) def _gather_sino_slice(self, global_shape: Tuple[int, int, int]): @@ -213,6 +215,8 @@ def _run_method(self, block: T, args: Dict[str, Any]) -> T: args["ind"] = 0 args[self.parameters[0]] = sino_slice[:, xp.newaxis, :] res = self.method(**args) + if isinstance(res, np.ndarray): + res = res[0] # and broadcast if self.comm.size > 1: res = self.comm.bcast(res, root=0) diff --git a/httomo/runner/task_runner.py b/httomo/runner/task_runner.py index 7af8dbdb6..80aade769 100644 --- a/httomo/runner/task_runner.py +++ b/httomo/runner/task_runner.py @@ -312,6 +312,7 @@ def _get_methods_name_for_snapshot(self, section: Section) -> str: irrelevant_method_names_snapshots = [ "data_checker", "calculate_stats", + "find_center", "find_center_360", "find_center_pc", "find_center_vo", From 70d2c4fa82b0a3d5e6cb6e52222a1f6b719442c4 Mon Sep 17 00:00:00 2001 From: algol Date: Thu, 28 May 2026 16:12:11 +0100 Subject: [PATCH 2/3] cleanup small tests --- tests/test_pipeline_small.py | 164 +---------------------------------- 1 file changed, 1 insertion(+), 163 deletions(-) diff --git a/tests/test_pipeline_small.py b/tests/test_pipeline_small.py index 88c6bc5d3..9e092d9fe 100644 --- a/tests/test_pipeline_small.py +++ b/tests/test_pipeline_small.py @@ -6,7 +6,6 @@ import numpy as np import pytest from numpy.testing import assert_allclose -from PIL import Image from plumbum import local from .conftest import change_value_parameters_method_pipeline, check_tif @@ -163,165 +162,4 @@ def test_run_pipeline_FBP3d_tomobar_denoising( assert "Preview: (0:180, 0:128, 0:160)" in verbose_log_contents assert "Data shape is (180, 128, 160) of type uint16" in verbose_log_contents assert "The amount of the available GPU memory is" in verbose_log_contents - assert "Using GPU 0 to transfer data of shape" in verbose_log_contents - - -# TODO: rewrite and move to test_pipeline_big -# @pytest.mark.small_data -# def test_tomo_standard_testing_pipeline_output_with_save_all( -# get_files: Callable, -# cmd, -# standard_data, -# standard_loader, -# testing_pipeline, -# output_folder, -# merge_yamls, -# ): -# cmd.insert(7, standard_data) -# merge_yamls(standard_loader, testing_pipeline) -# cmd.insert(8, "temp.yaml") -# cmd.insert(9, output_folder) -# subprocess.check_output(cmd) - -# files = get_files("output_dir/") -# assert len(files) == 11 - -# _check_yaml(files, "temp.yaml") -# _check_tif(files, 3, (160, 160)) - -# #: check the generated h5 files -# h5_files = list(filter(lambda x: ".h5" in x, files)) -# assert len(h5_files) == 5 - -# for file_to_open in h5_files: -# if "tomopy-recon-tomo-gridrec.h5" in file_to_open: -# with h5py.File(file_to_open, "r") as f: -# assert f["data"].shape == (160, 3, 160) -# assert f["data"].dtype == np.float32 -# assert_allclose(np.mean(f["data"]), 0.0015362317, atol=1e-6, rtol=1e-6) -# assert_allclose(np.sum(f["data"]), 117.9826, atol=1e-6, rtol=1e-6) - - -# TODO: we will be testing this in test_pipeline_big -# def test_i12_testing_pipeline_output( -# get_files: Callable, -# cmd, -# i12_data, -# i12_loader, -# testing_pipeline, -# output_folder, -# merge_yamls, -# ): -# cmd.insert(7, i12_data) -# merge_yamls(i12_loader, testing_pipeline) -# cmd.insert(8, "temp.yaml") -# cmd.insert(9, output_folder) -# subprocess.check_output(cmd) - -# files = get_files("output_dir/") -# assert len(files) == 18 - -# _check_yaml(files, "temp.yaml") - -# log_files = list(filter(lambda x: ".log" in x, files)) -# assert len(log_files) == 2 - -# tif_files = list(filter(lambda x: ".tif" in x, files)) -# assert len(tif_files) == 10 - -# h5_files = list(filter(lambda x: ".h5" in x, files)) -# assert len(h5_files) == 5 - -# gridrec_recon = list(filter(lambda x: "recon-gridrec.h5" in x, h5_files))[0] -# minus_log_tomo = list(filter(lambda x: "minus_log.h5" in x, h5_files))[0] -# remove_stripe_fw_tomo = list( -# filter(lambda x: "remove_stripe_fw.h5" in x, h5_files) -# )[0] -# normalize_tomo = list(filter(lambda x: "normalize.h5" in x, h5_files))[0] - -# with h5py.File(gridrec_recon, "r") as f: -# assert f["data"].shape == (192, 10, 192) -# assert_allclose(np.sum(f["data"]), 2157.03, atol=1e-2, rtol=1e-6) -# assert_allclose(np.mean(f["data"]), 0.0058513316, atol=1e-6, rtol=1e-6) -# with h5py.File(minus_log_tomo, "r") as f: -# assert_allclose(np.sum(f["data"]), 1756628.4, atol=1e-6, rtol=1e-6) -# assert_allclose(np.mean(f["data"]), 1.2636887, atol=1e-6, rtol=1e-6) -# with h5py.File(remove_stripe_fw_tomo, "r") as f: -# assert_allclose(np.sum(f["data"]), 1766357.8, atol=1e-6, rtol=1e-6) -# assert_allclose(np.mean(f["data"]), 1.2706878, atol=1e-6, rtol=1e-6) -# with h5py.File(normalize_tomo, "r") as f: -# assert f["data"].shape == (724, 10, 192) -# assert_allclose(np.sum(f["data"]), 393510.72, atol=1e-6, rtol=1e-6) -# assert_allclose(np.mean(f["data"]), 0.28308493, atol=1e-6, rtol=1e-6) - -# concise_log_file = list(filter(lambda x: "user.log" in x, files)) -# concise_log_contents = _get_log_contents(concise_log_file[0]) -# verbose_log_file = list(filter(lambda x: "debug.log" in x, files)) -# verbose_log_contents = _get_log_contents(verbose_log_file[0]) - -# assert "The center of rotation is 95.5" in concise_log_contents -# assert "The full dataset shape is (724, 10, 192)" in verbose_log_contents -# assert ( -# "Loading data: tests/test_data/i12/separate_flats_darks/i12_dynamic_start_stop180.nxs" -# in verbose_log_contents -# ) -# assert "Path to data: /1-TempPlugin-tomo/data" in verbose_log_contents -# assert "Preview: (0:724, 0:10, 0:192)" in verbose_log_contents - - -# TODO: Will be added to big-data tests when the sample data with separate darks and flats will be available. -# @pytest.mark.small_data -# def test_i12_testing_ignore_darks_flats_pipeline_output( -# get_files: Callable, -# cmd, -# i12_data, -# i12_loader_ignore_darks_flats, -# testing_pipeline, -# output_folder, -# merge_yamls, -# ): -# cmd.insert(7, i12_data) -# merge_yamls(i12_loader_ignore_darks_flats, testing_pipeline) -# cmd.insert(8, "temp.yaml") -# cmd.insert(9, output_folder) -# subprocess.check_output(cmd) - -# files = get_files("output_dir/") -# assert len(files) == 16 - -# _check_yaml(files, "temp.yaml") - -# log_files = list(filter(lambda x: ".log" in x, files)) -# assert len(log_files) == 1 - -# tif_files = list(filter(lambda x: ".tif" in x, files)) -# assert len(tif_files) == 10 - -# h5_files = list(filter(lambda x: ".h5" in x, files)) -# assert len(h5_files) == 4 - -# log_contents = _get_log_contents(log_files[0]) -# assert "The full dataset shape is (724, 10, 192)" in log_contents -# assert ( -# "Loading data: tests/test_data/i12/separate_flats_darks/i12_dynamic_start_stop180.nxs" -# in log_contents -# ) -# assert "Path to data: /1-TempPlugin-tomo/data" in log_contents -# assert "Preview: (0:724, 0:10, 0:192)" in log_contents -# assert ( -# "Running save_task_1 (pattern=projection): save_intermediate_data..." -# in log_contents -# ) -# assert ( -# "Running save_task_2 (pattern=projection): save_intermediate_data..." -# in log_contents -# ) -# assert ( -# "Running save_task_4 (pattern=sinogram): save_intermediate_data..." -# in log_contents -# ) -# assert "The center of rotation for sinogram is 95.5" in log_contents -# assert ( -# "Running save_task_5 (pattern=sinogram): save_intermediate_data..." -# in log_contents -# ) + assert "Using GPU 0 to transfer data of shape" in verbose_log_contents \ No newline at end of file From 86c4fad68982e94c2faeeb216ee198e74d7b3a2b Mon Sep 17 00:00:00 2001 From: algol Date: Thu, 28 May 2026 17:05:16 +0100 Subject: [PATCH 3/3] linting --- tests/test_pipeline_small.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pipeline_small.py b/tests/test_pipeline_small.py index 9e092d9fe..ef7d2a8e8 100644 --- a/tests/test_pipeline_small.py +++ b/tests/test_pipeline_small.py @@ -162,4 +162,4 @@ def test_run_pipeline_FBP3d_tomobar_denoising( assert "Preview: (0:180, 0:128, 0:160)" in verbose_log_contents assert "Data shape is (180, 128, 160) of type uint16" in verbose_log_contents assert "The amount of the available GPU memory is" in verbose_log_contents - assert "Using GPU 0 to transfer data of shape" in verbose_log_contents \ No newline at end of file + assert "Using GPU 0 to transfer data of shape" in verbose_log_contents