get_residual#
- mufasa.UltraCube.get_residual(cube, model, planemask=None)[source]#
Calculate the residual between the data cube and the model cube.
The residual is calculated as the difference between the spectral data in the cube and the corresponding model values. Optionally, a 2D spatial mask (planemask) can be applied to restrict the calculation to specific spatial regions.
- Parameters:
cube (SpectralCube) – A spectral cube object containing the observed data. It can be a dask-enabled cube or a standard numpy-based cube.
model (numpy.ndarray) – A 3D array representing the model cube, where the dimensions match those of the data cube (spectral axis as the first dimension).
planemask (numpy.ndarray, optional) – A 2D boolean array specifying the spatial pixels for which residuals should be calculated. If provided, only these regions will be used in the calculation. Default is None.
- Returns:
The residual array, calculated as the difference between the cube’s data and the model values. The returned type matches the cube’s data type (e.g., dask array if the cube uses dask, or numpy array otherwise).
- Return type:
numpy.ndarray or dask.array.Array
Notes
If planemask is provided, the residuals are calculated only for the specified spatial pixels, which can reduce computation time.
Handles memory-efficient computation when dask is enabled.