WavesFit Go
Methods and Conventions
Line shapes, physical constraints, and what an unfinished scan can tell us.
A spectrum is still being acquired. Which peak parameters can we estimate now, and which should wait for more data?
Before fitting, consider a peak whose right-hand side has not yet been measured. A numerical answer is possible; a well-determined width may not be.
WavesFit Go is an MIT-licensed library and standalone application for spectroscopy. It evaluates peak models, estimates backgrounds, and fits spectra from growing text files or directories of completed scans. A packaged browser dashboard displays the measurements, components, residuals, and parameter trends. The executable needs no separate numerical runtime.
This note develops the conventions behind a few of those routines. The examples below use synthetic data. When enabled, they run the published Go v0.1.0 engine, compiled to WebAssembly, in a browser worker. No spectrum is sent to a fitting server.
1. From broadening to a Voigt peak
Suppose a symmetric line is broadened by two independent contributions. A Gaussian can represent a distribution of unresolved energies or instrumental resolution; a Lorentzian describes an exponential decay in time. These are modelling assumptions, not a way to identify a mechanism from the curve alone. With centre , Gaussian standard deviation , and Lorentzian half-width , define
The convolution is the Voigt profile. WavesFit multiplies its unit-area shape by the parameter area, denoted :
Here is the Faddeeva function [1]. The library uses it directly rather than replacing the convolution by a weighted sum. Its public parameters are the full widths of the two underlying profiles:
gaussian_fwhm is and lorentzian_fwhm is . Neither is the full width of the resulting mixed profile. One may be zero, giving the pure Lorentzian or Gaussian limit; both cannot be zero. The displayed interval contains only part of a Voigt peak's total area.
2. Asymmetry and doublets
A symmetric broadening model cannot describe every photoemission line. The Doniach–Šunjić (DS) shape describes an asymmetric threshold associated with low-energy excitations [2]. In the package's convention, put for a tail towards higher coordinate values, and :
The parameter is amplitude, a prefactor. At , , whose area is . At positive the idealized long tail has no finite integral over the entire axis, so calling an area would be misleading. The physical spectrum is used over a finite energy interval. The gamma function in the equation is distinct from a width.
The library names the tail direction explicitly: higher or lower. Reversing the order of the measured array does not reverse the physical tail. For either a Voigt or DS doublet, a single component is replaced by
The signed splitting and branching ratio are explicit parameters. The two lines share their widths and, for DS, asymmetry. Fixing a physically justified ratio or splitting removes a free degree of freedom; a software default is not evidence that the constraint applies to a particular transition.
The package also supplies asymmetric Gaussians, Gaussian steps, and composite NEXAFS models. An asymmetric Gaussian uses a local width , which must remain positive over the fitted interval. A nonzero slope makes a local width parameter rather than the exact full width of the complete shape. NEXAFS combines explicitly chosen peaks and steps with one shared offset.
3. What belongs to the background?
The measured intensity includes more than the peaks we wish to interpret. WavesFit estimates a background from the observations and holds it fixed during each fit. It is not jointly optimized with the peak parameters. Endpoint anchors refer to increasing physical energy, even when the input array is descending.
| Background | Construction in v0.1.0 | What to examine |
|---|---|---|
| Linear | Interpolate the two anchors in physical energy. | Whether the endpoints lie outside the features of interest. |
| Exponential | Interpolate using , with the fractional energy position. | The chosen curvature ; the limit is a line. |
| Shirley | Iterate an endpoint-normalized integral of [3]. | Convergence, endpoint choice, and the assumption behind the tail direction. |
| Tougaard | Integrate an endpoint-normalized loss kernel proportional to [4]. | The loss coordinate and kernel scale , expressed in squared energy units. |
These are specific, documented implementations, including stabilized and corrected legacy routines. The exponential model uses a chosen curvature, and the Tougaard routine is an endpoint-normalized kernel rather than every parameterization bearing that name. Use the numerical conventions when reproducing a background. A background error can be absorbed into a broad peak; a small residual does not by itself establish a correct subtraction.
4. What the fit minimizes
For observations at energies , a fixed estimated background , one offset , and chosen peak functions , the prediction is
When positive measurement standard deviations are supplied, the objective is weighted least squares:
Without uncertainties it minimizes the unweighted squared residuals. Fixed parameters are removed from the optimization. The Go solver computes scaled, damped Gauss–Newton steps using Gonum QR, projects steps onto the allowed bounds, and uses SVD for rank and covariance diagnostics. Voigt derivatives are analytic; other supported profiles use numerical differences. A fit interval restricts the observations, not the meaning of the energy axis.
The plot below reports residuals as , so positive residuals indicate intensity missing from the model. The sign is opposite to the optimizer's residual convention, but the squared objective is unchanged.
5. Fit only what the scan has observed
Each successful fit can provide the starting parameters for the next update. This saves work when a spectrum changes gradually. It can also propagate an early mistake: if an unobserved peak is fitted to noise, its parameters may be poor starting values later. The package therefore checks for coverage on both sides of the configured peaks before fitting a growing scan.
| Parameter | Estimate | Standard error |
|---|---|---|
| p1.center | -0.80008 | 0.00060265 |
| p2.center | 0.80049 | 0.0011223 |
| p1.gaussian_fwhm | 0.65009 | 0.0017496 |
| p1.lorentzian_fwhm | 0.30000 | — (fixed or bound) |
A pause does not establish that a scan is complete. In real acquisition, configure a point count, a scan boundary, or finalized-file publication. Growing files may end with a partial line, and a writer may rotate or truncate a file. The installed application handles those events and shows failures and backlog. Completed scans enter a bounded queue in order; previews within a scan can be coalesced. A failed update retains the previous successful fit and records its failure.
6. A Good Curve Is Not a Unique Explanation
Move the peaks closer together and release the Lorentzian-width constraint. Several changes in area and width can then have similar effects on the total curve. A solver may converge even while individual parameters remain uncertain. The relevant local object is the Jacobian .
Small singular values indicate directions in parameter space to which the observations are insensitive. WavesFit evaluates rank after normalizing the Jacobian columns, with a relative cutoff of . It reports singular fits explicitly. Standard errors are returned only for converged, full-rank fits with positive residual degrees of freedom. Supplied uncertainties are treated as absolute; otherwise covariance is scaled by the residual sum of squares divided by , where is the number of free parameters.
Fixed parameters and parameters on active bounds have no symmetric standard error reported. These uncertainties condition on the chosen background and model. They do not include the uncertainty in background estimation, model choice, or the assumption that a particular pair of peaks represents the underlying physics.
A live fit is an estimate conditional on the data acquired so far, the selected model, and its constraints. Inspect the residuals and identifiability, preserve explicit scan boundaries, and distinguish a provisional update from a completed measurement.
Follow-up. If only one side of a peak is observed, which combination of its area, width, and centre can change without appreciably changing the measured curve?
Use WavesFit Go
Download the executable for your platform from the v0.1.0 release, extract it, and run wavesfit-go demo (wavesfit-go.exe demo on Windows). Open the local URL printed by the command. With Go 1.24 or later, install from source:
go install github.com/AlessandroLodi/wavesfit-go/cmd/wavesfit-go@v0.1.0
wavesfit-go demo
Use a saved JSON preset for acquisition or for a complete spectrum:
wavesfit-go serve --config acquisition.json
wavesfit-go fit spectrum.csv --config acquisition.json --output result.json
The native library can also be imported into a Go application. The same configuration describes named initial values, fixed parameters, bounds, fit intervals, source columns, units, scan completion, and fitting budgets. Results include curves, components, residuals, convergence, uncertainties, and timing. Sessions export JSONL and CSV for analysis.
The current release supports generic UTF-8 CSV, TSV, and whitespace tables. Specialized Igor instrument readers and transforms are follow-up work. Validation uses analytic limits, quadrature, synthetic recovery, and acquisition replay; representative hardware streams and independent Igor output have not yet been validated. Read the validation report before using the package for an experiment.
Check it in Go
This downloadable example checks both pure-profile half maxima, the DS Lorentzian limit, and recovery of a synthetic Voigt peak. Put it in an empty folder and run:
go mod init example.org/wavesfit-check
go get github.com/AlessandroLodi/wavesfit-go@v0.1.0
go run check.go
// MIT license. Run in an empty module with wavesfit-go v0.1.0 as a dependency.
package main
import (
"context"
"fmt"
"math"
wf "github.com/AlessandroLodi/wavesfit-go"
)
func main() {
gaussian := wf.Voigt(.5, 1, 0, 1, 0) / wf.Voigt(0, 1, 0, 1, 0)
lorentzian := wf.Voigt(.5, 1, 0, 0, 1) / wf.Voigt(0, 1, 0, 0, 1)
ds := wf.DoniachSunjic(0, 1, 0, 1, 0, "higher")
fmt.Printf("Gaussian half maximum: %.6f\n", gaussian)
fmt.Printf("Lorentzian half maximum: %.6f\n", lorentzian)
fmt.Printf("DS origin at alpha=0: %.6f\n", ds)
x, y := make([]float64, 301), make([]float64, 301)
for i := range x {
x[i] = -4 + 8*float64(i)/300
y[i] = .04 + wf.Voigt(x[i], 3, .4, .8, .3)
}
model, err := wf.DefaultModel("voigt", 1)
if err != nil {
panic(err)
}
result, err := wf.Fit(context.Background(), x, y, nil, model,
wf.BackgroundConfig{Kind: "none"}, wf.FitOptions{BudgetSeconds: 5}, nil)
if err != nil {
panic(err)
}
if !result.Success || math.Abs(result.Parameters["p1.center"]-.4) > 1e-5 {
panic("recovery failed")
}
fmt.Printf("Fit status: %s\n", result.Status)
fmt.Printf("Recovered center: %.6f eV\n", result.Parameters["p1.center"])
fmt.Printf("Recovered area: %.6f\n", result.Parameters["p1.area"])
}
Output from the published module:
Gaussian half maximum: 0.500000
Lorentzian half maximum: 0.500000
DS origin at alpha=0: 2.000000
Fit status: converged
Recovered center: 0.400000 eV
Recovered area: 3.000000
References and implementation
- NIST Digital Library of Mathematical Functions, §7.19: Voigt functions. The numerical implementation uses the gospecfunc Faddeeva routine.
- S. Doniach and M. Šunjić, “Many-electron singularity in X-ray photoemission and X-ray line spectra from metals,” Journal of Physics C 3, 285 (1970). doi:10.1088/0022-3719/3/2/010. The amplitude and tail convention used here are stated above.
- D. A. Shirley, “High-Resolution X-Ray Photoemission Spectrum of the Valence Bands of Gold,” Physical Review B 5, 4709 (1972). doi:10.1103/PhysRevB.5.4709.
- S. Tougaard, “Practical algorithm for background subtraction,” Surface Science 216, 343–360 (1989). doi:10.1016/0039-6028(89)90380-4. See the package conventions for the particular kernel and normalization.
- WavesFit Go: formulas and conventions, library and acquisition API, legacy routine inventory, and Gonum matrix methods.