utils_fits

Module for FITS utility functions.

ska_sdp_distributed_self_cal_prototype.processing_tasks.utils_fits.create_image(image_data: numpy.ndarray, width_in_pixels: int, height_in_pixels: int, pixel_width_in_radians: float, pixel_height_in_radians: float, phase_centre: astropy.coordinates.SkyCoord, polarisation_frame: ska_sdp_datamodels.science_data_model.PolarisationFrame = ska_sdp_datamodels.science_data_model.PolarisationFrame, frequency: float = 100000000.0, channel_bandwidth: float = 1000000.0, n_channels: int = 3, clean_beam: dict[str, float] | None = None) ska_sdp_datamodels.image.image_model.Image[source]

Create an image consistent with the inputs, with the necessary metadata to be saved as a FITS file.

Parameters:
  • image_data – A four dimensional array of pixel data [channels, polarisation, ra, dec].

  • width_in_pixels – Image width.

  • height_in_pixels – Image height.

  • pixel_width_in_radians – Width of a pixel in radians.

  • pixel_height_in_radians – Height of a pixel in radians.

  • phase_centre – phase_centre.

  • polarisation_frame – Polarisation frame.

  • frequency – Start frequency.

  • channel_bandwidth – Channel width (Hz).

  • n_channels – Number of channels in image.

  • clean_beam – dict holding clean beam e.g {“bmaj”:0.1, “bmin”:0.05, “bpa”:-60.0}.

Returns:

Astropy Image object.

ska_sdp_distributed_self_cal_prototype.processing_tasks.utils_fits.create_image_with_wcs(image_data: numpy.ndarray, wcs: astropy.wcs.WCS, polarisation_frame: ska_sdp_datamodels.science_data_model.PolarisationFrame = ska_sdp_datamodels.science_data_model.PolarisationFrame, clean_beam: dict[str, float] | None = None) ska_sdp_datamodels.image.image_model.Image[source]

Create an image consistent with the inputs, with the necessary metadata to be saved as a FITS file.

Parameters:
  • image_data – A four dimensional array of pixel data [channel, polarisation, ra, dec].

  • wcs – A WCS object for the image data, this can be constructed using create_wcs.

  • polarisation_frame – Polarisation frame.

  • clean_beam – dict holding clean beam e.g {“bmaj”:0.1, “bmin”:0.05, “bpa”:-60.0}.

Returns:

Astropy Image object.

ska_sdp_distributed_self_cal_prototype.processing_tasks.utils_fits.create_wcs(width_in_pixels: int, height_in_pixels: int, pixel_width_in_radians: float, pixel_height_in_radians: float, phase_centre: astropy.coordinates.SkyCoord, polarisation_frame: ska_sdp_datamodels.science_data_model.PolarisationFrame = ska_sdp_datamodels.science_data_model.PolarisationFrame, frequency: float = 100000000.0, channel_bandwidth: float = 1000000.0, n_channels: int = 3) astropy.wcs.WCS[source]

Create a FITS WCS consistent with the inputs.

Parameters:
  • width_in_pixels – Image width.

  • height_in_pixels – Image height.

  • pixel_width_in_radians – Width of a pixel in radians.

  • pixel_height_in_radians – Height of a pixel in radians.

  • phase_centre – Phase centre.

  • polarisation_frame – Polarisation frame.

  • frequency – Start frequency.

  • channel_bandwidth – Channel width (Hz).

  • n_channels – Number of channels in output image.

Returns:

A valid WCS object constructed to be used with 4d image data: [channel, polarisation, ra, dec]

Return type:

wcs

ska_sdp_distributed_self_cal_prototype.processing_tasks.utils_fits.extract_subimage(fits_path: str | Path, right_ascension: float, declination: float, image_size_degrees: float, hdu_id: int = 0) astropy.io.fits.HDUList[source]

Extract a subimage from a FITS file centered at the specified coordinates.

This function extracts a subimage from a FITS file by specifying the coordinates (right ascension and declination) at which the subimage should be centered, and the size of the subimage in degrees. The extraction is based on the header information of the specified HDU (Header Data Unit) in the FITS file.

Parameters:
  • fits_path – The path to the FITS file.

  • right_ascension – The right ascension of the centre of the subimage in degrees.

  • declination – The declination of the centre of the subimage in degrees.

  • image_size_degrees – The size of the subimage in degrees.

  • hdu_id – The index of the HDU to use from the FITS file. Defaults to 0.

Returns:

A HDU list containing the extracted subimage.

Return type:

hdu_list

ska_sdp_distributed_self_cal_prototype.processing_tasks.utils_fits.get_wcs_from_image_info(image_info: ImageInfo, width_in_pixels: int, height_in_pixels: int, polarisation_frame: ska_sdp_datamodels.science_data_model.PolarisationFrame = ska_sdp_datamodels.science_data_model.PolarisationFrame) astropy.wcs.WCS[source]

Create an FITS WCS consistent with the inputs.

Parameters:
  • image_info – Information on phase centre, pixel size and frequency required to construct the WCS.

  • width_in_pixels – Image width in pixels.

  • height_in_pixels – Image height in pixels.

  • polarisation_frame – Polarisation frame.

Returns:

[channel, polarisation, ra, dec]

Return type:

A valid WCS object constructed to be used with 4d image data

ska_sdp_distributed_self_cal_prototype.processing_tasks.utils_fits.load_image_data_from_fits(fits_path: Path | str, image_size: int) numpy.ndarray[source]

Load image data from a FITS file with appropriate metadata applied.

This function reads a FITS (Flexible Image Transport System) file and extracts specific header information along with image data centered at a specified right ascension and declination. The image size is determined by the provided image_size parameter and the pixel scale (CDELT2) from the FITS header.

Parameters:
  • fits_path – The file path to the FITS file.

  • image_size – The size of the image length in pixels, which is multiplied by the pixel scale to determine the final size in degrees.

Returns:

A 2D array of the image data.

Return type:

image_data

ska_sdp_distributed_self_cal_prototype.processing_tasks.utils_fits.save_fits_image(image_data: numpy.ndarray, wcs: astropy.wcs.WCS, output_path: Path)[source]

Create and save a fits image file containing image_data.

This function take a numpy array of floating point image data shaped [channels, polarisation, ra, dec] along with associated observation info and writes to disk a FITS image.

Parameters:
  • image_data – A four dimensional array of pixel data [channels, polarisation, ra, dec].

  • wcs – A WCS object for the image data, construct using create_wcs.

  • output_path – The path/filename where the image will be saved.

Returns:

None

Notes

  • Currently only takes one polarisation and assumes Stokes I.