fit_utils.py
fit_utils.py contains the package’s weighted linear fit and its associated return type. It is the densest module in the project because it combines statistics, input validation, and optional plotting, while also reusing the style system defined in plot_utils.
Main imports
Standard library:
dataclasses.dataclass,typing.TYPE_CHECKINGExternal libraries:
numpy as np,numpy.typing.ArrayLike,numpy.typing.NDArrayInternal imports from
plot_utils:_style_context,_validate_axis_limits,_validate_decimals,_validate_figsizeInternal imports from
stats_utils:_as_float_vector,weighted_mean,covariance,variance
What it exports
What it does
validate
x,y,sigma_y, and optionallysigma_xvalidate
decimals,tol, andmax_iterestimate slope and intercept with weighted least squares
update the weights iteratively when uncertainties on
xare also presentcompute residuals,
chi2,reduced_chi2, correlation, and other diagnosticscreate, when requested, a matplotlib figure with a fit panel and a residuals panel, using the same style system as
histogram