Spectral utils#
The madcubapy.utils package offers a set of utils to perform operations on
spectra data.
Create spectral arrays#
The create_spectral_array() function creates an spectral
array by providing the following parameters:
nchan: Number of channels in the spectrum.cdelt: Width of a channel.crpix: Reference channel of the spectrum.crval: Value of the reference channel.
>>> from madcubapy.utils import create_spectral_array
>>> x_axis = create_spectral_array(nchan=5, cdelt=2, crpix=2, crval=10)
>>> x_axis
array([8, 10, 12, 14, 16])
Spectral data conversions#
The user can convert between rest frequency, observed frequency, and velocity
using the predefined functions rest_to_obs(),
obs_to_rest(), obs_to_vel(),
vel_to_obs(), rest_to_vel(), and
vel_to_rest(). The user can use different conventions:
Radio \(V = c \frac{f_0 - f}{f_0} ; f(V) = f_0 ( 1 - V/c )\)
Relativistic \(V = c \frac{f_0^2 - f^2}{f_0^2 + f^2} ; f(V) = f_0 \frac{\left(1 - (V/c)^2\right)^{1/2}}{(1+V/c)}\)
Here \(f_0\) is the rest frequency, \(f\) is the observed frequency, and \(V\) is the velocity.
For the input data, the functions accept single values and arrays of values,
which must be Quantity objects. As an example, here is how to
convert observed frequency to velocity using
obs_to_vel()
>>> from madcubapy.utils import obs_to_vel
>>> obs_freq_array = (263.35134466, 264.3413873) * u.GHz
>>> line_rest_freq = 266 * u. GHz
>>> velocity_array = obs_to_vel(obs_freq=obs_freq_array,
doppler_rest=line_rest_freq,
doppler_convention="relativistic")
>>> velocity_array
[3000, 1875.1495799 ] km / s
To avoid the use of several functions, madcubapy also offers the
SpectralData class to work with spectral data with
units and automatically perform conversions between frequencies, wavelengths,
photon energies, and Doppler velocities. Check
The SpectralData page to know more.