Imaging API¶
SerialImager¶
Serial synthesis imager – the single-process imaging engine.
Wraps the four CASA synthesis C++ tools (synthesisimager,
synthesisdeconvolver, synthesisnormalizer, iterbotsink)
into a clean Python lifecycle that can be driven standalone or
by the Dask-parallel engines.
Public API:
SerialImager(config)
.setup() -- wires up all C++ tools
.make_psf() -- compute PSF
.make_pb() -- compute primary beam
.run_major_cycle() -- one major cycle (grid / degrid)
.run_minor_cycle() -- one round of deconvolution
.has_converged() -- check convergence
.restore() -- restore images
.pbcor() -- PB-correct images
.teardown() -- release tools
.run() -- full end-to-end pipeline
- class pclean.imaging.serial_imager.SerialImager(config, init_iter_control=True)[source]¶
Bases:
objectSingle-process CLEAN imaging pipeline.
- Parameters:
config (PcleanConfig) – Validated hierarchical configuration.
init_iter_control (bool) – Whether to create an
iterbotsinktool. Set toFalsewhen this imager is driven externally (e.g. by a Dask coordinator that manages convergence itself).
- teardown()[source]¶
Release all C++ tool resources.
The CASA C++
table::done()internally callstable::name()forLogOrigin, which emits a spuriousINFO name:: No table opened.message for every internal table reference that was already closed. We usecasalog.filterMsgto suppress this specific message during teardown, then clear the filter list afterwards.- Return type:
None
- run_major_cycle(is_first=False)[source]¶
Execute one major cycle.
- Parameters:
is_first (bool) – If
Truethis is the initial residual computation (model is zero).- Return type:
None
- run_minor_cycle()[source]¶
Execute one round of minor-cycle deconvolution on all fields.
- Returns:
Trueif iterations were performed.- Return type:
- has_converged(nmajor_limit=-1)[source]¶
Check convergence (peak residual, niter, threshold …).
Calls
initminorcycleinternally (idempotent if already called via_init_minor_cycle()) then evaluatescleanComplete.
Deconvolver¶
Deconvolution wrapper.
Provides a standalone Deconvolver class that can be used
independently of the full imaging pipeline – for example when
the residual / PSF already exist on disk and only minor-cycle
deconvolution is needed.
- class pclean.imaging.deconvolver.Deconvolver(imagename, decpars, iterpars=None)[source]¶
Bases:
objectThin wrapper around
synthesisdeconvolver.- Parameters:
Normalizer¶
Image normalizer wrapper.
Provides a standalone Normalizer class that handles the
gather / scatter / divide-by-weight operations required for
both serial and parallel imaging.
- class pclean.imaging.normalizer.Normalizer(normpars, partimagenames=None)[source]¶
Bases:
objectWrapper around
synthesisnormalizer.In parallel continuum mode the normalizer gathers partial images produced by different workers, divides by weight, and scatters the model back.
- Parameters:
Auto-Masking¶
Pure-numpy auto-multithresh masking.
Re-implements CASA’s SDMaskHandler::autoMaskByMultiThreshold algorithm
using numpy/scipy, eliminating:
Repeated full-cube copy to TempImage
Per-plane TempImage allocations (~8 per chan per iteration)
casacore TableCache interactions (mask0 subtable bug)
Multiple statistics passes
The algorithm faithfully reproduces the six stages of the C++ implementation: threshold → prune → smooth → grow → combine → negative mask.
- Memory optimisation notes:
All intermediate masks use
np.bool_(1 byte/pixel) instead offloat32(4 bytes/pixel), giving a 4× footprint reduction on mask arrays. Only the final mask returned to the caller is float32 (CASA image format).AutoMaskState.posmaskand.prevmaskare stored asbool_between iterations. Whenpbis None no PB-mask array is allocated at all (pb_mask = Nonesentinel).
References
SDMaskHandler.cc autoMaskByMultiThreshold() (CASA 6.x)
Kepley et al. 2020, PASP 132, 024505
- class pclean.imaging.automask.AutoMaskConfig(sidelobethreshold=3.0, noisethreshold=5.0, lownoisethreshold=1.5, negativethreshold=0.0, smoothfactor=1.0, minbeamfrac=0.3, cutthreshold=0.01, growiterations=100, dogrowprune=True, minpercentchange=0.0, fastnoise=True)[source]¶
Bases:
objectParameters mirroring CASA’s auto-multithresh knobs.
Defaults match CASA’s
tcleandefaults.- Parameters:
- class pclean.imaging.automask.AutoMaskState(posmask=None, prevmask=None, iteration=0, skip=False)[source]¶
Bases:
objectMutable state carried across major-cycle iterations.
The C++ implementation keeps
posmaskandprevmaskinsideSIImageStore. Here we keep lightweight numpy arrays per channel so the Python caller can stash them between cycles.- Parameters:
- pclean.imaging.automask.automask_plane(residual, sidelobe_level, beam_area_pix, beam_sigma_pix, cfg, state, pb=None, pblimit=0.2, beam_pa_rad=0.0)[source]¶
Compute the auto-multithresh mask for a single 2-D plane.
This is the numpy equivalent of
SDMaskHandler::autoMaskByMultiThresholdoperating on one (pol, chan) slice.- Memory strategy:
All intermediate masks are
np.bool_(1 byte/pixel).pb_maskisNonewhen no PB is provided (zero alloc).state.posmask/state.prevmaskstored asbool_.In-place
|=replacesnp.maximumchains.Only the final return value is cast to
float32for CASA I/O.
- Parameters:
residual (ndarray[tuple[Any, ...], dtype[float32]]) – 2-D residual image (float32).
sidelobe_level (float) – PSF sidelobe level (scalar, from
getPSFSidelobeLevel).beam_area_pix (float) – Restoring beam area in pixels.
beam_sigma_pix (tuple[float, float]) –
(sigma_major, sigma_minor)of the restoring beam in pixels (for Gaussian smoothing).cfg (AutoMaskConfig) – Automasking parameters.
state (AutoMaskState) – Mutable per-channel state (updated in-place).
pb (ndarray[tuple[Any, ...], dtype[float32]] | None) – Primary beam image (same shape as residual). If given, regions with
pb < pblimitare excluded.pblimit (float) – PB cutoff for the mask region.
beam_pa_rad (float) – Beam position angle in radians (East from North).
- Returns:
The updated binary mask (float32, 0/1).
- Return type:
- pclean.imaging.automask.beam_info_from_image(imagename)[source]¶
Read beam area, sidelobe level, sigma, and PA from a CASA image.