Fit Manager#

Fit manager for handling curve fitting operations.

This module manages fit operations for curves, handles fit parameter storage and retrieval, and coordinates between UI and fit calculations.

class mdaviz.fit_manager.FitData(model_name: str, fit_result: FitResult, x_range: Tuple[float, float] | None = None, visible: bool = True)[source]#

Container for fit data associated with a curve.

class mdaviz.fit_manager.FitManager(*args: Any, **kwargs: Any)[source]#

Manages fit operations for curves.

addFit(curveID: str, model_name: str, x_data: numpy.ndarray, y_data: numpy.ndarray, x_range: tuple[float, float] | None = None, initial_params: dict[str, float] | None = None, bounds: dict[str, tuple[float, float]] | None = None) None[source]#

Add or replace a fit for a curve.

Parameters: - curveID: ID of the curve to fit - model_name: Name of the fit model to use - x_data: X values for fitting - y_data: Y values for fitting - x_range: Optional range of x values to use for fitting - initial_params: Optional initial parameter guesses - bounds: Optional parameter bounds

Raises: - ValueError: If model_name is not available or fit fails

clearAllFits() None[source]#

Remove all fits from all curves.

fitAdded#

alias of str

fitRemoved#

alias of str

fitUpdated#

alias of str

fitVisibilityChanged#

alias of str

getAllFits() Dict[str, Dict[str, FitData]][source]#

Get all fits for all curves (maintains compatibility with existing code).

Returns: - Dictionary mapping curve IDs to their single fit

getCurveFits(curveID: str) Dict[str, FitData][source]#

Get the fit for a curve (maintains compatibility with existing code).

Parameters: - curveID: ID of the curve

Returns: - Dictionary with single fit data if exists, empty dict otherwise

getFitCount(curveID: str) int[source]#

Get the number of fits for a curve.

Parameters: - curveID: ID of the curve

Returns: - Number of fits for the curve (0 or 1)

getFitCurveData(curveID: str) Tuple[numpy.ndarray, numpy.ndarray] | None[source]#

Get the fitted curve data for plotting.

Parameters: - curveID: ID of the curve

Returns: - Tuple of (x_fit, y_fit) arrays if found, None otherwise

getFitData(curveID: str) FitData | None[source]#

Get fit data for a curve.

Parameters: - curveID: ID of the curve

Returns: - FitData object if found, None otherwise

getFitParameters(curveID: str) Dict[str, float] | None[source]#

Get fit parameters for a curve.

Parameters: - curveID: ID of the curve

Returns: - Dictionary of parameter names and values if found, None otherwise

getFitQualityMetrics(curveID: str) Dict[str, float] | None[source]#

Get fit quality metrics for a curve.

Parameters: - curveID: ID of the curve

Returns: - Dictionary of quality metrics if found, None otherwise

getFitUncertainties(curveID: str) Dict[str, float] | None[source]#

Get fit parameter uncertainties for a curve.

Parameters: - curveID: ID of the curve

Returns: - Dictionary of parameter names and uncertainties if found, None otherwise

get_available_models() dict[str, FitModel][source]#

Get available fit models.

Returns: - Dictionary mapping model names to FitModel instances

hasFits(curveID: str) bool[source]#

Check if a curve has a fit.

Parameters: - curveID: ID of the curve

Returns: - True if curve has a fit, False otherwise

isFitVisible(curveID: str) bool[source]#

Check if a fit is visible.

Parameters: - curveID: ID of the curve

Returns: - True if fit is visible, False otherwise

removeAllFits(curveID: str) None[source]#

Remove the fit from a curve (alias for removeFit).

Parameters: - curveID: ID of the curve

removeFit(curveID: str) None[source]#

Remove the fit from a curve.

Parameters: - curveID: ID of the curve

setFitVisibility(curveID: str, visible: bool) None[source]#

Set visibility of a fit curve.

Parameters: - curveID: ID of the curve - visible: Whether the fit curve should be visible