boilercore.fits#

Model fits.

Module Contents#

Classes#

Fit

Model fit.

Functions#

fix_model

Fix edge-cases of lambdify where all inputs must be arrays.

get_model_errors

Get error parameters for model parameters.

fit_and_plot

Get fits and errors for project model and plot the results.

fit_from_params

Get fits and errors for project model.

fit

Get fits and errors.

get_guesses

Compose guesses.

get_bounds

Compose bounds.

plot_fit

Plot a model fit.

get_model_with_error

Evaluate the model for x and return y with errors.

combine_params_and_errors

Return parameters with errors given mappings, one with _err-suffixed keys.

Data#

EPS

Minimum positive value to avoid divide-by-zero for affected parameters.

MIN_CONVECTION_COEFF

Minimum positive convection coefficient to avoid instability of exponents.

INIT_CONVECTION_COEFF

An initial guess not too close to zero to avoid iteration instability.

MIN_TEMP

Minimum temperature to avoid instability near absolute zero.

XY_COLOR

Default color for measurement points.

CONFIDENCE_INTERVAL_95

Confidence interval for a single sample from a student’s t-distribution.

API#

boilercore.fits.EPS: float#

None

Minimum positive value to avoid divide-by-zero for affected parameters.

boilercore.fits.MIN_CONVECTION_COEFF#

0.001

Minimum positive convection coefficient to avoid instability of exponents.

boilercore.fits.INIT_CONVECTION_COEFF#

1.0

An initial guess not too close to zero to avoid iteration instability.

boilercore.fits.MIN_TEMP#

0.001

Minimum temperature to avoid instability near absolute zero.

boilercore.fits.fix_model(
f,
) collections.abc.Callable[..., Any]#

Fix edge-cases of lambdify where all inputs must be arrays.

See the notes section in the link below where it says, “However, in some cases the generated function relies on the input being a numpy array.”

https://docs.sympy.org/latest/modules/utilities/lambdify.html#sympy.utilities.lambdify.lambdify

boilercore.fits.get_model_errors(
params: list[sympy.Symbol],
) list[str]#

Get error parameters for model parameters.

class boilercore.fits.Fit#

Model fit.

fit_method: Literal[trf, dogbox]#

‘trf’

Model fit method.

independent_params: list[str]#

‘field(…)’

Independent parameters.

free_params: list[str]#

‘field(…)’

Free parameters.

fixed_params: list[str]#

‘field(…)’

Parameters to fix. Evaluated before fitting, overridable in code.

bounds: dict[str, tuple[float, float]]#

‘field(…)’

Bounds of model parameters.

values: dict[str, float]#

‘field(…)’

Values of model parameters.

property errors: list[str]#

Error parameters for each free parameter.

property fixed_values: dict[str, float]#

Fixed values for each fixed parameter.

property fixed_errors: list[str]#

Error parameters for each fixed parameter.

property free_errors: list[str]#

Error parameters for each free parameter.

property params_and_errors: list[str]#

Model parameters and their errors.

get_models(
models: pathlib.Path,
) tuple[collections.abc.Callable[..., Any], collections.abc.Callable[..., Any]]#

Unpickle the model function for fitting data.

boilercore.fits.XY_COLOR#

(0.2, 0.2, 0.2)

Default color for measurement points.

boilercore.fits.CONFIDENCE_INTERVAL_95#

None

Confidence interval for a single sample from a student’s t-distribution.

boilercore.fits.fit_and_plot(
model: Any,
params: boilercore.fits.Fit,
x: Any,
y: Any,
y_errors: Any = None,
confidence_interval=CONFIDENCE_INTERVAL_95,
ax: matplotlib.axes.Axes | None = None,
run: str | None = None,
) tuple[dict[str, float], dict[str, float]]#

Get fits and errors for project model and plot the results.

boilercore.fits.fit_from_params(
model: Any,
params: boilercore.fits.Fit,
x: Any,
y: Any,
y_errors: Any = None,
confidence_interval: float = CONFIDENCE_INTERVAL_95,
method: Literal[trf, dogbox] = 'trf',
) tuple[dict[str, float], dict[str, float]]#

Get fits and errors for project model.

boilercore.fits.fit(
model: Any,
free_params: list[str],
initial_values: collections.abc.Mapping[str, boilercore.types.Guess],
model_bounds: collections.abc.Mapping[str, boilercore.types.Bound],
x: Any,
y: Any,
y_errors: Any = None,
confidence_interval: float = CONFIDENCE_INTERVAL_95,
method: Literal[trf, dogbox] = 'trf',
) tuple[Any, Any]#

Get fits and errors.

boilercore.fits.get_guesses(
params: collections.abc.Sequence[str],
guesses: collections.abc.Mapping[str, boilercore.types.Guess],
) tuple[boilercore.types.Guess, ...]#

Compose guesses.

boilercore.fits.get_bounds(
params: collections.abc.Sequence[str],
bounds: collections.abc.Mapping[str, boilercore.types.Bound],
) tuple[boilercore.types.Bound, ...]#

Compose bounds.

boilercore.fits.plot_fit(
model: Any,
x: Any,
y: Any,
y_0: float,
params: collections.abc.Mapping[str, Any],
errors: collections.abc.Mapping[str, Any],
y_errors: collections.abc.Sequence[Any] | None = None,
ax: matplotlib.axes.Axes | None = None,
run: str | None = None,
)#

Plot a model fit.

boilercore.fits.get_model_with_error(
model,
x,
params,
errors,
)#

Evaluate the model for x and return y with errors.

boilercore.fits.combine_params_and_errors(
params: collections.abc.Mapping[str, Any],
errors: collections.abc.Mapping[str, Any],
) dict[str, Any]#

Return parameters with errors given mappings, one with _err-suffixed keys.