From 75ad138d7f013d714c114c653bcc7c096a04c84a Mon Sep 17 00:00:00 2001 From: algol Date: Fri, 26 Jun 2026 17:56:20 +0100 Subject: [PATCH 1/3] adding templates and supporting func for frame averager --- .../packages/backends/httomolibgpu/httomolibgpu.yaml | 9 +++++++++ .../httomolibgpu/supporting_funcs/misc/morph.py | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/httomo_backends/methods_database/packages/backends/httomolibgpu/httomolibgpu.yaml b/httomo_backends/methods_database/packages/backends/httomolibgpu/httomolibgpu.yaml index 1dbe824d..2e96a663 100644 --- a/httomo_backends/methods_database/packages/backends/httomolibgpu/httomolibgpu.yaml +++ b/httomo_backends/methods_database/packages/backends/httomolibgpu/httomolibgpu.yaml @@ -66,6 +66,15 @@ misc: memory_gpu: multiplier: None method: module + average_projection_frames: + pattern: sinogram + output_dims_change: True + implementation: gpu_cupy + save_result_default: False + padding: False + memory_gpu: + multiplier: 2.1 + method: direct rescale: rescale_to_int: pattern: all diff --git a/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/misc/morph.py b/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/misc/morph.py index 9b78eb27..4e31386a 100644 --- a/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/misc/morph.py +++ b/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/misc/morph.py @@ -25,13 +25,14 @@ from typing import Tuple import numpy as np -from httomolibgpu.misc.morph import data_resampler, sino_360_to_180 +from httomolibgpu.misc.morph import data_resampler, sino_360_to_180, average_projection_frames __all__ = [ "_calc_memory_bytes_data_resampler", "_calc_output_dim_data_resampler", "_calc_memory_bytes_sino_360_to_180", "_calc_output_dim_sino_360_to_180", + "_calc_output_dim_average_projection_frames", ] @@ -39,6 +40,15 @@ def _calc_output_dim_data_resampler(non_slice_dims_shape, **kwargs): return kwargs["newshape"] +def _calc_output_dim_average_projection_frames(non_slice_dims_shape, **kwargs): + k: float = kwargs["projection_averaging_factor"] + + n_proj = non_slice_dims_shape[0] + n_full = n_proj // k + remainder = n_proj % k + n_out = n_full + (remainder > 0) + return n_out, non_slice_dims_shape[1] + def _calc_memory_bytes_data_resampler( non_slice_dims_shape: Tuple[int, int], dtype: np.dtype, From 3f47ffb0baf85795148273ae32c35d69df043dac Mon Sep 17 00:00:00 2001 From: dkazanc Date: Wed, 8 Jul 2026 13:48:21 +0100 Subject: [PATCH 2/3] adding angles averaging directive --- .../angles_averaging_directive.yaml | 20 +++++++++++++++++++ .../scripts/yaml_pipelines_generator.py | 7 +++++++ 2 files changed, 27 insertions(+) create mode 100644 httomo_backends/pipelines_full/angles_averaging_directive.yaml diff --git a/httomo_backends/pipelines_full/angles_averaging_directive.yaml b/httomo_backends/pipelines_full/angles_averaging_directive.yaml new file mode 100644 index 00000000..bfe4df51 --- /dev/null +++ b/httomo_backends/pipelines_full/angles_averaging_directive.yaml @@ -0,0 +1,20 @@ +- method: standard_tomo + module_path: httomo.data.hdf.loaders +- method: remove_outlier + module_path: httomolibgpu.misc.corr +- method: dark_flat_field_correction + module_path: httomolibgpu.prep.normalize +- method: find_center_vo + module_path: httomolibgpu.recon.rotation +- method: average_projection_frames + module_path: httomolibgpu.misc.morph +- method: minus_log + module_path: httomolibgpu.prep.normalize +- method: LPRec3d_tomobar + module_path: httomolibgpu.recon.algorithm +- method: calculate_stats + module_path: httomo.methods +- method: rescale_to_int + module_path: httomolib.misc.rescale +- method: save_to_images + module_path: httomolib.misc.images diff --git a/httomo_backends/scripts/yaml_pipelines_generator.py b/httomo_backends/scripts/yaml_pipelines_generator.py index ecf6f43f..c1c2b378 100644 --- a/httomo_backends/scripts/yaml_pipelines_generator.py +++ b/httomo_backends/scripts/yaml_pipelines_generator.py @@ -221,6 +221,13 @@ def yaml_pipelines_generator( key="path_to_stiched_params_file", comment="Provide an absolute path to the text file with seam index and blending width.", ) + elif "average_projection_frames" in method_name: + pipeline_full.yaml_set_comment_before_after_key( + i, + "--- Apply averaging of projection data in the angular dimension. --- ", + indent=0, + ) + pipeline_full += yaml_template_method elif "data_resampler" in method_name: pipeline_full.yaml_set_comment_before_after_key( i, From cb65a015b9fbb884543e570ac81a6102812fc63e Mon Sep 17 00:00:00 2001 From: dkazanc Date: Wed, 8 Jul 2026 13:49:26 +0100 Subject: [PATCH 3/3] linting --- .../httomolibgpu/supporting_funcs/misc/morph.py | 9 +++++++-- .../httomolibgpu/supporting_funcs/recon/algorithm.py | 12 +++++------- httomo_backends/scripts/yaml_pipelines_generator.py | 2 +- tests/test_httomolibgpu.py | 1 + 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/misc/morph.py b/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/misc/morph.py index 4e31386a..20c95b39 100644 --- a/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/misc/morph.py +++ b/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/misc/morph.py @@ -25,7 +25,11 @@ from typing import Tuple import numpy as np -from httomolibgpu.misc.morph import data_resampler, sino_360_to_180, average_projection_frames +from httomolibgpu.misc.morph import ( + data_resampler, + sino_360_to_180, + average_projection_frames, +) __all__ = [ "_calc_memory_bytes_data_resampler", @@ -46,9 +50,10 @@ def _calc_output_dim_average_projection_frames(non_slice_dims_shape, **kwargs): n_proj = non_slice_dims_shape[0] n_full = n_proj // k remainder = n_proj % k - n_out = n_full + (remainder > 0) + n_out = n_full + (remainder > 0) return n_out, non_slice_dims_shape[1] + def _calc_memory_bytes_data_resampler( non_slice_dims_shape: Tuple[int, int], dtype: np.dtype, diff --git a/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/recon/algorithm.py b/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/recon/algorithm.py index 6d7afb48..ac788083 100644 --- a/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/recon/algorithm.py +++ b/httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/recon/algorithm.py @@ -43,7 +43,7 @@ "_calc_output_dim_CGLS3d_tomobar", "_calc_output_dim_FISTA3d_tomobar", "_calc_output_dim_ADMM3d_tomobar", - "_calc_output_dim_OSEM3d_tomobar", + "_calc_output_dim_OSEM3d_tomobar", "_calc_padding_FISTA3d_tomobar", "_calc_padding_ADMM3d_tomobar", "_calc_padding_OSEM3d_tomobar", @@ -57,6 +57,7 @@ def _calc_padding_FISTA3d_tomobar(**kwargs) -> Tuple[int, int]: def _calc_padding_ADMM3d_tomobar(**kwargs) -> Tuple[int, int]: return (5, 5) + def _calc_padding_OSEM3d_tomobar(**kwargs) -> Tuple[int, int]: return (5, 5) @@ -106,6 +107,7 @@ def _calc_output_dim_ADMM3d_tomobar(non_slice_dims_shape, **kwargs): def _calc_output_dim_OSEM3d_tomobar(non_slice_dims_shape, **kwargs): return __calc_output_dim_recon(non_slice_dims_shape, **kwargs) + def _calc_memory_bytes_FBP3d_tomobar( non_slice_dims_shape: Tuple[int, int], dtype: np.dtype, @@ -668,18 +670,14 @@ def _calc_memory_bytes_OSEM3d_tomobar( backproj = out_data_size mlem_part = ( - recon_data_size_original - + normalisation - + Ax - + ratio - + backproj - + out_data_size + recon_data_size_original + normalisation + Ax + ratio + backproj + out_data_size ) regul_part = 8 * np.prod(output_dims_larger_grid) * dtype.itemsize tot_memory_bytes = int(mlem_part + regul_part) return (tot_memory_bytes, 0) + def _calc_memory_bytes_ADMM3d_tomobar( non_slice_dims_shape: Tuple[int, int], dtype: np.dtype, diff --git a/httomo_backends/scripts/yaml_pipelines_generator.py b/httomo_backends/scripts/yaml_pipelines_generator.py index c1c2b378..efe059d5 100644 --- a/httomo_backends/scripts/yaml_pipelines_generator.py +++ b/httomo_backends/scripts/yaml_pipelines_generator.py @@ -227,7 +227,7 @@ def yaml_pipelines_generator( "--- Apply averaging of projection data in the angular dimension. --- ", indent=0, ) - pipeline_full += yaml_template_method + pipeline_full += yaml_template_method elif "data_resampler" in method_name: pipeline_full.yaml_set_comment_before_after_key( i, diff --git a/tests/test_httomolibgpu.py b/tests/test_httomolibgpu.py index 8e1395a9..f25ec59c 100644 --- a/tests/test_httomolibgpu.py +++ b/tests/test_httomolibgpu.py @@ -1059,6 +1059,7 @@ def test_recon_MLEM3d_tomobar_nonOS_memoryhook( assert estimated_memory_mb >= max_mem_mb assert percents_relative_maxmem <= 100 + @pytest.mark.cupy @pytest.mark.parametrize("slices", [3, 5]) @pytest.mark.parametrize("recon_size_it", [2560])