From 100906b5849c7cff8a06a73dad24ab917bae0881 Mon Sep 17 00:00:00 2001 From: Thomas Williams <32936518+thomaswilliamsastro@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:20:47 +0000 Subject: [PATCH] Expose the max_loops parameter Fixes #423 Exposes the `max_loops` parameter used in imaging at the Imaging/ChunkedImaging handler level. Sometimes this needs to be tuned up for bright targets, and was hardcoded. By defaults, stays at the value of 20 we were using before --- CHANGELOG.md | 1 + phangsPipeline/handlerImaging.py | 14 ++++++++++++-- phangsPipeline/handlerImagingChunked.py | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 296a654..60a1ef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added support for gridding multiple singledish mosaics in the singledish pipeline (#414). - Set `singlescale_mask_absolute=True` as the default in imaging, reflecting actual imaging usage. (#418). - Add optional tests to check if cube channels are noise only, and if so to mask them out (#399). +- Expose ``max_loops`` for multiscale and singlescale clean in ``loop_imaging`` and chunked ``run_imaging`` (#428). ### Changed diff --git a/phangsPipeline/handlerImaging.py b/phangsPipeline/handlerImaging.py index cfa9471..5a8a1c2 100644 --- a/phangsPipeline/handlerImaging.py +++ b/phangsPipeline/handlerImaging.py @@ -173,6 +173,7 @@ def loop_imaging( convergence_noise_z_threshold=None, channel_noise_sigma_threshold=None, singlescale_threshold_value=1.0, + max_loops=20, extra_ext_in=None, suffix_in=None, extra_ext_out=None, @@ -242,6 +243,9 @@ def loop_imaging( greater than 2.0. singlescale_threshold_value : float Threshold value for singlescale clean. Default is 1.0. + max_loops : int + Maximum number of clean loops for the multiscale and singlescale + clean stages. Default is 20. extra_ext_in : str Extra extension for input files. suffix_in : str @@ -378,6 +382,7 @@ def loop_imaging( convergence_noise_z_threshold=convergence_noise_z_threshold, channel_noise_sigma_threshold=channel_noise_sigma_threshold, singlescale_threshold_value=singlescale_threshold_value, + max_loops=max_loops, dynamic_sizing=dynamic_sizing, force_square=force_square, export_dirty=export_dirty, @@ -853,6 +858,7 @@ def task_multiscale_clean( imaging_method='tclean', convergence_fracflux=0.01, convergence_noise_z_threshold=None, + max_loops=20, backup=True, ): """ @@ -895,7 +901,7 @@ def task_multiscale_clean( threshold_type='snr', threshold_value=4.0, min_loops=3, - max_loops=20, + max_loops=max_loops, max_total_niter=None, convergence_fracflux=convergence_fracflux, convergence_totalflux=None, @@ -1083,6 +1089,7 @@ def task_singlescale_clean( convergence_fracflux=0.01, threshold_value=1.0, convergence_noise_z_threshold=None, + max_loops=20, backup=True, ): """ @@ -1125,7 +1132,7 @@ def task_singlescale_clean( threshold_type='snr', threshold_value=threshold_value, min_loops=3, - max_loops=20, + max_loops=max_loops, max_total_niter=None, convergence_fracflux=convergence_fracflux, convergence_totalflux=None, @@ -1207,6 +1214,7 @@ def recipe_phangsalma_imaging( convergence_noise_z_threshold=None, channel_noise_sigma_threshold=None, singlescale_threshold_value=1.0, + max_loops=20, dynamic_sizing=True, force_square=False, export_dirty=False, @@ -1415,6 +1423,7 @@ def recipe_phangsalma_imaging( imaging_method=imaging_method, convergence_fracflux=convergence_fracflux, convergence_noise_z_threshold=convergence_noise_z_threshold, + max_loops=max_loops, ) if do_export_to_fits and export_multiscale: @@ -1473,6 +1482,7 @@ def recipe_phangsalma_imaging( convergence_fracflux=convergence_fracflux, convergence_noise_z_threshold=convergence_noise_z_threshold, threshold_value=singlescale_threshold_value, + max_loops=max_loops, ) # Reset the current imaging to the results of the singlescale clean. diff --git a/phangsPipeline/handlerImagingChunked.py b/phangsPipeline/handlerImagingChunked.py index 3565062..b6e38cf 100644 --- a/phangsPipeline/handlerImagingChunked.py +++ b/phangsPipeline/handlerImagingChunked.py @@ -341,6 +341,7 @@ def run_imaging( convergence_noise_z_threshold=None, singlescale_threshold_value=1.0, channel_noise_sigma_threshold=None, + max_loops=20, extra_ext_in=None, suffix_in=None, extra_ext_out=None, @@ -403,6 +404,9 @@ def run_imaging( channel_noise_sigma_threshold : float Threshold value for defining a channel as purely noise. Default is None, which will not perform this check. + max_loops : int + Maximum number of clean loops for the multiscale and singlescale + clean stages. Default is 20. extra_ext_in : str Extra extension for input files. suffix_in : str @@ -492,6 +496,7 @@ def run_imaging( convergence_noise_z_threshold=convergence_noise_z_threshold, channel_noise_sigma_threshold=channel_noise_sigma_threshold, singlescale_threshold_value=singlescale_threshold_value, + max_loops=max_loops, dynamic_sizing=dynamic_sizing, force_square=force_square, overwrite=overwrite, @@ -1231,6 +1236,7 @@ def task_multiscale_clean( convergence_fracflux=0.01, convergence_noise_z_threshold=None, channel_noise_sigma_threshold=None, + max_loops=20, backup=True, gather_chunks_into_cube=False, remove_chunks=False, @@ -1322,7 +1328,7 @@ def task_multiscale_clean( threshold_type='snr', threshold_value=4.0, min_loops=3, - max_loops=20, + max_loops=max_loops, max_total_niter=None, convergence_fracflux=convergence_fracflux, convergence_totalflux=None, @@ -1520,6 +1526,7 @@ def task_singlescale_clean( remove_chunks=False, threshold_value=1.0, skip_singlescale_if_mask_empty=True, + max_loops=20, backup=True, ): """ @@ -1607,7 +1614,7 @@ def task_singlescale_clean( threshold_type='snr', threshold_value=threshold_value, min_loops=3, - max_loops=20, + max_loops=max_loops, max_total_niter=None, convergence_fracflux=convergence_fracflux, convergence_totalflux=None, @@ -1768,6 +1775,7 @@ def recipe_phangsalma_imaging( convergence_noise_z_threshold=None, channel_noise_sigma_threshold=None, singlescale_threshold_value=1.0, + max_loops=20, dynamic_sizing=True, force_square=False, export_multiscale=False, @@ -1853,6 +1861,7 @@ def recipe_phangsalma_imaging( convergence_noise_z_threshold=convergence_noise_z_threshold, channel_noise_sigma_threshold=channel_noise_sigma_threshold, skip_multiscale_if_mask_empty=skip_multiscale_if_mask_empty, + max_loops=max_loops, gather_chunks_into_cube=False, ) @@ -1875,6 +1884,7 @@ def recipe_phangsalma_imaging( convergence_noise_z_threshold=convergence_noise_z_threshold, threshold_value=singlescale_threshold_value, skip_singlescale_if_mask_empty=skip_singlescale_if_mask_empty, + max_loops=max_loops, gather_chunks_into_cube=False) # Reset the current imaging to the results of the singlescale clean.