API Reference
Cube
- class casa_cube.cube.Cube(filename, only_header=False, correct_factor=None, unit=None, pixelscale=None, restfreq=None, zoom=None, **kwargs)[source]
Bases:
objectA class to handle astronomy data cubes. This class provides functionality to read, manipulate, and analyze 3D FITS data cubes commonly used in (radio) astronomy.
The cube data is expected to have 3 dimensions: - Two spatial dimensions (RA, Dec) - One spectral dimension (frequency or velocity)
The class provides methods for: - Reading FITS files - Basic cube manipulation (cropping, smoothing, etc.) - Moment map generation - Spectral analysis - Visualization
- Variables:
filename (str) – Path to the input FITS file
header (astropy.io.fits.Header) – FITS header information
data (numpy.ndarray) – 3D array containing the cube data
wcs (astropy.wcs.WCS) – World Coordinate System information
object (str) – Name of the astronomical object
unit (str) – Units of the data values
- __init__(filename, only_header=False, correct_factor=None, unit=None, pixelscale=None, restfreq=None, zoom=None, **kwargs)[source]
Initialize a Cube object.
- Parameters:
filename (str) – The path to the FITS file containing the cube data.
only_header (bool) – If True, only read the header and not the data.
- _read(only_header=False, correct_factor=None, unit=None, pixelscale=None, instrument=None, restfreq=None, zoom=None)[source]
Read the FITS file and initialize the Cube object.
- Parameters:
only_header (bool) – If True, only read the header and not the data.
correct_factor (array-like) – Array of correction factors for the data.
unit (str) – The unit of the data.
pixelscale (float) – The pixel scale in arcsec.
instrument (str) – The instrument used to acquire the data.
restfreq (float) – The rest frequency of the data in Hz.
zoom (float) – The zoom factor for the data.
- cutout(filename, FOV=None, ix_min=None, ix_max=None, iv_min=None, iv_max=None, vmin=None, vmax=None, no_pola=False, pmin=None, pmax=None, channels=None, **kwargs)[source]
Cut out a region (in space, frequency and polarization) of the cube and save it as a new FITS file.
- Parameters:
filename (str) – The path to the output FITS file.
FOV (float) – The field of view in arcsec.
ix_min (int) – The minimum index of the x-axis.
ix_max (int) – The maximum index of the x-axis.
iv_min (int) – The minimum index of the velocity axis.
iv_max (int) – The maximum index of the velocity axis.
vmin (float) – The minimum velocity in km/s.
vmax (float) – The maximum velocity in km/s.
no_pola (bool) – If True, only keep the first polarization.
pmin (int) – The minimum index of the polarization axis.
pmax (int) – The maximum index of the polarization axis.
channels (list) – The list of channels to keep.
**kwargs – Additional keyword arguments for the fits.writeto function.
- tapered_fits(filename, taper=None, **kwargs)[source]
Create a tapered version of a fits file.
- Parameters:
filename (str) – The path to the output FITS file.
taper (float) – The taper size in arcsec.
**kwargs – Additional keyword arguments for the fits.writeto function.
- plot(iv=None, v=None, colorbar=True, plot_beam=True, color_scale=None, fmin=None, fmax=None, limit=None, limits=None, moment=None, moment_fname=None, vturb=False, Tb=False, cmap=None, v0=None, dv=None, ax=None, no_ylabel=False, no_xlabel=False, no_vlabel=False, title=None, alpha=1.0, interpolation='bicubic', resample=0, bmaj=None, bmin=None, bpa=None, taper=None, colorbar_label=True, colorbar_side='right', M0_threshold=None, M8_threshold=None, threshold=None, threshold_value=nan, vlabel_position='bottom', vlabel_color='white', vlabel_size=8, shift_dx=0, shift_dy=0, mol_weight=None, iv_support=None, v_minmax=None, axes_unit='arcsec', quantity_name=None, stellar_mask=None, levels=4, plot_type='imshow', linewidths=None, zorder=None, per_arcsec2=False, colors=None, x_beam=0.125, y_beam=0.125, mJy=False, width=None, highpass_filter=0, normalise=False, dynamic_range=None, hpf=False, RJ=True, **kwargs)[source]
Plotting routine for continuum image, moment maps and channel maps.
- Parameters:
iv (int) – The index of the velocity channel to plot.
v (float) – The velocity in km/s.
colorbar (bool) – Whether to plot the colorbar.
plot_beam (bool) – Whether to plot the beam.
color_scale (str) – The color scale to use.
fmin (float) – The minimum value of the color scale.
fmax (float) – The maximum value of the color scale.
limit (float) – The limit of the color scale.
limits (list) – The limits of the color scale.
moment (int) – The moment to plot.
moment_fname (str) – The filename of the moment map.
vturb (bool) – Whether to plot the turbulent velocity.
Tb (bool) – Whether to plot the brightness temperature.
cmap (str) – The colormap to use.
v0 (float) – The central velocity.
dv (float) – The velocity width.
ax (matplotlib.axes.Axes) – The axes to plot on.
no_ylabel (bool) – Whether to hide the y-axis label.
no_xlabel (bool) – Whether to hide the x-axis label.
no_vlabel (bool) – Whether to hide the velocity label.
title (str) – The title of the plot.
alpha (float) – The alpha value of the plot.
interpolation (str) – The interpolation method to use.
resample (int) – The resampling factor.
bmaj (float) – The major axis of the beam.
bmin (float) – The minor axis of the beam.
bpa (float) – The position angle of the beam.
taper (float) – The taper size.
colorbar_label (bool) – Whether to show the colorbar label.
colorbar_side (str) – The side of the colorbar to plot.
M0_threshold (float) – The threshold for the M0 moment map.
M8_threshold (float) – The threshold for the M8 moment map.
threshold (float) – The threshold for the plot.
threshold_value (float) – The value to use for the threshold.
vlabel_position (str) – The position of the velocity label.
vlabel_color (str) – The color of the velocity label.
vlabel_size (int) – The size of the velocity label.
shift_dx (float) – The shift in the x-direction.
shift_dy (float) – The shift in the y-direction.
mol_weight (str) – The molecular weight to use.
iv_support (list) – The indices of the velocity channels to support.
v_minmax (list) – The minimum and maximum velocities to plot.
axes_unit (str) – The unit of the axes.
quantity_name (str) – The name of the quantity to plot.
stellar_mask (str) – The filename of the stellar mask.
levels (int) – The number of levels for the contour plot.
plot_type (str) – The type of plot to make.
linewidths (list) – The linewidths for the contour plot.
zorder (int) – The zorder for the plot.
per_arcsec2 (bool) – Whether to plot the quantity per arcsec^2.
colors (list) – The colors for the contour plot.
x_beam (float) – The x-axis beam size.
y_beam (float) – The y-axis beam size.
mJy (bool) – Whether to plot the quantity in mJy.
width (float) – The width of the plot.
highpass_filter (float) – The highpass filter to apply.
normalise (bool) – Whether to normalise the plot.
dynamic_range (float) – The dynamic range of the plot.
hpf (bool) – Whether to apply a highpass filter.
**kwargs – Additional keyword arguments for the plot.
- plot_channels(n=20, num=21, ncols=5, iv_min=None, iv_max=None, vmin=None, vmax=None, **kwargs)[source]
Plot the channels of the cube.
- Parameters:
n (int) – The number of channels to plot.
num (int) – The figure number.
ncols (int) – The number of columns in the plot.
iv_min (int) – The minimum index of the velocity channel to plot.
iv_max (int) – The maximum index of the velocity channel to plot.
vmin (float) – The minimum velocity to plot.
vmax (float) – The maximum velocity to plot.
**kwargs – Additional keyword arguments for the plot.
- get_line_profile(threshold=None, **kwargs)[source]
Get the line profile of the cube.
- Parameters:
threshold (float) – The threshold for the line profile.
**kwargs – Additional keyword arguments for the plot.
- plot_line(x_axis='velocity', threshold=None, ax=None, **kwargs)[source]
Plot the line profile of the cube.
- Parameters:
x_axis (str) – The axis to plot on.
threshold (float) – The threshold for the line profile.
ax (matplotlib.axes.Axes) – The axes to plot on.
**kwargs – Additional keyword arguments for the plot.
- get_moment_map(moment=0, v0=0, M0_threshold=None, M8_threshold=None, threshold=None, iv_support=None, v_minmax=None)[source]
Calculate the moment map of the cube.
We use the same convention as CASA : moment 8 is peak flux, moment 9 is peak velocity This returns the moment maps in physical units, ie: - M0 is the integrated line flux (Jy/beam . km/s) - M1 is the average velocity (km/s) - M2 is the velocity dispersion (km/s) - M8 is the peak intensity - M9 is the velocity of the peak
- Parameters:
moment (int) – The moment to calculate.
v0 (float) – The central velocity.
M0_threshold (float) – The threshold for the M0 moment map.
M8_threshold (float) – The threshold for the M8 moment map.
threshold (float) – The threshold for the moment map.
iv_support (list) – The indices of the velocity channels to support.
v_minmax (list) – The minimum and maximum velocities to plot.
- get_high_pass_filter_map(moment=None, w0=None, gamma=0, **kwargs)[source]
Perform a Gaussian high pass filter on a moment map. w0 is in arcsec, with an optional radial stretch exponent gamma
- Parameters:
moment (int) – The moment to use for the high pass filter.
w0 (float) – The width of the Gaussian filter in arcsec.
gamma (float) – The radial stretch exponent.
**kwargs – Additional keyword arguments for the moment map.
- get_fwhm(v0=0, M0_threshold=None)[source]
Get the line FWHM of the cube.
- Parameters:
v0 (float) – The central velocity.
M0_threshold (float) – The threshold for the M0 moment map.
- get_vturb(v0=0, M0_threshold=None, threshold=None, mol_weight=None)[source]
Get the turbulent linewidth of the cube.
- Parameters:
v0 (float) – The central velocity.
M0_threshold (float) – The threshold for the M0 moment map.
- get_std(taper=0)[source]
Get the standard deviation of the cube.
- Parameters:
taper (float) – The taper for the beam.
- property beam
Returns the beam parameters in (“), (“), (deg).
- _Jybeam_to_Tb(im, RJ=False)[source]
Convert flux converted from Jy/beam to K using full Planck law.
Constants
- casa_cube.FWHM_to_sigma = 1.0 / np.sqrt(8.0 * np.log(2))
- casa_cube.arcsec = np.pi / 648000
- casa_cube.default_cmap = cmr.arctic
- casa_cube.line_list Dictionary of molecular line frequencies and names
Utility Functions
- casa_cube.add_colorbar(mappable, shift=None, width=0.05, ax=None, trim_left=0, trim_right=0, side='right', **kwargs)[source]
Add a color bar to a plot.
- Parameters:
mappable (matplotlib.cm.ScalarMappable) – The mappable object to add the color bar to.
shift (float) – The shift for the color bar.
width (float) – The width of the color bar.
ax (matplotlib.axes.Axes) – The axes to add the color bar to.
trim_left (float) – The left trim for the color bar.
trim_right (float) – The right trim for the color bar.
side (str) – The side of the color bar.