Image Object DocString

Image class, for manipulating JWST image data.

This class is used to create and manipulate Image objects. Many of the JWST instruments provide data in image form (2D arrays). Reduced images in the JWST pipeline have the default suffix “_i2d”. This class can also be used to manipulate images generated from a data cube.

The Image object has two headers, both containing information about the data. The structure and information of the headers are identical to those of the files output by the reduction pipeline. The first header is called ‘primary’ and contains all general information about the observations (PI, instrument, date, time and duration of observations, configuration, etc.). The second header provides more information about the data, such as 2D array size, 2-axis sampling and units. A summary of the information can be displayed using the .info() method.

The values (in surface brightness if units are the default) of the 2D array are stored in the .data attribute. The uncertainties at each pixel of the image are also stored in an .errs attribute, an array of the same size as the data.

When creating a Cube object, you must provide the file name in .fits format.

param file_name:

The name of the file in .fits format. For JWST imaging, the default name contains the suffix “_i2d”.

type file_name:

str

JWSToolKit.Image.primary_header

The FITS primary header, using astropy.io tools.

Type:

‘astropy.io.fits.Header’

JWSToolKit.Image.data_header

The FITS header associated with the data, using astropy.io tools.

Type:

‘astropy.io.fits.Header’

JWSToolKit.Image.data

Data stored as an image (2D array). The two dimensions are the spatial dimensions.

Type:

array_like

JWSToolKit.Image.errs

Uncertainties associated with ‘science’ data stored in the .data attribute.

Type:

array_like

JWSToolKit.Image.size

The number of points in each dimension.

Type:

array_like

JWSToolKit.Image.px_area

Area of the spatial pixels. The value is given in steradian.

Type:

float

JWSToolKit.Image.units

The unit of values stored in the .data table. Default values are surface brightness in MJy/sr.

Type:

str

class JWSToolKit.Image.Image(file_name)[source]

Bases: object

convolve(fwhm: float, psf: str = 'gaus', control_plot: bool = False)[source]

Convolves the image with a convolution kernel.

Parameters:
  • fwhm (float) – Full-width at half-maximum of convolution profile. Whatever the convolution kernel, the 2D profile is symmetrical. The value must be given in arcsec.

  • psf (str, optional) – Convolution kernel. Possible choices are: ‘gaussian’, ‘voigt’, ‘lorentz’.

  • control_plot (bool, optional) – If True, shows the image before and after convolution.

Returns:

The initial image convoluted by a PSF profile.

Return type:

Image object

crop(width: int, height: int, center: list[float] = None)[source]

Cut out a portion of the image based on width and height

Parameters:
  • width (int) – Width of final image, in pixel.

  • int (height =) – Height of final image, in pixel.

  • center (list, optional) – The central position of the final image in the reference frame of the initial image, in pixels. It must be in the form [x,y].

Returns:

An image object with modified header considering cropping parameters.

Return type:

Image object

extract_intensity_profile(center: list[float], angle: float, length: float, control_plot: bool = False)[source]

Extract an intensity profile along a straight line.

Parameters:
  • center (list) – The central position from which the profile is extracted. Is the pivot point of the line, given in pixels as [x,y].

  • angle (float) – The position angle of the extraction line, given in degrees.

  • length (float) – Length of extraction line, given in pixels.

  • control_plot (bool, optional) – If True, displays the extraction line on the image.

Returns:

The spatial axis in pixels and associated intensity values.

Return type:

list

classmethod from_file_extension(primary_header, data_header, data, errs=None)[source]

Builds a ‘Image’ object from file headers and data.

Parameters:
  • primary_header (astropy.io.fits.header.Header) – The JWST image primary header, extract with astropy.io.

  • data_header (astropy.io.fits.header.Header) – The science header for JWST images, extract with astropy.io.

  • data (array_like) – Values from the image, stored in a 2D array.

  • errs (array_like, optional) – Error data associated with the data array, stored in a 2D array

Returns:

A Image object.

Return type:

Image object

get_px_coords(coords: list)[source]

Returns the coordinates in pixels (x,y) of one or more pixel positions in the image.

Parameters:

coords (list) – Coordinates in degrees (R.A., Dec.) to be converted into pixel coordinates. It can contain two elements (corresponding to the position of a single point) or two sub-lists containing the R.A. and Dec. positions of several points respectively.

Returns:

If the coordinates of a single point have been given, the list contains two elements being the (x,y) coordinates converted into pixel coordinates. If the coordinates are those of several points, the list contains two sub-lists containing respectively the x and y positions of the different points.

Return type:

array_like

get_world_coords(coords: list)[source]

Returns the coordinates in degrees (R.A., Dec.) of one or more pixel positions in the image.

Parameters:

coords (list) – Coordinates in pixels to be converted into degrees. It can contain two elements (corresponding to the position of a single point) or two sub-lists containing the horizontal and vertical positions of several points respectively.

Returns:

If the coordinates of a single point have been given, the list contains two elements being the R.A., Dec. coordinates converted into degrees. If the coordinates are those of several points, the list contains two sub-lists containing respectively the R.A., Dec. positions of the different points.

Return type:

array_like

info()[source]

Prints information stored in headers associated with the image.

plot(scale: str = 'lin', use_wcs: bool = False, lims: list[float] = None, abs_transform: bool = False, save: bool = False, colorbar: bool = False, origin_arcsec: list[float] = None, draw_compass: bool = False)[source]

Display the image via matplotlib

Parameters:
  • scale (str, optional) – Transformation for normalizing image values, i.e. colorbar scaling. Accepted transformations are : ‘lin’, ‘log’, ‘sqrt’, ‘asinh’.

  • use_wcs (bool, optional) – If True, the figure axes are given in RA Dec world coordinates using the wcs of the observations.

  • lims (list, optional) – The minimum and maximum values to be displayed on the image (may depend on the type of normalization of the figure). Limits must respect the form [x,y].

  • abs_transform (bool, optional) – If True, displays the absolute value of the image.

  • save (bool, optional) – If True, saves the figure in png format.

  • colorbar (bool, optional) – If True, displays the color scale on figure.

  • origin_arcsec (list, optional) – The pixel position of the axis origin converted to arcsec. It must be given in the form [x0, y0].

rotate(angle: float, control_plot: bool = False)[source]

Rotates the image by modifying the WCS of the file headers.

Parameters:
  • angle (float) – Angle of rotation to be applied to data. The angle follows the counter-clockwise convention.

  • control_plot (float, optional) – If True, show the image before and after rotation.

Returns:

Image rotated, with headers updated.

Return type:

Image object

save_as_dat(filename: str = None)[source]

Saves the image as a .dat file

Parameters:

filename (str, optional) – Output file name.

save_as_fits(filename: str = None)[source]

Saves the image as a .fits file

Parameters:

filename (str, optional) – Output file name.