get_chisq#
- mufasa.UltraCube.get_chisq(cube, model, expand=20, reduced=True, usemask=True, mask=None)[source]#
Calculate the chi-squared or reduced chi-squared value for a spectral cube.
This function computes the chi-squared goodness-of-fit statistic by comparing the observed data in the cube with a provided model. Optionally, the calculation can be restricted to masked regions and expanded spectral regions.
- Parameters:
cube (SpectralCube) – The observed spectral cube containing the data to compare against the model.
model (numpy.ndarray) – A 3D array representing the model cube, which must have the same shape as the input cube.
expand (int, optional) – Number of spectral channels to expand the mask region. Default is 20.
reduced (bool, optional) – If True, compute the reduced chi-squared value by normalizing with the degrees of freedom. If False, compute the standard chi-squared value. Default is True.
usemask (bool, optional) – If True, apply a mask to exclude invalid regions from the calculation. If no mask is provided, regions where the model is zero are excluded. Default is True.
mask (numpy.ndarray, optional) – A 3D boolean array specifying regions to include in the calculation. If None, a mask is automatically derived from the model.
- Returns:
A 2D array representing the chi-squared (or reduced chi-squared) value at each spatial pixel in the cube.
- Return type:
Notes
The expand parameter allows users to extend the region of interest by a specified number of spectral channels around the model.
The reduced chi-squared value is normalized by the number of degrees of freedom.
The residuals between the cube and model are weighted using the mask.
- Raises:
ValueError – If the cube and model dimensions do not match.
Examples
>>> from spectral_cube import SpectralCube >>> import numpy as np >>> cube = SpectralCube.read("example_cube.fits") >>> model = np.random.random(cube.shape) >>> chisq = get_chisq(cube, model, expand=10, reduced=True) >>> print(chisq)