API¶
Here we describe all the functions used to collapse the spectral cube which are typically called by the command line interface. However, importing these into your workflow may be useful.
In general, for the generated moment maps, MX
, where X
is an integer
denotes a statistical moment. For the nontraditional methods, v0
, dV
and Fnu
represent the line center, width and peak, respectively.
Note
The convolution for smooththreshold
is currently experimental and is
work in progress. If things look suspicious, please raise an issue.
Moment Maps¶
Implementation of traditional momentmap methods. See the CASA documentation for more information.

bettermoments.methods.
collapse_zeroth
(velax, data, rms)¶ Collapses the cube by integrating along the spectral axis. It will return the integrated intensity along the spectral axis,
M0
, and the associated uncertainty,dM0
. Following Teague (2019) these are calculated by,and
where and are the chanenl width and flux density at the channel, respectively and the sum goes over the whole
axis
.Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Flux densities or brightness temperature array. Assumes that the first axis is the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.
Returns: M0
, the integrated intensity along provided axis anddM0
, the uncertainty onM0
in the same units asM0
.Return type: M0
(ndarray),dM0
(ndarray)

bettermoments.methods.
collapse_first
(velax, data, rms)¶ Collapses the cube using the intensity weighted average velocity (or first moment map). For a symmetric line profile this will be the line center, however for highly nonsymmetric line profiles, this will not give a meaningful result. Following Teague (2019), the line center is given by,
where and are the velocity and flux density at the channel, respectively and the sum goes over the whole
axis
. In addition, the uncertainty is given by,where is the rms noise.
Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Flux densities or brightness temperature array. Assumes that the zeroth axis is the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.
Returns: M1
, the intensity weighted average velocity in units ofvelax
anddM1
, the uncertainty in the intensity weighted average velocity with same units asv0
.Return type: M1
(ndarray),dM1
(ndarray)

bettermoments.methods.
collapse_second
(velax, data, rms)¶ Collapses the cube using the intensityweighted average velocity dispersion (or second moment). For a symmetric line profile this will be a measure of the line width. Following Teague (2019) this is calculated by,
where is the first moment and and are the velocity and flux density at the channel, respectively. The uncertainty is given by,
where is the rms noise in the channel.
Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Flux densities or brightness temperature array. Assumes that the first axis is the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.
Returns: M2
is the intensity weighted velocity dispersion with units ofvelax
.dM2
is the unceratinty ofM2
in the same units.Return type: M2
(ndarray),dM2
(ndarray)

bettermoments.methods.
collapse_eighth
(velax, data, rms)¶ Take the peak value along the provided axis. The uncertainty is the RMS noise of the image.
Parameters:  velax (ndarray) – Velocity axis of the cube. Not needed.
 data (ndarray) – Flux densities or brightness temperature array. Assumes that the first axis is the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.
Returns: The peak value,
M8
, and the associated uncertainty,dM8
.Return type: M8
(ndarray),dM8
(ndarray)

bettermoments.methods.
collapse_ninth
(velax, data, rms)¶ Take the velocity of the peak intensity along the provided axis. The uncertainty is half the channel width.
Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Flux densities or brightness temperature array. Assumes that the first axis is the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.
Returns: The velocity value of the peak value,
M9
, and the associated uncertainty,dM9
.Return type: M9
(ndarray),dM9
(ndarray)

bettermoments.methods.
collapse_maximum
(velax, data, rms)¶ A wrapper returning the result of both
bettermoments.collapse_cube.collapse_eighth()
andbettermoments.collapse_cube.collapse_ninth()
.Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Flux densities or brightness temperature array. Assumes that the first axis is the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.
Returns: The peak value,
M8
, and the associated uncertainty,dM8
. The velocity value of the peak value,M9
, and the associated uncertainty,dM9
.Return type: M8
(ndarray),dM8
(ndarray),M9
(ndarray),dM9
(ndarray)
NonTraditional Methods¶

bettermoments.methods.
collapse_quadratic
(velax, data, rms)¶ Collapse the cube using the quadratic method presented in Teague & ForemanMackey (2018). Will return the line center,
v0
, and the uncertainty on this,dv0
, as well as the line peak,Fnu
, and the uncertainty on that,dFnu
. This provides the subchannel precision ofbettermoments.collapse_cube.collapse_first()
with the robustness to noise frombettermoments.collapse_cube.collapse_ninth()
.Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Flux density or brightness temperature array. Assumes that the zeroth axis is the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.
Returns: v0
, the line center in the same units asvelax
withdv0
as the uncertainty onv0
in the same units asvelax
.Fnu
is the line peak in the same units as thedata
with associated uncertainties,dFnu
.Return type: v0
(ndarray),dv0
(ndarray),Fnu
(ndarray),dFnu
(ndarray)

bettermoments.methods.
collapse_width
(velax, data, rms)¶ Returns an effective width, a rescaled ratio of the integrated intensity and the line peak. For a Gaussian line profile this would be the Doppler width as the total intensity is given by,
where and are the chanenl width and flux density at the channel. If the line profile is Gaussian, then equally
where is the peak value of the line and is the Doppler width of the line. As and are readily calculated using
bettermoments.collapse_cube.collapse_zeroth()
andbettermoments.collapse_cube.collapse_quadratic()
, respectively, can calculated through . This should be more robust against noise than second moment maps.Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Flux densities or brightness temperature array. Assumes that the first axis is the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.
Returns: The effective velocity dispersion,
dV
andddV
, the associated uncertainty.Return type: dV
(ndarray),ddV
(ndarray)
(Higher Order) Gaussian Fits¶

bettermoments.methods.
collapse_gaussian
(velax, data, rms, indices=None, chunks=1, **kwargs)¶ Collapse the cube by fitting a Gaussian line profile to each pixel. This function is a wrapper of collapse_analytical which provides more details about the arguments.
Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Maksed intensity or brightness temperature array. The first axis must be the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.  indices (Optional[list]) – A list of pixels described by
(y_idx, x_idx)
tuples to fit. If none are provided, will fit all pixels.  chunks (Optional[int]) – Split the cube into
chunks
sections and run the fits with separate processes throughmultiprocessing.pool
.
Returns: gv0
(ndarray),dgv0
(ndarray),gFnu
(ndarray),dgFnu
(ndarray),gdV
(ndarray),dgdV
(ndarray):The Gaussian center,
gv0
, the line peak,gFnu
and the Doppler width,gdV
, all with associated uncertainties,dg*
.

bettermoments.methods.
collapse_gaussthick
(velax, data, rms, indices=None, chunks=1, **kwargs)¶ Collapse the cube by fitting a Gaussian line profile with an optically thick core to each pixel. This function is a wrapper of collapse_analytical which provides more details about the arguments.
Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Maksed intensity or brightness temperature array. The first axis must be the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.  indices (Optional[list]) – A list of pixels described by
(y_idx, x_idx)
tuples to fit. If none are provided, will fit all pixels.  chunks (Optional[int]) – Split the cube into
chunks
sections and run the fits with separate processes throughmultiprocessing.pool
.
Returns: gtv0
(ndarray),dgtv0
(ndarray),gtFnu
(ndarray),dgtFnu
(ndarray),gtdV
(ndarray),dgtdV
(ndarray),gttau
(ndarray),dgttau
(ndarray):The Gaussian center,
gtv0
, the line peak,gtFnu
, the Dopler width,gtdV
, and the effective optical depth,gttau
, all with associated uncertainties,dgt*
.

bettermoments.methods.
collapse_gausshermite
(velax, data, rms, indices=None, chunks=1, **kwargs)¶ Collapse the cube by fitting a Gaussian line profile with an optically thick core to each pixel. This function is a wrapper of collapse_analytical which provides more details about the arguments.
Parameters:  velax (ndarray) – Velocity axis of the cube.
 data (ndarray) – Maksed intensity or brightness temperature array. The first axis must be the velocity axis.
 rms (float) – Noise per pixel in same units as
data
.  indices (Optional[list]) – A list of pixels described by
(y_idx, x_idx)
tuples to fit. If none are provided, will fit all pixels.  chunks (Optional[int]) – Split the cube into
chunks
sections and run the fits with separate processes throughmultiprocessing.pool
.
Returns: ghv0
(ndarray),dghv0
(ndarray),ghFnu
(ndarray),dghFnu
(ndarray),ghdV
(ndarray),dghdV
(ndarray),ghh3
(ndarray),dghh3
(ndarray),ghh4
(ndarray),dghh4
(ndarray):The Gaussian center,
ghv0
, the line peak,ghFnu
, the Dopler width,ghdV
, with additional expansion termsghh3`, the assymetry of the line and ``ghh4
, the saturation of the line core., All values come with their associated uncertainties,dgt*
.