tuskitoo.SpectralExtraction.fitting module
- make_fit(ydata, num_source=2, initial_center=None, initial_separation=None, bound_sigma=None, fix_sep=None, fix_height=None, custom_expr=None, weights=None, param_limit=None, param_fix=None, param_value=None, verbose=False, distribution='gaussian')[source]
Fits a model to the provided data using either a Gaussian or Moffat profile.
Parameters:
- ydataarray-like
The dependent data (observations or measurements) to be fitted by the model.
- num_sourceint, optional, default=2
Number of sources (or components) to include in the fitting model.
- initial_centerfloat, int, or None, optional, default=None
Initial estimate for the center (mean or peak position) of each source/component.
- initial_separationlist or None, optional, default=None
Initial guess for the separation between the sources/components.
- bound_sigmaarray-like or None, optional, default=None
Bounds or constraints on the sigma (standard deviation) for components beyond the first.
- fix_seplist, bool, or None, optional, default=None
List of source indices for which the separation is fixed (i.e., not varied during fitting).
- fix_heightbool or None, optional, default=None
Flag to fix the height (amplitude) of the sources/components.
- custom_exprdict or None, optional, default=None
Dictionary mapping parameter names to custom expressions for the fitting function. Refer to https://lmfit.github.io/lmfit-py/index.html for details.
- weightsarray-like or None, optional, default=None
Weights for each data point in ydata; useful for weighted fitting.
- param_limitdict or None, optional, default=None
Dictionary specifying limits (min and max) for parameters. Example: {‘sigma_1’: (0.1, 5.0), ‘center_1’: (100, 200)}
- param_fixlist or None, optional, default=None
List of parameter names to be fixed at a specified value during fitting.
- param_valuedict or None, optional, default=None
Dictionary of initial parameter values. Example: {‘height_1’: 10.0, ‘sigma_1’: 2.0}
- verbosebool, optional, default=False
If True, prints detailed information during the fitting process.
- distributionstr, optional, default=”gaussian”
Type of distribution to use for fitting. Supported options are “gaussian” and “moffat”.
Returns:
- resultlmfit.model.ModelResult
The result of the fitting process, including fitted parameters and fit statistics.
Raises:
- ValueError:
If the provided distribution is not among the supported types.
- Parameters:
ydata (array)
- parallel_fit(image, error, num_source, pixel_limit=None, n_cpu=None, mask_list=[], **kwargs)[source]
Perform parallel fitting on a 2D image using multiple sources.
Parameters:
- image2D array-like
The image data to be fitted.
- error2D array-like
The error (sigma) associated with the image data.
- num_sourceint
Number of sources (or components) to include in the fitting model.
- pixel_limitlist or tuple of two ints, optional, default=None
Column indices [start, end] that limit the processing region. If None, all columns are processed.
- n_cpuint or None, optional, default=None
Number of CPU cores to use for parallel processing. Defaults to the total available cores.
- wavelenghtlist, optional, default=[]
(Not used yet) Intended to hold wavelength information for each pixel.
- mask_listlist, optional, default=[]
List of column ranges to mask (exclude) from fitting. Each element should be a two-element iterable (start, stop).
- **kwargsdict
- Additional keyword arguments to be passed to the make_fit function. These can include:
initial_center
initial_separation
bound_sigma
fix_sep
fix_height
custom_expr
weights
param_limit
param_fix
param_value
verbose
distribution
Returns:
- spectral_extraction_resultsdict
- A dictionary containing:
“value”: Fitted parameter values.
“std”: Parameter uncertainties.
“name_params”: Names of the fitted parameters.
“extra_params”: Extra fit statistics (e.g., chisqr, redchi, AIC, BIC, R-squared).
“normalized_image”: The normalized image used for fitting.
“normalize_matrix”: Normalization factors for each pixel column.
“num_source”: Number of sources used.
“distribution”: Distribution type used.
“mask”: The mask applied to the image.
“parameter_number”: Number of parameters per source.