casa_fits package

Submodules

casa_fits.Image module

class Image(imagename: str = '', data: numpy.ndarray = <factory>, width: int | None = None, height: int | None = None, nchan: int | None = None, center_radec: tuple[float, float] = (0, 0), center_pix: tuple[float, float] = (0, 0), freq0: float = 0, incr_x: float = 0, incr_y: float = 0, incr_hz: float = 0, unit_x: str = 'arcsec', unit_y: str = 'arcsec', unit_data: str = '', beam: tuple[float, float, float] = (0, 0, 0))

Bases: object

imagename: str = ''
data: ndarray
width: int | None = None
height: int | None = None
nchan: int | None = None
center_radec: tuple[float, float] = (0, 0)
center_pix: tuple[float, float] = (0, 0)
freq0: float = 0
incr_x: float = 0
incr_y: float = 0
incr_hz: float = 0
unit_x: str = 'arcsec'
unit_y: str = 'arcsec'
unit_data: str = ''
beam: tuple[float, float, float] = (0, 0, 0)
convert_axes_unit(unit: str)

Convert the axes units of the image to the specified unit.

Parameters:

unit (str) – The unit to convert to (e.g., ‘arcsec’).

get_ticks(xtickspan: int, ytickspan: int, relative: bool, fmt: str, width: int | None = None, height: int | None = None) tuple[list[float], list[str], list[float], list[str]]

Returns x and y ticks and tick labels.

Parameters:
  • xtickspan (int) – Span of ticks of x-axis.

  • ytickspan (int) – Span of ticks of y-axis.

  • relative (bool) – If True, ticks are relative coordinates. If False, ticks are global coordinates (NOT IMPLEMENTED YET!).

  • fmt (str) – Format of tick labels.

  • width (int | None) – Width of the image. If None, use the width of the image.

  • height (int | None) – Height of the image. If None, use the height of the image.

Returns:

xticks, xticks_label, yticks, yticks_label

get_two_dim_data(stokes: int = 0, chan: int = 0) ndarray

Extracts the 2D data based on the specified Stokes and channel indices.

Parameters:
  • stokes (int, optional) – Stokes parameter index. Defaults to 0.

  • chan (int, optional) – Channel index. Defaults to 0.

Returns:

The extracted 2D data.

Return type:

np.ndarray

keep_stokes_chan(stokes: int, chan: int)

Keep only specific stokes and channel from the image data. This is useful for the image that has only one stokes and channel.

Parameters:
  • stokes (int) – The Stokes parameter to keep.

  • chan (int) – The channel to keep.

casa_fits.azimuth_cut module

azimuth_cut(img: Image, radius: float, inclination: float, pa: float, beam_factor: float = 0.5, stokes: int = 0, chan: int = 0) tuple

Extract an azimuthal cut from an image using a deprojected elliptical annulus.

This implementation computes the deprojected radius for each pixel, given the inclination and position angle, and selects pixels that lie within an annulus defined by [radius_px - beam_size/2, radius_px + beam_size/2]. The azimuthal angle is computed in the deprojected frame.

Parameters:
  • img (Image) – The Image object.

  • radius (float) – The radius in arcsec.

  • inclination (float) – The inclination angle in degrees.

  • pa (float) – The position angle in degrees.

  • beam_factor (float, optional) – Sampling size based on the beam size. Defaults to 0.5.

  • stokes (int, optional) – Stokes parameter index. Defaults to 0.

  • chan (int, optional) – Channel index. Defaults to 0.

Returns:

A tuple of three numpy arrays:
  • The azimuthal angle (in degrees) bins.

  • The mean intensity in each bin.

  • The standard deviation of the intensity in each bin.

Return type:

tuple

casa_fits.detectpeak module

detectpeak(img: Image, rms: float, threshold_rms: int = 5, find_max: bool = True) list[tuple[int, int, float]]

Detects peaks in an image.

Parameters:
  • img (Image) – The image object.

  • rms (float) – The RMS noise level for peak detection. Only pixels with intensity greater than threshold_rms * rms will be considered.

  • threshold_rms (int) – The threshold in terms of RMS to consider a pixel as a peak. Default is 5.

  • find_max (bool) – If True, the function will find the maximum peaks. Otherwise, it will find the minimum peaks.

Returns:

The list of detected peaks. Each peak is represented as a tuple (x, y, value).

Return type:

list[tuple[int, int, float]]

casa_fits.imshow module

draw_beam(ax: Axes, img: Image, beam: tuple | None = None, color: str = 'white') None

Draws the beam on the image.

Parameters:
  • ax (matplotlib.axes.Axes) – The Axes object.

  • img (Image) – The Image object.

  • beam (tuple) – The beam parameters (beam_x, beam_y, beam_ang). If both img and beam are provided, beam will be used.

  • color (str) – The color of the beam. Default to ‘white’.

imshow(ax: Axes, img: Image, **kwargs)

Rasterizes an image on given Axes object with matplotlib from a CASA style image file.

Parameters:
  • ax (matplotlib.axes.Axes) – The Axes object.

  • img (Image) – The Image object.

  • config (PlotConfig) – The PlotConfig object.

Returns:

The AxesImage object.

Return type:

matplotlib.image.AxesImage

overlay_contour(ax: Axes, img_base: Image, img: Image, stokes: int = 0, chan: int = 0, fill: bool = False, **kwargs) None

Overlays contours on the image.

To plot with correct scaling, both Image objects should have incr_x and incr_y attributes.

Parameters:
  • ax (plt.Axes) – The Axes object.

  • img_base (Image) – Image plotted as background (This should have been already plotted).

  • img (Image) – Image to be plotted as contours.

  • fill (bool) – If True, the contours will be filled. Default is False.

  • nchan (int) – The channel number to be plotted. If img is a cube, this should be specified.

  • **kwargs – Contour configuration keywords of matplotlib.pyplot.contour.

casa_fits.imstat module

imstat(image: Image, uncertainty: float, unit: str = 'beam', mask: ndarray | None = None, inverse_mask: bool = False)

Alternative version of imstat.

Parameters:
  • image (Image) – Image object.

  • uncertainty (float) – Flux uncertainty.

  • unit (str, optional) – Unit of area. Choices are ‘beam’ or ‘arcsec’. Defaults to ‘beam’.

  • mask (np.ndarray, optional) – If specified, statistics are calculated using only the data within the mask. Defaults to None.

  • inverse_mask (bool, optional) – If True, the specified mask region is inverted. Defaults to False.

casa_fits.io module

load_fits(fits_file: str, width: int | None = None, height: int | None = None, center_radec: tuple[float, float] | tuple[str, str] | None = None) Image

Create an Image object from a FITS file.

Parameters:
  • fits_file (str) – Path to the FITS file.

  • width (int, optional) – Width of the cropped image. If None, uses the full width.

  • height (int, optional) – Height of the cropped image. If None, uses the full height.

  • center_radec (tuple[float, float], optional) – Center coordinates in RA, Dec format. If None, uses the center of the image.

Returns:

An Image object.

Return type:

Image

load_image(imagename: str, width: int | None = None, height: int | None = None, center_radec: tuple[float, float] | tuple[str, str] | None = None) Image

Create an Image object from a CASA image file.

Parameters:
  • imagename (str) – Path to the CASA image file.

  • width (int, optional) – Width of the cropped image. If None, uses the full width.

  • height (int, optional) – Height of the cropped image. If None, uses the full height.

  • center_radec (tuple[float, float], optional) – Center coordinates in RA, Dec format. If None, uses the center of the image.

Returns:

An Image object.

Return type:

Image

casa_fits.matplotlib_helper module

set_cbar(im: AxesImage, observable: str, unit: str, rescale: str, fmt: str, fmt_default: str) None

Sets the colorbar for the given figure and image axes.

Parameters:
  • im (plt.image.AxesImage) – The image axes.

  • observable (str) – The observable being plotted.

  • unit (str) – The unit of the observable.

  • rescale (str) – The SI prefix to rescale the colorbar.

  • fmt (str) – The format string for the colorbar labels.

  • fmt_default (str) – The default format string for the colorbar labels.

set_axes_options(ax: Axes, title: str, xlabel: str, ylabel: str, xticks, xticks_label, yticks, yticks_label)

casa_fits.radial_cut module

radial_cut(img: Image, azimuth: float, sample_size: int = 5, stokes: int = 0, chan: int = 0) tuple[ndarray, ndarray, ndarray]

Radial line cut of the image along the specified azimuth angle from the center.

Parameters:
  • img (Image) – The Image object.

  • azimuth (float) – The azimuth angle in degrees.

  • sample_size (int, optional) – The number of samples to take along the radial line. Defaults to 5.

  • stokes (int, optional) – Stokes parameter index. Defaults to 0.

  • chan (int, optional) – Channel index. Defaults to 0.

Returns:

A tuple of three numpy arrays:
  • The radial distance from the center.

  • The mean intensity.

  • The standard deviation of the intensity.

Return type:

tuple

casa_fits.radial_profile module

radial_profile(img: Image, azimuth: tuple | None = None, sample_size: int = 5, inc: float = 0.0, PA: float = 0.0, stokes: int = 0, chan: int = 0) tuple

Extract a radial profile from an image.

Parameters:
  • img (Image) – The Image object.

  • azimuth (tuple) – The azimuth range angle in degrees. If None, all azimuth angles are considered.

  • sample_size (int, optional) – The number of samples to take along the radial line. Defaults to 5.

  • inc (float, optional) – The inclination angle in degrees. Defaults to 0.0.

  • PA (float, optional) – The position angle in degrees. Defaults to 0.0.

  • stokes (int, optional) – Stokes parameter index. Defaults to 0.

  • chan (int, optional) – Channel index. Defaults to 0.

Returns:

A tuple of three numpy arrays:
  • The radial distance from the center.

  • The mean intensity.

  • The standard deviation of the intensity.

Return type:

tuple

casa_fits.utilities module

get_si_prefix_symbol(prefix: str) str

Returns the SI prefix symbol for a given prefix string.

Parameters:

prefix (str) – The SI prefix string.

Returns:

The symbol associated with the given prefix.

Return type:

str

get_si_prefix_base10(prefix: str) float

Returns the base 10 multiplier for a given SI prefix string.

Parameters:

prefix (str) – The SI prefix string.

Returns:

The base 10 multiplier associated with the given prefix.

Return type:

float

get_pret_dir_name(dir: str) str

Returns the last component of a directory path without trailing slashes.

Parameters:

dir (str) – The directory path.

Returns:

The last component of the directory path.

Return type:

str

downsample_data(data: ndarray, sample_size: int) ndarray

Downsamples a 2D numpy array by averaging over blocks of size sample_size.

Parameters:
  • data (np.ndarray) – The 2D numpy array to downsample.

  • sample_size (int) – The size of the blocks to average over.

Returns:

The downsampled 2D numpy array.

Return type:

np.ndarray

Module contents