continunet.image
continunet.image.fits module
Models for pre-processing FITS image data.
continunet.image.processing module
Processing module for pre-processing input images and post-processing output images from the network.
- class continunet.image.processing.PostProcessor(reconstructed_image: ndarray, pre_processed_image: object, threshold, sigma_snr, rms_box, clean_maps)[source]
Bases:
objectPost-processes the output of the neural network, generating segmentation maps and source catalogues.
- calculate_area_correction_factor()[source]
Function to calculate the area correction factor for a given image.
- calculate_flux_errors(properties)[source]
Compute peak and integrated flux uncertainties and signal-to-noise ratios for a single radio source using the local RMS noise map.
This function follows standard radio-interferometric error propagation (e.g. Condon 1997) by estimating the noise on the peak flux from the local map RMS, and the noise on the integrated flux from the RMS scaled by the square root of the number of synthesized beams covered by the source.
- Parameters:
properties (pandas.Series) –
- A row from the source catalogue containing:
- coordsndarray of shape (N, 2)
Pixel coordinates belonging to the source segmentation region.
- max_intensityfloat
Peak pixel value of the source, in Jy/beam.
- image_intensityfloat
Integrated flux of the source in Jy, after any flux conversion or correction performed elsewhere in the pipeline.
- source_area_pixelsint
Number of pixels in the source region (used to compute the number of beams covered).
Assumptions
-----------
Jy/beam. (- The map intensities (max_intensity) and the RMS map are in units of)
flux (- image_intensity has already been converted to a true integrated)
correction (density in Jy (e.g. via pixel-area/beam-area scaling and any)
factor).
pixels. (- Beam area returned by self.get_beam_area() is in units of image)
- Returns:
n_beams (float) – Number of synthesized beams spanned by the source: area_pixels / beam_area.
sigma_integrated (float) – Uncertainty on the integrated flux density in Jy. Computed as: local_rms * sqrt(n_beams).
sigma_peak (float) – Uncertainty on the peak flux density in Jy/beam. Equal to the local RMS noise.
snr_peak (float) – Signal-to-noise ratio of the peak flux: peak_flux / local_rms.
snr_integrated (float) – Signal-to-noise ratio of the integrated flux: integrated_flux / sigma_integrated.
Notes
sigma_integrated follows the standard assumption that integrating over
N beams increases uncertainty as sqrt(N), appropriate for partially or fully resolved sources. - Using the median RMS within the segmentation region provides a robust local noise estimate even in presence of small-scale variations.
- static convert_orientation_to_position_angle(orientation)[source]
Convert the orientation of the source to position angle in degrees.
- correct_flux_densities(properties, predicted_map)[source]
Correct integrated fluxes for beam undersampling. Works only for compact sources (<~ few beam areas).
- estimate_noise_map(image, box_size=100, step_size=30, sigma=3.0, max_iters=5, mask=None)[source]
Estimate a spatially varying noise (RMS) map similar to PyBDSF.
- Parameters:
image (2D np.ndarray) – The input residual image (float).
box_size (int) – Size of the local box (in pixels) for RMS estimation.
step_size (int) – Step between box centers (in pixels). Controls sampling density.
sigma (float) – Sigma-clipping threshold (number of sigma to clip).
max_iters (int) – Maximum number of sigma-clipping iterations.
mask (2D np.ndarray, optional) – Boolean mask where True = ignore pixel (e.g., known sources).
- Returns:
rms_map (2D np.ndarray) – Interpolated local RMS (noise) map.
mean_map (2D np.ndarray) – Interpolated local mean (background) map.
- fast_noise_map(image, box_size=100, sigma=3, max_iters=3)[source]
Compute a fast, approximate spatially varying noise (RMS) and mean map using boxcar smoothing and optional iterative sigma-clipping.
This method provides a significantly faster alternative to full box-based noise estimation (e.g., PyBDSF-style tiling) by using uniform filters to compute local statistics over the entire image in one pass. The result is a smoothly varying estimate of the background mean and RMS.
- Parameters:
image (2D np.ndarray) – Input image from which to estimate local noise. Will be cast to float32 internally.
box_size (int, optional) – Size of the box (in pixels) used by the uniform filter when computing local means and variances. Larger values result in smoother noise/mean maps.
sigma (float, optional) – Sigma threshold for optional iterative sigma-clipping. Pixels deviating more than
sigma * rmsfrom the local mean are replaced with the mean before recomputing statistics.max_iters (int, optional) – Number of sigma-clipping iterations to perform. Set to zero to disable clipping entirely.
- Returns:
rms (2D np.ndarray) – Estimated spatially varying RMS (noise) map.
mean (2D np.ndarray) – Estimated spatially varying mean (background) map.
Notes
This method assumes noise varies slowly on scales larger than
box_size. - Sigma-clipping helps suppress bright sources but is approximate: clipping modifies the image iteratively rather than evaluating statistics in independent tiles. - This approach is best suited for applications where speed is more important than strict robustness to complex source structure.
- get_model_map(use_raw=False)[source]
Calculate the model map from the cleaned segmentation map and the input image. If use_raw is True, the raw sources are used to create the model map.
- get_residuals(use_raw=False)[source]
Calculate the residuals from the input image and the model map.
- get_segmentation_map()[source]
Calculate the segmentation map from the reconstructed image. Only binary segmentation maps are currently supported.