Python API¶
lineshapes.Model ¶
Composable optical-constant model; calling it returns delta + 1j*beta.
Build by chaining; every builder method mutates the model and returns it. Energies are in eV.
delta is the exact Hilbert partner of beta for each peak (delta < 0 below a resonance),
and amp is the height of beta at the peak center for every lineshape.
Example
The model also exposes a flat parameter vector (params, param_names, set_params) for
fitting without rebuilding, and bind to fix an energy grid for repeated evaluation. A new
model is empty and evaluates to zero.
params
property
¶
Flat parameter vector: each component's parameters in insertion order, then
continuum.bkg, continuum.slope, scale, shift.
param_names
property
¶
Names matching params, e.g. 'gaussian[0].e0', 'step[1].height', 'scale'.
gaussian ¶
Add a Gaussian peak with its Dawson-function delta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e0
|
float
|
Center in eV. |
required |
width
|
float
|
1/e half-width in eV: beta falls to |
required |
amp
|
float
|
Peak height of beta. |
required |
lorentzian ¶
Add a Lorentzian peak, delta + i beta = amp*gamma / (E - e0 - i*gamma).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e0
|
float
|
Center in eV. |
required |
gamma
|
float
|
Half width at half maximum in eV. |
required |
amp
|
float
|
Peak height of beta. |
required |
voigt ¶
Add an exact Voigt peak (Gaussian convolved with Lorentzian), via the Faddeeva function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e0
|
float
|
Center in eV. |
required |
sigma
|
float
|
Gaussian standard deviation in eV. |
required |
gamma
|
float
|
Lorentzian half width at half maximum in eV ( |
required |
amp
|
float
|
Peak height of beta. |
required |
pseudo_voigt ¶
Add a pseudo-Voigt eta*Lorentzian + (1-eta)*Gaussian sharing one FWHM.
Its delta is exact by linearity. It is a single component with its own eta parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e0
|
float
|
Center in eV. |
required |
fwhm
|
float
|
Full width at half maximum of both parts, in eV. |
required |
eta
|
float
|
Lorentzian fraction in |
required |
amp
|
float
|
Peak height of beta. |
required |
continuum ¶
Set the linear continuum in beta, bkg + slope*E (replaces any previous one).
step ¶
Add an erf ionization step to beta: 0.5*height*(1 + erf((E-e0)/width)) + decay*max(E-e0, 0).
Only beta is modeled analytically; the matching delta belongs in the fixed delta table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e0
|
float
|
Edge energy in eV. |
required |
width
|
float
|
Erf width in eV. |
required |
height
|
float
|
Step height of beta. |
required |
decay
|
float
|
Linear post-edge slope added above |
0.0
|
delta_table ¶
Set the fixed continuum delta (e.g. computed once with kkcalc), added to delta.
Interpolated linearly like numpy.interp and clamped to the end values outside the table.
It is not a fit parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
energy
|
FloatArray
|
Strictly increasing energies in eV. |
required |
delta
|
FloatArray
|
Delta values at |
required |
scale ¶
Set the overall multiplicative scale (e.g. the density relative to a unit-density table).
set_params ¶
Set all parameters from a flat vector.
Raises:
| Type | Description |
|---|---|
ValueError
|
On a wrong length or an invalid value (non-positive width, |
bind ¶
Bind the model to a fixed energy grid for fitting loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
energy
|
FloatArray
|
Energy grid in eV. |
required |
cache
|
bool
|
Keep each component's contribution ( |
True
|
__call__ ¶
__call__(energy: FloatArray, params: FloatArray | None = None, parallel: bool = False) -> ComplexArray
Evaluate delta + 1j*beta on energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
energy
|
FloatArray
|
1-D float64 energies in eV (sorted input is fastest). |
required |
params
|
FloatArray | None
|
Evaluate at this parameter vector without modifying the model. |
None
|
parallel
|
bool
|
Use all cores; results are identical to the single-core path. |
False
|
lineshapes.Evaluator ¶
A Model bound to a fixed energy grid; recomputes only the components that changed.
Created by Model.bind. Changing scale, continuum.bkg or continuum.slope costs no
peak work; changing shift recomputes every component.
Example
__call__ ¶
Evaluate at params (or the current parameters).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
FloatArray | None
|
Flat parameter vector to set first. |
None
|
out
|
ComplexArray | None
|
Optional contiguous complex128 array of the grid length to write into. |
None
|
lineshapes.datasets ¶
Example datasets shipped with the package: ZnPc and Alq3 carbon K-edge spectra.
All optical-constant tables are per unit density (1 g/cm^3). The continuum of each material is
fixed ahead of time (bare-atom beta, with its delta from kkcalc2); the peaks are fit on top.
Provenance and the generating script: tools/make_example_data.py.
Tables (see available):
| name | columns |
|---|---|
znpc_nexafs |
energy_ev, theta_deg, mu_cm2_per_g, intensity_raw (five angles) |
znpc_dft_clusters, alq3_dft_clusters |
energy_ev, amplitude, sigma_ev (DFT transition clusters) |
alq3_oc_tey |
energy_ev, delta, beta (optical constants from total-electron-yield XAS) |
alq3_oc_model |
energy_ev, delta, beta (building-block model optical constants) |
lineshapes.units ¶
Unit conversions between absorption measurements and the optical constant beta.
mu_to_beta ¶
Convert a mass absorption coefficient to beta: beta = mu * rho * lambda / (4 pi).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
energy_ev
|
ArrayLike
|
Photon energy in eV. |
required |
mu_cm2_per_g
|
ArrayLike
|
Mass absorption coefficient in cm^2/g. |
required |
density_g_cm3
|
float
|
Mass density in g/cm^3. The example tables are per unit density (1.0); the
film density is applied later as the model |
1.0
|
beta_to_mu ¶
Inverse of mu_to_beta.
wavelength_angstrom ¶
Photon wavelength in Angstrom for energies in eV.