get_refit_guesses#
- mufasa.master_fitter.get_refit_guesses(ucube, mask, ncomp, method='best_neighbour', refmap=None, structure=None)[source]#
Generate initial guesses for refitting based on neighboring pixels or convolution.
- Parameters:
ucube (UltraCube) – The UltraCube object containing the spectral data and fitted parameters.
mask (numpy.ndarray) – A 2D boolean mask indicating the pixels to be refitted.
ncomp (int) – The number of components for which the guesses are being generated.
method ({'best_neighbour', 'convolved'}, optional) – The method used for generating guesses: - ‘best_neighbour’: Uses the nearest neighbor with the highest reference value from refmap. - ‘convolved’: Uses a Gaussian convolution to interpolate guesses from surrounding pixels. Defaults to ‘best_neighbour’.
refmap (numpy.ndarray, optional) – A 2D array of reference values used to identify the best neighbor for each pixel in the mask. Required if method=’best_neighbour’.
structure (numpy.ndarray, optional) – A binary structure defining the neighborhood for finding the best neighbor. Defaults to a 3x3 square neighborhood.
- Returns:
guesses (numpy.ndarray) – A 3D array of guesses with shape (parameters, y, x), where parameters corresponds to the number of parameters in the model.
mask (numpy.ndarray) – A 2D boolean mask indicating the valid pixels with generated guesses.
- Raises:
ValueError – If refmap is not provided when method=’best_neighbour’.
TypeError – If refmap is not a numpy array.
Notes
When using the ‘best_neighbour’ method, the function identifies the neighbor with the maximum value in refmap for each masked pixel and uses its parameters as the guess.
When using the ‘convolved’ method, a Gaussian kernel is applied to interpolate guesses for each parameter.
If no valid neighbors or guesses can be found, the corresponding pixel in the mask is set to False.
Examples
>>> guesses, updated_mask = get_refit_guesses(ucube, mask, ncomp=2, method='best_neighbour', refmap=lnkmap) >>> # Uses the best neighbor method to generate guesses for 2-component fitting.
>>> guesses, updated_mask = get_refit_guesses(ucube, mask, ncomp=1, method='convolved') >>> # Uses convolution to generate guesses for 1-component fitting.