continunet.image

continunet.image.fits module

Models for pre-processing FITS image data.

class continunet.image.fits.FitsImage(path)[source]

Bases: ABC

Abstract model for an image imported from FITS format.

check_header()[source]

Check the header contains required information.

get_beam_size()[source]

Return the beam size in arcseconds.

load()[source]

Load fits image from file and populate model args.

class continunet.image.fits.ImageSquare(*args, **kwargs)[source]

Bases: FitsImage

Model for a 2D FITS image.

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: object

Post-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.

static calculate_ellipse_area(bmaj, bmin)[source]

Function to calculate the area of an ellipse.

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 * rms from 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.

generate_2d_gaussian_beam()[source]

Generate a 2D Gaussian beam for a given fits image.

generate_normalized_beam()[source]
get_beam_area()[source]

Returns the area of the Gaussian beam in pixels

get_beam_fwhm()[source]

Get FWHM of the beam in pixels from the fits header.

get_beam_size()[source]

Get sigma of the beam in pixels from the fits header.

get_labelled_map()[source]

Label the binary segmentation map.

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_nan_mask()[source]

Get mask for nan values (MIGHTEE specific)

get_raw_sources()[source]

Get the raw sources from the labelled map.

get_residuals(use_raw=False)[source]

Calculate the residuals from the input image and the model map.

get_rms_map(rms_box='default')[source]

Make RMS map using residual and model maps.

get_segmentation_map()[source]

Calculate the segmentation map from the reconstructed image. Only binary segmentation maps are currently supported.

get_source_mask(predicted_map, source, beam_shape)[source]

Get the mask of the source in the cutout.

get_sources()[source]

Clean the raw sources to produce a catalogue of sources.

static pad_to_target_shape(array, target_shape)[source]

Pad the array to match the target shape.

replace_map_nans()[source]

MIGHTEE specific method to replace nan values in all maps.

static sum_array(array)[source]

Sum the array.

class continunet.image.processing.PreProcessor(image: object, layers: int = 4)[source]

Bases: object

Pre-process image data for inference.

clean_nans()[source]

Check for NaNs in the image data.

normalise()[source]

Normalise the image data.

process()[source]

Process the image data.

reshape()[source]

Reshape the image data for the network. Shape must be divisible by 2 ** n layers.