qspec logo qspec logo

A physics toolbox for laser spectroscopy.

Static Badge Static Badge Static Badge

Static Badge Static Badge

© 2026 Patrick Müller. All rights reserved.

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_fit with the syntax of scipy.optimize.curve_fit. Requires the optional dependency odrpack, which can be installed with pip 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 x data.

sigma_yscalar_nd | None

The $1\sigma$ uncertainty of the y data.

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. If p0 is None, 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 x data. Must have the same shape as x. If None, the errors are initialized with 0.

p0_fixedscalar_nd | None

A numpy array or an Iterable of bool values specifying whether to fix a parameter. Must have the same length as p0.

reportbool

Whether to print the result of the fit.

kwargs

Additional keyword arguments are passed to odrpack.odr_fit.

Returns:
(popt, pcov)tuple[ndarray, ndarray]

The optimal parameters and their covariance matrix.

Raises:
ImportError

If odrpack is not installed.

ValueError

If f has no parameters to optimize or if p0_fixed and p0 have different shapes.