This module provides tools for analyzing and visualizing X-ray Photoelectron Spectroscopy (XPS) data. It enables users to:
- Load spectra from
.TXTfiles (exported from measurement instruments). - Extract peaks within user-defined energy ranges.
- Subtract background from peaks.
- Integrate peak areas.
- Smooth data.
- Find peak positions via polynomial fitting.
- Plot raw and corrected spectra.
The module is organized into two main classes:
Component→ Represents a spectrum (entire dataset for one element or orbital).Peak→ Represents a specific spectral peak within aComponent.
The following Python packages are required:
pandasnumpymatplotlibscipy
Install them with:
pip install pandas numpy matplotlib scipyThe module expects input data files in the following format:
data/
├── AM25_<component_name>.TXT
Where <component_name> is the name passed to the Component class.
Each .TXT file must be tab-delimited with a header of 4 lines, followed by columns:
KE BE CPS Background
from xps_module import Component# Load an XPS spectrum (e.g., Oxygen 1s)
comp = Component("O1s")comp.plot_BE(title="O1s Spectrum")# Define peaks by specifying energy intervals (in eV)
comp.select_peaks([(528, 534)])
# Access the first peak
peak = comp.peaks[0]# Subtract background using intervals outside the peak
peak.subtract_background([(528, 529), (533, 534)], deg=1, plot=True)peak.integrate()
print("Integrated area:", peak.Integral)peak.smooth(deg=5)peak.find_peak_position((529, 532))
print("Peak position:", peak.peak_pos)
print("Peak height:", peak.height)peak.plot_raw_spectrum()
peak.plot_corrected_spectrum(title="Corrected O1s Spectrum")Represents a full XPS spectrum.
-
__init__(componenet_name: str)Loads spectrum fromdata/AM25_<component_name>.TXT. -
select_peaks(intervals, energy_scale='BE')Extracts peaks from the spectrum.intervals: list of(min_energy, max_energy)energy_scale:"BE"(default) or"KE"
-
plot_BE(title='BE spectrum')Plots the binding energy spectrum.
Represents an individual peak extracted from a Component.
-
subtract_background(intervals, deg=1, plot=False)Fits polynomial background using side intervals and subtracts it. -
integrate()Computes integrated peak area. -
smooth(deg=3)Smooths spectrum via moving average. -
find_peak_position(interval)Estimates peak position and height with quadratic fit. -
plot_raw_spectrum()Plots the original (uncorrected) spectrum. -
plot_corrected_spectrum(title)Plots spectrum after background subtraction.
# Load spectrum
comp = Component("O1s")
# Select region of interest
comp.select_peaks([(528, 534)])
peak = comp.peaks[0]
# Background subtraction
peak.subtract_background([(528, 529), (533, 534)], plot=True)
# Integration
peak.integrate()
print("Area under peak:", peak.Integral)
# Peak position
peak.find_peak_position((529, 532))
print("Peak at", peak.peak_pos, "eV with height", peak.height)
# Plot final result
peak.plot_corrected_spectrum("Corrected O1s Spectrum")