analysis.xps#

pyleem.analysis.xps.shirley_background(profile, base_diff, iterations=20, tol=1e-6)[source]#

Calculate Shirley background for XPS spectra.

Implements iterative Shirley algorithm for background subtraction. Background at each point is proportional to integrated peak area toward higher binding energy. Here we simply assume that the x axis is in descending BE order.

Modified from code by Kane O’Donnell.

Parameters:
  • profile (ndarray) – Intensity values of spectrum.

  • base_diff (float) – Difference between left and right baseline intensities.

  • iterations (int) – Maximum iterations.

  • tol (float) – Convergence tolerance.

Returns:

Calculated background intensity values.

Return type:

ndarray

pyleem.analysis.xps.pseudo_voigt_fits(peak_constraints)[source]#

Create composite pseudo-Voigt model for XPS peak fitting.

Combines multiple pseudo-Voigt peaks (Gaussian-Lorentzian mixture) into single fitting model with optional parameter constraints.

The constraints are nested dictionaries with the following structure:

Example:

{
    "label": {
        "param": {"value": value, "min": min, "max": max, "vary": vary}
    }
}
Parameters:

peak_constraints (dict) – Dictionary of peak constraints for lmfit.

Returns:

Composite model and initial parameters.

Return type:

tuple(lmfit.Model, lmfit.Parameters)

pyleem.analysis.xps.parameter_estimation(profile, abscissa, num_peaks, peak_prominence=0.1, smooth_sigma=None)[source]#

Estimate initial parameters for XPS peak fitting.

Uses scipy peak detection to locate peaks and estimate positions, widths, and areas. The values are estimates for automatic fitting.

Parameters:
  • profile (ndarray) – XPS intensity profile.

  • abscissa (ndarray) – XPS binding energy abscissa.

  • num_peaks (int) – Expected number of peaks.

  • peak_prominence (float) – Minimum prominence as a fraction of signal range.

  • smooth_sigma (int) – Optional Gaussian smoothing sigma for detection.

Returns:

Peak centers, estimated widths, and areas.

Return type:

tuple(ndarray, ndarray, ndarray)

pyleem.analysis.xps.parameter_constraint(profile, abscissa, num_peaks, peak_prominence=0.1, smooth_sigma=None)[source]#

Create parameter constraints dictionary for XPS fitting.

Parameters:
  • profile (ndarray) – XPS intensity profile.

  • num_peaks (int) – Number of peaks to fit.

  • peak_prominence (float) – Minimum prominence as a fraction of signal range.

  • smooth_sigma (float) – Optional Gaussian smoothing sigma for detection.

Returns:

Constraints dictionary for lmfit.

Return type:

dict

pyleem.analysis.xps.xps_background(profile, baseline=None, baseline_average=10)[source]#

Calculate the Shirley background with baseline offset.

pyleem.analysis.xps.fit_range_mask(abscissa, fit_range=None)[source]#

Return a boolean mask for a fit range.

The fit range is a tuple of (left, right) values.

pyleem.analysis.xps.fit_xps(profile, abscissa, baseline=None, baseline_average=10, num_peaks=None, peak_prominence=0.1, peak_constraints=None, fit_range=None, smooth_sigma=None)[source]#

Fit an XPS profile with automatic or manual peak constraints.

If peak_constraints is provided, those manual constraints define the peaks. Otherwise, num_peaks controls automatic detection on the background-subtracted signal. fit_range selects the region used for the Shirley background.

class pyleem.analysis.xps.XPSCalibration(readers, roi=None, onset=0)[source]#

Bases: Analyzer

Config for XPS analyzer.

Configuration files are recommended due to the complexity of the analysis.

[reader]
paths = ["data_0eV.dat", "data_1eV.dat", "data_2eV.dat"]
metadata = [
    {"Beam Energy" = [400, "eV"]},
    {"Beam Energy" = [400, "eV"]},
    {"Beam Energy" = [400, "eV"]},
]

[task]
baselines = [[197, 100], [197, 100], [197, 100]]
num_peaks = 1
# optional
ref_index = 0
ref_value = 285.0
peak_prominence = 0.1
analyze(num_peaks, baselines, pixel_per_ev=None, peak_shift=None, ref_index=None, ref_value=None, **fit_kwargs)[source]#

Analyze XPS spectrum with background subtraction.

Parameters:
  • num_peaks (int) – Number of peaks to fit.

  • baseline (tuple) – Tuple (left, right) background intensities.

  • peak_prominence (float) – Peak detection prominence.

Returns:

Fit result and Shirley background.

Return type:

tuple(lmfit.ModelResult, ndarray)

class pyleem.analysis.xps.XPSAnalyzer(readers, roi, pixel_per_ev, peak_shift, onset=0)[source]#

Bases: SpectraBase

Analyzer for X-ray photoelectron spectroscopy data.

Handles energy calibration and provides binding energy scales.

Parameters:
  • readers (list) – List of readers.

  • roi (ROI) – Region of interest for profile extraction.

  • pixel_per_ev (float) – Pixel per eV.

  • peak_shift (float) – Peak shift.

  • onset (int) – Onset index.

fit(index, num_peaks=None, baseline=None, peak_prominence=0.1, peak_constraints=None, fit_range=None, smooth_sigma=None)[source]#

Fit XPS spectrum with background subtraction.

Parameters:
  • num_peaks (int) – Number of peaks to fit.

  • baseline (tuple) – Tuple (left, right) background intensities.

  • peak_prominence (float) – Peak detection prominence fraction.

  • peak_constraints (dict) – Optional manual peak constraints.

  • fit_range (tuple) – Optional range to use for background and fitting.

  • smooth_sigma (float) – Optional Gaussian smoothing sigma.

Returns:

Fit result.

Return type:

dict

get_binding_energy(index)[source]#

Return the binding energy for a given index.

plot_profile(index, ax=None, show_fit=False, **fit_kwargs)[source]#

Plot XPS fit results.

Parameters:
  • axes (tuple) – Tuple of two axes (profile, residuals).

  • result (lmfit.ModelResult) – Fitting result object.

  • background (ndarray) – Shirley background array.