- qspec.analyze. odr_fit ( f , x , y , sigma_x=None , sigma_y=None , p0=None , delta0=None , p0_fixed=None , report=False , **kwargs )[source]
-
Fit a function to data with uncertainties in both $x$ and $y$ using the orthogonal distance regression (ODR) routine
odrpack.odr_fitwith the syntax ofscipy.optimize.curve_fit. Requires the optional dependencyodrpack, which can be installed withpip install qspec[odr].- Parameters:
-
- fCallable
The model function $f$ to fit to the data.
- xscalar_nd
The $x$ data.
- yscalar_nd
The $y$ data.
- sigma_xscalar_nd | None
The $1\sigma$ uncertainty of the
xdata.- sigma_yscalar_nd | None
The $1\sigma$ uncertainty of the
ydata.- p0scalar_nd | None
A numpy array or an Iterable of the initial guesses for the parameters. Must have at least the same length as the minimum number of parameters required by the function
f. Ifp0isNone, 1 is taken as an initial guess for all non-keyword parameters.- delta0scalar_nd | None
A numpy array or an Iterable of the initial guesses for the errors of the
xdata. Must have the same shape asx. IfNone, the errors are initialized with 0.- p0_fixedscalar_nd | None
A numpy array or an Iterable of
boolvalues specifying whether to fix a parameter. Must have the same length asp0.- reportbool
Whether to print the result of the fit.
- kwargs
Additional keyword arguments are passed to
odrpack.odr_fit.
- Returns:
- Raises:
-
- ImportError
If
odrpackis not installed.- ValueError
If
fhas no parameters to optimize or ifp0_fixedandp0have different shapes.