erlab.analysis.gold

Fermi edge fitting.

Functions

correct_with_edge(darr, modelresult, *[, ...])

Corrects the given data array darr with the given values or fit result.

edge(gold, *[, along, bin_size, temp, ...])

Fit a Fermi edge to the given gold data.

poly(gold, *[, along, bin_size, temp, ...])

poly_from_edge(center[, weights, degree, ...])

quick_fit(darr, *[, eV_range, method, temp, ...])

Perform a Fermi edge fit on an EDC.

quick_resolution(darr[, ax])

Fit a Fermi edge to the given data and plot the results.

resolution(gold, angle_range, eV_range_edge)

Fit a Fermi edge and obtain the resolution from the corrected data.

resolution_roi(gold_roi, eV_range[, ...])

Fit a Fermi edge to the data and obtain the resolution.

spline_from_edge(center[, weights, lam, along])

erlab.analysis.gold.correct_with_edge(darr, modelresult, *, along='alpha', shift_coords=True, plot=False, plot_kw=None, **shift_kwargs)[source]

Corrects the given data array darr with the given values or fit result.

Parameters:
  • darr (DataArray) – The input data array to be corrected.

  • modelresult (ModelResult | Dataset | ndarray[tuple[Any, ...], dtype[floating]] | Callable | tuple[float, ...]) – The model result that contains the Fermi edge information. It can be an instance of lmfit.model.ModelResult, a numpy array containing the edge position at each angle, a fit result dataset that contains polynomial coefficients, a callable function that takes an array of angles and returns the corresponding energy value, or a tuple of coefficients for a polynomial (lowest order first).

  • along (str, default: "alpha") – The angular dimension name in the data. If None, it is assumed to be "alpha".

  • shift_coords (bool, default: True) – If True, the coordinates of the output data will be changed so that the output contains all the values of the original data. If False, the coordinates and shape of the original data will be retained, and only the data will be shifted. Defaults to False.

  • plot (bool, default: False) – Whether to plot the original and corrected data arrays. Defaults to False.

  • plot_kw (dict | None, default: None) – Additional keyword arguments for the plot. Defaults to None.

  • **shift_kwargs – Additional keyword arguments to erlab.analysis.transform.shift().

Returns:

corrected (xarray.DataArray) – The edge corrected data.

erlab.analysis.gold.edge(gold, *, along='alpha', angle_range, eV_range, bin_size=(1, 1), temp=None, vary_temp=False, bkg_slope=True, resolution=0.02, fast=False, method='least_squares', scale_covar=True, normalize=True, fixed_center=None, progress=True, parallel_kw=None, parallel_obj=None, return_full=False, drop_nans=False, **kwargs)[source]

Fit a Fermi edge to the given gold data.

Only successful fits with valid error estimates are returned.

Parameters:
  • gold (DataArray) – The gold data to fit the edge model to.

  • along (str, default: "alpha") –

    The dimension along which to parallelize the fitting. By default "alpha". It is better to choose the dimension with the largest number of points.

    If gold is chunked, this parameter is only used to specify the dimension along which to apply angle_range.

  • angle_range (tuple[float, float]) – The range of values along the along dimension to consider.

  • eV_range (tuple[float, float]) – The range of eV values to consider.

  • bin_size (tuple[int, int], default: (1, 1)) – The bin size for coarsening the gold data, by default (1, 1).

  • temp (float | None, default: None) – The temperature in Kelvins. If None, the temperature is inferred from the attributes, by default None

  • vary_temp (bool, default: False) – Whether to fit the temperature value during fitting, by default False.

  • bkg_slope (bool, default: True) – Whether to include a linear background above the Fermi level. If False, the background above the Fermi level is fit with a constant. Defaults to True.

  • resolution (float, default: 0.02) – The initial resolution value to use for fitting, by default 0.02.

  • fast (bool, default: False) – Whether to use the Gaussian-broadeded step function to fit the edge, by default False.

  • method (str, default: "least_squares") – The fitting method to use, by default "least_squares".

  • scale_covar (bool, default: True) – Whether to scale the covariance matrix, by default True.

  • fixed_center (float | None, default: None) – The fixed center value. If provided, the Fermi level will be fixed at the given value, by default None.

  • normalize (bool, default: True) – Whether to normalize the energy coordinates, by default True.

  • progress (bool, default: True) – Whether to display the fitting progress, by default True.

  • parallel_kw (dict | None, default: None) – Additional keyword arguments for parallel fitting, by default None.

  • parallel_obj (Parallel | None, default: None) – The joblib.Parallel object to use for fitting, by default None. If provided, parallel_kw will be ignored.

  • return_full (bool, default: False) – Whether to return the full fit results, by default False.

  • drop_nans (bool, default: False) – Whether to drop fits that resulted in NaN values, by default False. If True, the function will always return the computed data even for chunked inputs, because dropping NaNs requires computing all fit results. If return_full is True, this option is ignored.

  • **kwargs – Additional keyword arguments to fitting.

Returns:

  • center_arr, center_stderr – The fitted center values and their standard errors, returned when return_full is False.

  • fit_result – A dataset containing the full fit results, returned when return_full is True.

Return type:

tuple[DataArray, DataArray] | Dataset

erlab.analysis.gold.poly(gold, *, along='alpha', angle_range, eV_range, bin_size=(1, 1), temp=None, vary_temp=False, bkg_slope=True, resolution=0.02, fast=False, method='least_squares', normalize=True, degree=4, correct=False, crop_correct=False, parallel_kw=None, plot=True, fig=None, scale_covar=True, scale_covar_edge=True)[source]
erlab.analysis.gold.poly_from_edge(center, weights=None, degree=4, method='least_squares', scale_covar=True, along='alpha')[source]
erlab.analysis.gold.quick_fit(darr, *, eV_range=None, method='leastsq', temp=None, resolution=None, center=None, fix_temp=True, fix_center=False, fix_resolution=False, bkg_slope=True, plot=False, ax=None, plot_fit_kwargs=None, plot_data_kwargs=None, plot_line_kwargs=None, plot_span_kwargs=None, **kwargs)[source]

Perform a Fermi edge fit on an EDC.

This function is a convenient wrapper around DataArray.xlm.modelfit() that fits a Fermi edge to the given data.

If data with 2 or more dimensions is provided, the data is averaged over all dimensions except the energy prior to fitting.

Parameters:
  • darr (DataArray) – The input data to be fitted.

  • eV_range (tuple[float, float] | None, default: None) – The energy range to consider for fitting. If None, the entire energy range is used. Defaults to None.

  • method (str, default: "leastsq") – The fitting method to use that is compatible with lmfit. Defaults to “leastsq”.

  • temp (float | None, default: None) – The temperature value to use for fitting. If None, the temperature is inferred from the data attributes.

  • resolution (float | None, default: None) – The initial resolution value to use for fitting. If None, the resolution is set to 0.02, or to the 'TotalResolution' attribute if present.

  • center (float | None, default: None) – The initial center value to use for fitting. If None, the center is automatically guessed if fix_center is False. Otherwise, the center is fixed to 0.

  • fix_temp (bool, default: True) – Whether to fix the temperature value during fitting. Defaults to True.

  • fix_center (bool, default: False) – Whether to fix the Fermi level during fitting. If True, the Fermi level is fixed to 0. Defaults to False.

  • fix_resolution (bool, default: False) – Whether to fix the resolution value during fitting. Defaults to False.

  • bkg_slope (bool, default: True) – Whether to include a linear background above the Fermi level. If False, the background above the Fermi level is fit with a constant. Defaults to True.

  • plot (bool, default: False) – Whether to plot the result of the fit. Defaults to False.

  • ax (Axes | None, default: None) – The axes to plot the result on if plot is True. If None, the current axes are used.

  • plot_fit_kwargs (dict[str, Any] | None, default: None) – Additional keyword arguments for the fit plot, passed to matplotlib.axes.Axes.plot(). Defaults to None.

  • plot_data_kwargs (dict[str, Any] | None, default: None) – Additional keyword arguments for the data plot, passed to matplotlib.axes.Axes.plot(). Defaults to None.

  • plot_line_kwargs (dict[str, Any] | None, default: None) – Additional keyword arguments for the plot line that indicates the fitted center, passed to matplotlib.axes.Axes.axvline(). Defaults to None.

  • plot_span_kwargs (dict[str, Any] | None, default: None) – Additional keyword arguments for the plot span that indicates the fitted FWHM, passed to matplotlib.axes.Axes.axvspan(). Defaults to None.

  • **kwargs – Additional keyword arguments to DataArray.xlm.modelfit().

Returns:

result (xarray.Dataset) – The result of the fit.

Return type:

Dataset

erlab.analysis.gold.quick_resolution(darr, ax=None, **kwargs)[source]

Fit a Fermi edge to the given data and plot the results.

Deprecated since version 3.5.1: Use quick_fit() with plot=True instead.

erlab.analysis.gold.resolution(gold, angle_range, eV_range_edge, eV_range_fit=None, bin_size=(1, 1), degree=4, fast=False, method='leastsq', plot=True, parallel_kw=None, scale_covar=True)[source]

Fit a Fermi edge and obtain the resolution from the corrected data.

Deprecated since version 3.5.1: Use poly() and quick_fit() instead.

erlab.analysis.gold.resolution_roi(gold_roi, eV_range, fix_temperature=True, method='leastsq', plot=True, scale_covar=True)[source]

Fit a Fermi edge to the data and obtain the resolution.

Deprecated since version 3.5.1: Use quick_fit() instead.

erlab.analysis.gold.spline_from_edge(center, weights=None, lam=None, along='alpha')[source]