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  (  a ,  a_ref ,  x=None ,  y=None ,  xy=(0, 1) ,  func=york_fit ,  alpha=0 ,  find_alpha=False ,  show=True ,  **kwargs  )[source]

Perform $2$-dimensional linear regression to create a King plot, see linear_alpha_fit. The data are modified with the mass factors $\mu$, see qspec.physics.mass_factor. Choose between {"york_fit" (default), "linear_fit", "linear_monte_carlo"} for the fit routine. Use a parameter alpha to optimize the correlation coefficient between the $y$-intercept and the slope.

Parameters:
aarray_like

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

a_refarray_like

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

xarray_like | None

The $x$ data and their standard deviations as shape (len(a), 2) arrays. Either the differences of mean-square nuclear charge radii $\delta\langle r^2\rangle^{A,A_\mathrm{ref}}$ or $\Lambda^{A,A_\mathrm{ref}}$ (fm$^2$), plotted with mode="radii", or isotope shifts $\delta\nu_x^{A,A_\mathrm{ref}}$ (MHz), plotted with mode="shifts", see King.plot. If None, x is inherited from King.x_abs.

yarray_like | None

The isotope shifts $\delta\nu_y^{A,A_\mathrm{ref}}$ and their standard deviations as shape (len(a), 2) arrays (MHz). If None, y is inherited from King.x_abs.

xytuple[int, int]

A 2-tuple of indices (ix, iy), used to select the two plot axes from King.x_abs. Only used if x or y is not specified. The default value is (0, 1), fitting the second against the first axis.

funcstr | Callable

The fitting routine. Must be one of {"york_fit" (default), "linear_fit", "linear_monte_carlo"}.

alphascalar

An $x$-axis offset $\alpha$ to reduce the correlation coefficient between the $y$-intercept and the slope. Expected unit: (u fm$^2$) or (u MHz).

find_alphabool

Whether to search for the best alpha. Uses the given alpha as a starting point. May not give the desired result if alpha was initialized too far from its optimal value.

showbool

Whether to plot the fit result.

kwargs

Additional keyword arguments are passed to King.plot.

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

The best y-intercept and slope and their covariance matrix. The final alpha can be accessed through King.alpha.

Raises:
ValueError

If less than 3 data points are given, if neither x (y) nor King.x_abs are given, or if func is not supported.