Skip to content

Commit

Permalink
Merge pull request #154 from tjgalvin/wscleandivergence
Browse files Browse the repository at this point in the history
Detect and retry wsclean divergence error
  • Loading branch information
tjgalvin authored Jul 30, 2024
2 parents 968ba7e + 5f99596 commit a8230ec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- the strategy format now has a `operations` set of keywords, including `stokesv` to drawn options from
- naming format of output linmos files could contain the pol field
- `stokesv` imaging will not linmos the cleaning residuals together, even if the `--linmos-residuals` CLI is provided
- Capture `CleanDivergenceError` from `wsclean` and rerun with larger image size and lower gain

# 0.2.5
- added in skip rounds for masking and selfcal
Expand Down
42 changes: 37 additions & 5 deletions flint/prefect/common/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ def task_wsclean_imager(
Returns:
WSCleanCommand: A resulting wsclean command and resulting meta-data
"""
from flint.exceptions import CleanDivergenceError

ms = in_ms if isinstance(in_ms, MS) else in_ms.ms

update_wsclean_options = (
Expand All @@ -286,11 +288,41 @@ def task_wsclean_imager(
update_wsclean_options["fits_mask"] = fits_mask.mask_fits

logger.info(f"wsclean inager {ms=}")
return wsclean_imager(
ms=ms,
wsclean_container=wsclean_container,
update_wsclean_options=update_wsclean_options,
)
try:
return wsclean_imager(
ms=ms,
wsclean_container=wsclean_container,
update_wsclean_options=update_wsclean_options,
)
except CleanDivergenceError:
# NOTE: If the cleaning failed retry with some larger images
# and slower cleaning. Perhaps this should be moved closer
# to the wscleaning functionality
size = (
update_wsclean_options["size"] + 1024
if "size" in update_wsclean_options
else 8196
)
mgain = (
max(0, update_wsclean_options["mgain"] - 0.1)
if "mgain" in update_wsclean_options
else 0.6
)
convergence_wsclean_options = dict(size=size, mgain=mgain)
# dicts are mutable. Don't want to change for everything. Unclear to me
# how prefect would behave here.
update_wsclean_options = update_wsclean_options.copy().update(
**convergence_wsclean_options
)
logger.warn(
f"Clean divergence dertected. Reruning. Updated options {convergence_wsclean_options=}"
)

return wsclean_imager(
ms=ms,
wsclean_container=wsclean_container,
update_wsclean_options=update_wsclean_options,
)


@task
Expand Down

0 comments on commit a8230ec

Please sign in to comment.