ska_sdp_spectral_line_imaging.util module

class ska_sdp_spectral_line_imaging.util.SafeDict[source]

Bases: dict

Class to allow for selective format_map function

ska_sdp_spectral_line_imaging.util.rechunk(target, ref, dim)[source]

Rechunk a target DataArray based on a ref DataArray

Parameters:
  • target (xr.DataArray) -- DataArray to be rechunked

  • ref (xr.DataArray) -- Reference DataArray

  • dim (dict) -- Dimensions to be expanded along

Returns:

xr.DataArray

ska_sdp_spectral_line_imaging.util.export_image_as(image, output_path, export_format='fits')[source]

Export data in the desired export_format

Parameters:
Returns:

dask.delayed.Delayed

Raises:

ValueError: -- If the provided data format is not in fits or zarr

ska_sdp_spectral_line_imaging.util.export_to_zarr(data, output_path, clear_attrs=False)[source]

Lazily export xarray dataset/dataarray to zarr file format.

Parameters:
  • data (xarray.DataArray | xarray.Dataset) -- Xarray data to be exported

  • output_path (str) -- Output file path. A ".zarr" is appended to this path.

  • clear_attrs (bool = False) -- Whether to clear attributes of the data before writing to zarr.

Returns:

dask.delayed.Delayed

A dask delayed object which represents the task of writing data to zarr.

ska_sdp_spectral_line_imaging.util.export_to_fits(image, output_path)[source]

Exports Image instance to multiple FITS files, one per polarisation. The caller is expected to call dask.compute() on the returned delayed objects for the actual writes to happen.

Parameters:
  • image (ska_sdp_datamodels.image.Image) -- Image instance containing all the polarisations.

  • output_path (str) -- Path to write FITS image to. The output_path is appended with ".{pol}.fits" where "pol" is the polarization being written.

Returns:

List[dask.delayed.Delayed]

ska_sdp_spectral_line_imaging.util.estimate_cell_size_in_arcsec(baseline, wavelength, factor=3.0)[source]

A generalized function which estimates cell size for given baseline value.

This function is dask compatible i.e. can take dask arrays as input, and return dask array as output.

Parameters:
  • baseline (float) -- Baseline length in meters. For better estimation, this has to be the maximum baseline length in any direction.

  • wavelength (float) -- Wavelength in meters. For better estimation, it has to be the minimum wavelength observed.

  • factor (float) -- Scaling factor.

Return type:

float

Returns:

float

Cell size in arcsecond. The output is rounded to the 2 decimal places.

ska_sdp_spectral_line_imaging.util.estimate_image_size(wavelength, antenna_diameter, cell_size)[source]

Estimates dimension of the image which will be used in the imaging stage.

This function is dask compatible i.e. can take dask arrays as input, and return dask array as output.

Parameters:
  • wavelength (float) -- Wavelength in meters. For better estimation, this has to be the maximum wavelength observed.

  • antenna_diameter (float) -- Diameter of the antenna in meters. For better estimation, this has to be the minimum of the diameters of all antennas.

  • cell_size (float) -- Cell size in arcsecond.

Return type:

int

Returns:

int

Size of the image. The output is rounded to the nearest multiple of 100 greater than the calculated image size.

ska_sdp_spectral_line_imaging.util.get_polarization_frame_from_observation(observation)[source]

Reads an observation from the xradio processing set, and generates a PolarizationFrame instance from the polarization coordinates. This is required to generate an instance of Image class.

Parameters:

observation (xarray.Dataset) -- Observation from xradio processing set

Return type:

PolarisationFrame

Returns:

PolarisationFrame

ska_sdp_spectral_line_imaging.util.get_wcs_from_observation(obs, cell_size, nx, ny)[source]

Reads an observation from the xradio processing set, and extracts WCS information. This is required to create an instance of Image class defined in ska_sdp_datamodels.image.Image.

Since Image dimensions are fixed to ["frequency", "polarisation", "y", "x"], the sequence of axes in WCS is ["RA", "DEC", "STOKES", "FREQ"].

NOTE: Polarization axis is defaulted to stokes, with crval = 1.0 and cdelta = 1.0. This is done due to the difference in the sequence of linear and circular polarizations values in FITS and in processing set. Consumer of this function is expected to populate correct values for polarizations present in the processing set.

NOTE: field_and_source_base_xds is assumed to be the same across all observations in the processing set. The first observation is used to extract the field phase center.

Parameters:
  • obs (xarray.Dataset) -- Concatenated observation dataset from upstream output

  • cell_size (float) -- Cell size in arcseconds.

  • nx (int) -- Image size X

  • ny (int) -- Image size Y

Return type:

WCS

Returns:

WCS

ska_sdp_spectral_line_imaging.util.get_dask_array_from_fits(image_path, hduid, shape, dtype)[source]
ska_sdp_spectral_line_imaging.util.get_dataarray_from_fits(image_path, hduid=0)[source]

Reads FITS image and returns an xarray dataarray with dimensions ["polarization", "frequency", "y", "x"] or only ["y", "x"] if data is 2 dimensionsional.

Function can also read coordinte values for dimensions "polarization" and "frequency". Spatial coordinates "y" and "x" are linear, and the their coordinate values are not populatedin output dataarray. If needed, those can be populated later. Refer ska_sdp_datamodels.image.Image.constructor.

The image data is read as a dask array using delayed read calls to astropy.fits.open.

Parameters:
  • image_path (str) -- Path to FITS image

  • hduid (int) -- The HDU number in the HDUList read from FITS image.

Returns:

xarray.DataArray

Raises:

NotImplementedError -- If chunksizes are passed as parameter