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.King. fit_nd  (  a ,  a_ref ,  x=None ,  axis=0 ,  optimize_cov=False ,  func=linear_nd_fit ,  show=True ,  **kwargs  )[source]

Perform $n$-dimensional linear regression to create a King plot. The data are modified with the mass factors $\mu$, see qspec.physics.mass_factor. Choose between {"linear_nd_fit" (default), "linear_nd_monte_carlo"} for the fit routine.

Parameters:
ascalar_nd

An iterable of the mass numbers $A$ of the used isotopes.

a_refscalar_nd

An iterable of the mass numbers $A_\mathrm{ref}$ of the used reference isotopes.

xscalar_nd | None

The data as an iterable of vectors with standard deviations of shape (k, n, 2), where k is the number of data points/isotopes and n is the dimension of each vector. If None, x is inherited from King.x_abs.

axisint

The vector component to use for the parameterization. For example, a King plot with the isotope shifts of two transitions ["D1", "D2"] yields the slope $F_\mathrm{D2} / F_\mathrm{D1}$ if axis == 0.

optimize_covbool

If True, the origin vector of the straight line is optimized to yield the smallest covariances.

funcCallable | str

The fitting routine. Must be one of {"linear_nd_fit" (default), "linear_nd_monte_carlo"}.

showbool

Whether to plot the fit result.

kwargs

Additional keyword arguments are passed to func and King.plot.

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

The optimized parameters and their covariances. The resulting shapes are (2 * n, ) and (2 * n, 2 * n).

Raises:
ValueError

If neither x nor King.x_abs are given or if func is not supported.