window_moments#

mufasa.moment_guess.window_moments(spec, window_hwidth=4.0, v_atpeak=None, signal_mask=None)[source]#

Calculate the zeroth, first, and second moments of a spectrum or cube within a specified velocity window.

Parameters:
  • spec (pyspeckit.Cube, pyspeckit.spectrum.classes.Spectrum, or SpectralCube) – The spectrum or cube for which moments are calculated. Can be a pyspeckit.Cube, pyspeckit.spectrum.classes.Spectrum, or SpectralCube object.

  • window_hwidth (float, optional) – The half-width of the spectral window in km/s used to calculate moments. This is useful for isolating hyperfine lines. Default is 4.0.

  • v_atpeak (float, numpy.ndarray, or None, optional) – The velocity or velocity map (in km/s) around which to center the moment calculation. If None, it will be estimated from the spectrum or cube. Default is None.

  • signal_mask (numpy.ndarray or None, optional) – An optional mask to apply when estimating the velocity peak (v_atpeak). Useful for suppressing noise when determining the peak. Default is None.

Returns:

A tuple containing: - Zeroth moment (m0) as a numpy array. - First moment (m1) as a numpy array in km/s. - Second moment (m2) as a numpy array in km/s.

Return type:

tuple of numpy.ndarray

Raises:

Exception – If the input spec is not a supported type.

Notes

  • This function acts as a wrapper to calculate moments for different types of inputs (SpectralCube, pyspeckit.Cube, or pyspeckit.spectrum).

  • For SpectralCube, v_atpeak as a map is not currently supported.

Examples

For a SpectralCube object:

>>> from spectral_cube import SpectralCube
>>> cube = SpectralCube.read("example_cube.fits")
>>> m0, m1, m2 = window_moments(cube, window_hwidth=3.0, v_atpeak=5.0)

For a pyspeckit.spectrum.classes.Spectrum:

>>> import pyspeckit
>>> spec = pyspeckit.Spectrum("example_spectrum.fits")
>>> m0, m1, m2 = window_moments(spec, window_hwidth=2.0)