pymca-bridge
by nanare-sudo
README.md
# pymca-bridge
pymca-bridge adds a command-line interface, a Python API and a Model Context Protocol (MCP) server to a
running [PyMca](https://github.com/vasole/pymca) graphical user interface (Solé et al. 2007), and an
optional assistant panel in the PyMca window through which a large language model (LLM) agent runs the
same commands. Every command acts on the objects of the open PyMca session (data sources, scan window,
MCA window), so typed commands and mouse interaction can be combined. The analysis commands (peak and
edge fits with PyMca's Specfit engine, model comparison, error propagation, normalization, alignment,
linear combination fitting, principal component analysis) report statistical uncertainties, and every
step is recorded for replay.
PyMca's installation and the opened data files are not modified. Two-dimensional data (images) are
accessible only through `exec`; structure refinement and phase identification are outside the scope.
A user guide with the complete command reference is in [docs/pymca-bridge-guide.pdf](docs/pymca-bridge-guide.pdf).
**Contents:** [Installation](#installation) · [Quick start](#quick-start) ·
[Architecture and security](#architecture-and-security) · [Commands](#commands) ·
[Analysis methods](#analysis-methods) · [AI assistant](#ai-assistant) · [MCP](#mcp-server) ·
[Python](#python-api) · [Data being written](#data-being-written) ·
[Record, report, undo](#record-report-undo) · [Troubleshooting](#troubleshooting) ·
[Limitations](#limitations) · [References](#references)
## Installation
Requirements: Python ≥ 3.10. PyMca5 (≥ 5.9), PyQt5 (≥ 5.15), NumPy and the Anthropic SDK are installed as
dependencies. Development and tests were done on Linux; macOS and Windows have not been tested.
```sh
uv tool install git+https://github.com/nanare-sudo/pymca-bridge
pymca-bridge --version
pymca-bridge doctor # installation, display, running PyMca, assistant settings
eval "$(pymca-bridge completion bash)" # optional: tab completion (zsh: completion zsh)
```
From a local copy: `git clone https://github.com/nanare-sudo/pymca-bridge`, then
`uv tool install ./pymca-bridge` (isolated tool environment) or `pip install ./pymca-bridge` into an
existing environment. Update with `uv tool upgrade pymca-bridge`, or for a local copy with
`uv tool install --force --reinstall-package pymca-bridge ./pymca-bridge`. The package is not on PyPI.
Development: `uv sync`, then `QT_QPA_PLATFORM=offscreen uv run pytest` runs the tests without a display.
## Quick start
`pymca-bridge example` writes a synthetic SPEC file (Poisson noise with fixed seeds, marked as synthetic in
its header). The user guide uses the same file for all examples.
```sh
pymca-bridge example example.dat # write the synthetic test file
pymca-bridge serve example.dat # PyMca with the bridge and the assistant panel
```
In a second terminal:
```sh
pymca-bridge scans # key, command, points, columns
pymca-bridge plot --scan 1-2 --x 2theta --y Det --m I0 # Det/I0 of scans 1 and 2
pymca-bridge fit --model gauss,lorentz,voigt --xmin 32.5 --xmax 33.7 # line shapes ranked by BIC
pymca-bridge screenshot --target plot --out plot.png
```
| Scan | Command | Content (columns) |
|---|---|---|
| 1, 2 | `ascan 2theta` | Gaussian diffraction peak on a linear background (`2theta`, `I0`, `Det`); scan 2 repeats scan 1 with the peak 0.03° higher and a 7 % lower monitor |
| 3 | `ascan 2theta` | two overlapping peaks, a third peak and a single-point outlier (`2theta`, `I0`, `Det`) |
| 4 | `timescan` | exponential decay on a constant background (`Time`, `I0`, `Det`) |
| 5 | `ascan energy` | absorption edge at 8979 eV with a pre-edge peak and a white line, transmission (`Energy`, `I0`, `I1`) |
| 6–9 | `ascan energy` | edges over 500 eV: reference A, reference B, a mixture of 65 % A and 35 % B, and a repeat of the mixture with the energy axis shifted by 0.8 eV |
| 10 | `ascan samz` | three MCA spectra (512 channels, E = 0.03 keV + 0.02 keV × channel) with Cu Kα/Kβ, Ar Kα and an elastic scatter peak at 9.6 keV |
| 11 | `ct` | one fluorescence spectrum (2048 channels, E = 0.005 keV + 0.01 keV × channel) of a brass-like sample with a nickel trace, excited at 15 keV: Cu, Zn, Ni and Ar K lines, Si escape peaks, pile-up peaks above the elastic peak, Rayleigh and Compton scatter |
`pymca-bridge example` also writes `example_xrf.cfg`, a PyMca fit configuration for scan 11.
## Architecture and security
`pymca-bridge serve` starts PyMca's main window and, in the same process, a TCP server bound to
`127.0.0.1` on a random free port. A background thread accepts connections; each request is passed to the
GUI thread through the Qt event queue and executed there, one request at a time, on the same objects that
the mouse actions use. The server writes a session file (`~/.pymca-bridge/session.json`, file mode 0600)
with the port and a random 128-bit token. Every other command reads this file, sends one JSON request with
the token and prints the reply. Several PyMca sessions can run side by side with different session files
(`PYMCA_BRIDGE_SESSION=/path/a.json pymca-bridge serve`).
`exec` runs arbitrary Python code in the PyMca process with the permissions of the user. The token
therefore has the role of a password; the server does not listen on other network interfaces.
## Commands
`pymca-bridge COMMAND --help` lists the options of a command; the user guide contains the full reference.
| Area | Commands |
|---|---|
| Session | `serve`, `ping`, `state`, `doctor`, `show`, `windows`, `quit` |
| Data sources | `open`, `import-text` (CSV, `;`/tab separated, decimal commas, `.xy`), `close`, `refresh`, `sources`, `scans`, `columns`, `example` |
| X-ray data (no PyMca needed) | `lines` (emission lines, edges, fluorescence yields; candidate lines for a peak energy, including escape, pile-up and scatter peaks), `attenuation` (µ/ρ, attenuation length, transmission; information depth of a fluorescence line) |
| Plotting | `plot`, `calc` (expressions of counters, e.g. `log(I0/I1)`), `mca`, `curves`, `data`, `curve`, `active`, `remove`, `clear`, `axes`, `tool`, `plugin` (PyMca's plot plugins), `screenshot`, `export`, `figure` |
| Curve operations | `math normalize`, `smooth`, `derivative`, `integral`, `scale`, `shift`, `crop`, `baseline`, `background`, `resample`, `subtract`, `divide`, `add`, `multiply`, `average`, `align`, `convert` (2θ, q, d; energy, k) |
| Analysis | `fit`, `peaks`, `stats`, `roi`, `describe`, `calibrate`, `compare`, `lcf`, `pca`, `xrf-fit`, `batch fit/stats/peaks/roi/edge` |
| Record and reuse | `history` (`--script`, `--notebook`), `report` (HTML, Markdown, PDF), `undo`, `save`, `load` (`--last`) |
| Python in PyMca | `exec CODE`, `exec --file script.py` (names `main`, `app`, `qt`, `np`, `scan`, `mca`, `bridge`; set `result`) |
| Assistant | `assistant`, `ask`, `setup`, `config`, `mcp`, `completion` |
Global options (before or after the command): `--json` (machine-readable output), `--session FILE`,
`--timeout SECONDS`, `--verbose` (PyMca's traceback on errors).
Conventions:
- Scans: `--scan 12`, `12.1`, `10-15`, `10-15,18`, `40-` (scan 40 and all later ones, in `batch`) or
`selected` (the scans selected in PyMca's file browser).
- Curves are addressed by a unique part of their legend (`<file> <scan>.<order> <counter>`, e.g.
`"example.dat 1.1 Det"`) or by a pattern with `*` (`"normalized:*"`). Derived curves are named
`<operation>: <curve>`; `--name` sets another name.
- `--window mca` applies the curve commands (`curves`, `data`, `fit`, `peaks`, `stats`, `roi`, `figure`,
`export`, …) to PyMca's MCA window instead of the scan window.
- `--visible` (in `fit`, `peaks`, `stats`, `roi`, `compare`, `lcf`, `pca`, `batch`) restricts the analysis
to the x range shown in the plot.
Further examples with the example file:
```sh
pymca-bridge plot --scan 3 --x 2theta --y Det --replace
pymca-bridge describe # points, noise, outliers, peaks or edge
pymca-bridge fit --model auto --peaks auto --robust --weight counts --components
pymca-bridge calc "Det/I0" --scan 1 --x 2theta --errors Det,I0 --replace
pymca-bridge fit --weight sigma # weighted with the propagated σ
pymca-bridge calc "log(I0/I1)" --scan 6-9 --x Energy --name mu --replace
pymca-bridge math normalize "*mu" --by edge # E0, pre/post-edge polynomials, jump
pymca-bridge lcf "normalized: example.dat 6.1" "normalized: example.dat 7.1" \
--sample "normalized: example.dat 8.1" --sum-one # fractions of the mixture ± 1σ
pymca-bridge math align "normalized: example.dat 9.1" --to "normalized: example.dat 8.1" --use derivative
pymca-bridge pca "normalized:*" # number of significant components
pymca-bridge batch edge --scan 6-9 --expr "log(I0/I1)" --x Energy --out edges.csv
pymca-bridge mca --scan 10 --point 1-3 # spectra into the MCA window
pymca-bridge roi --window mca --xmin 390 --xmax 412 --weight counts
pymca-bridge figure figure.pdf --size 16 10 --style paper # matplotlib figure of the plotted curves
pymca-bridge mca --scan 11 --replace # fluorescence spectrum, excited at 15 keV
pymca-bridge xrf-fit --config example_xrf.cfg # line areas, background, 3σ detection limits
pymca-bridge lines --energy 6.88 --excitation 15 Cu Zn Ni Co # Co Kα or the Si escape peak of Zn Kα?
pymca-bridge attenuation SiO2 --density 2.65 --excitation 15 --line "Cu Ka" # information depth
```
## Analysis methods
The statements below describe the implementation in `src/pymca_bridge/analysis.py`.
**Fits (`fit`, `batch fit`).** Least squares with PyMca's Specfit engine (the engine of the scan window's
fit dialog). Models: `gauss`, `lorentz`, `voigt` (pseudo-Voigt), `split-gauss`, `split-lorentz`,
`split-voigt`, `hypermet`; edges `step-up`, `step-down` (error function), `atan`, `slit`; `exp`
(exponential decay); `linear`, `constant`, `poly2` … `poly5`. Backgrounds: `none`, `constant`, `linear`,
`strip`. Peak fits start from the peak search of `peaks`; with `--peaks N`, missing peaks are placed at the
largest residual. Weighted fits of several peaks are also started from the solution of the unweighted fit, and
the result with the lower χ² is kept (protection against local minima). Parameters are reported with 1σ standard errors from the covariance matrix. Without
weights the errors are scaled by √χ²_ν; with `--weight counts` (Poisson weights, σ = √N) or `--weight
sigma` (σ from `calc --errors`) they are not scaled, so χ²_ν tests the model against the stated errors.
The output also gives the reduced χ², R² and the RMS residual. `--fix NAME=VALUE` and
`--bounds NAME=LOW:HIGH` constrain parameters (`fwhm` applies to all peaks, `fwhm2` to the second one).
Diagnostic lines (`check:`) report a Durbin–Watson statistic below 1 (residuals not random), counting data
fitted without weights, χ²_ν > 3 with weights, parameters with σ larger than half their value, positions
less certain than the peak width, negative heights and positions outside the fitted range.
**Model comparison.** Several models (comma-separated; `--model auto` = gauss, lorentz, voigt) and peak
numbers (`--peaks 1-3`; `--peaks auto` = 1 to the number found plus one, at most 6) are fitted to the same
points and ranked by the Bayesian information criterion (Schwarz 1978): BIC = n ln(RSS/n) + k ln n without
weights, BIC = χ² + k ln n with weights; fixed or tied parameters are not counted in k. The output lists
ΔBIC relative to the best model, read with the scale of Kass and Raftery (1995): 0–2 not worth more than a
bare mention, 2–6 positive, 6–10 strong, above 10 very strong evidence for the model with the lower BIC.
**Outliers (`fit --robust`).** Single-point outliers are first detected from the second difference: it
must exceed 8 times its local noise level and have the opposite sign of the second differences at both
neighbors, a pattern that sharp peak maxima do not show. The fit is then repeated without points whose residuals exceed 4
robust standard deviations (1.4826 × median absolute deviation, not below the noise level), at most six
times. Runs of three or more adjacent points are kept, because they indicate a deficiency of the model,
and at most 20 % of the points can be excluded. Excluded points are listed and marked in the plot.
**Bootstrap (`fit --bootstrap N`).** The fit is repeated N times (default 50) on the fitted curve plus
residuals resampled in blocks (block bootstrap, Künsch 1989). The block length is 1 for uncorrelated
residuals and otherwise twice the lag at which their autocorrelation falls below 1/e. The standard deviation of the refitted parameters is
reported as an additional 1σ that accounts for correlated residuals.
**Counting statistics (`calc --errors`).** The listed counters are treated as independent Poisson
variables (σ² = N). The 1σ of the expression is propagated to first order with numerical derivatives.
Expressions that combine points (`max`, `mean`, `median`, indexing) use the full Jacobian up to 2000
points and a Monte Carlo estimate (400 draws, relative precision of σ about 4 %) above that.
**Peak search, statistics, net areas.** `peaks` finds local maxima of a smoothed curve whose prominence
exceeds a threshold given by `--sensitivity` (default 4) in units of the noise level of the smoothed
curve; the noise is a robust estimate from second differences (1.4826 × MAD / √6). The position comes from a
parabola through the maximum and its two neighbors, the FWHM is measured at half the prominence. `stats` gives
maximum and minimum with their positions, mean, standard deviation, integral (trapezoidal rule), centroid
and FWHM in an x range. `roi` subtracts a straight line through the mean of `--edge-points` points (default 3) at both
ends; the 1σ of the net area follows from Poisson statistics of channel sums (`--weight counts`) or from
the point-to-point noise and includes the correlation between gross area and background.
**Curve operations.** `math smooth` applies a Savitzky–Golay filter (Savitzky and Golay 1964; default
window 7 points, order 2); `math derivative` is the numerical gradient dy/dx (smooth noisy data first). `math background` subtracts a SNIP background (Ryan
et al. 1988) or PyMca's iterative strip; the default window is twice the largest FWHM found by the peak
search. `math convert` uses q = 4π sin θ / λ, d = 2π / q and k = 0.5123 √(E − E0) (k in Å⁻¹, E in eV).
`calibrate` fits a polynomial (order 1 or 2) to measured and known positions and reports the coefficients
± 1σ and the residual of each reference point.
**Absorption edges (`math normalize --by edge`, `batch edge`).** PyMca's XAS normalization: E0 at the
maximum of the smoothed derivative (or `--e0`), a pre-edge polynomial (order 1) in E0 − 400 eV … E0 − 50 eV,
a post-edge polynomial (order 2) from E0 + 20 eV to the end of the scan. The normalized spectrum is
(μ − pre-edge line) / jump, with the jump being the difference of both polynomials at E0; `--flatten`
divides by the post-edge curve instead. The white line is the maximum within 30 eV above E0.
**Alignment (`math align`).** The x shift between a curve and a reference minimizes the squared
difference with a free scale and offset (`--use derivative`: smoothed first derivatives); it is refined
between grid points. Its 1σ comes from a parametric bootstrap: the search is repeated 40 times on
smoothed copies of both curves with added noise of the measured level.
**References and mixtures (`compare`, `lcf`).** `compare` gives for every reference the best scale a,
the R-factor Σ(s − a·r)² / Σ s² and the correlation coefficient. `lcf` fits the sample as Σ wᵢ rᵢ with
wᵢ ≥ 0 (exact search over all subsets of up to 8 references) and, with `--sum-one`, Σ wᵢ = 1. The 1σ of
the weights follows from the covariance matrix scaled by the residual variance (conditional on Σ wᵢ = 1);
correlated references give large σ.
**Principal components (`pca`).** Singular value decomposition of the curves interpolated onto a common
grid, by default after subtracting the mean curve. A component is counted as significant when its
singular value exceeds the 99 % quantile of the largest singular value of a pure-noise matrix of the same
size and measured noise level (Tracy–Widom approximation of Johnstone 2001). `--reconstruct N` adds the
curves rebuilt from N components.
**Fluorescence spectra (`xrf-fit`).** PyMca's fluorescence fit (Advanced Fit) with a configuration saved
in PyMca: area ± 1σ of every element line group, the fit and the continuum, the fitted energy calibration
and the detector resolution, FWHM(E) = √(noise² + 2.3548²·F·ε·E) with the Fano factor F and ε = 3.85 eV
per electron–hole pair (PyMca's detector model), quoted at 5.9 keV. For every line group the background B
is the sum of all other contributions of the fit (continuum, other lines, escape and pile-up peaks) within
±1 FWHM of its strongest line, and the detection limit is 3√B/f, where f is the fraction of the group's
area in that window (3σ criterion; Currie 1968 discusses detection limits in general). A group whose area
is below this limit is reported as not detected. The fit σ does not include the uncertainty of the
background stripped before the fit; at trace level the scatter of repeated results can be larger.
**X-ray data (`lines`, `attenuation`).** Emission-line energies, relative rates, edges, fluorescence
yields and mass attenuation coefficients come from PyMca's element database. `lines --energy E` lists the
lines within a tolerance and the artifacts that can appear at E: escape peaks (parent energy minus the Kα
or Kβ energy of the detector material, with PyMca's escape probability), pile-up peaks (twice a line
energy) and, with `--excitation`, the Rayleigh and Compton (E′ = E0/(1 + (E0/mₑc²)(1 − cos θ))) scatter
peaks. `attenuation --line` computes χ = µ/ρ(E0)/sin α + µ/ρ(Eᵢ)/sin β for primary fluorescence of a
homogeneous sample and reports 1/(χρ) (depth of origin of 63 % of the thick-sample signal), ln 100/(χρ)
(thick within 1 %) and 0.1035/(χρ) (signal proportional to the mass per area within 5 %). Chapter 7 of
the user guide summarizes the physics of X-ray fluorescence and the configuration of PyMca's fit.
All uncertainties are statistical (fit standard errors, bootstrap, propagated counting errors).
Systematic contributions such as calibration, normalization and the choice of model are not included and
have to be assessed separately.
## AI assistant
`pymca-bridge serve` adds an assistant panel to the PyMca window. A request typed into the panel is
passed to an LLM agent together with a short description of the PyMca state (open files, selected scans,
curves, axes); the agent answers by running `pymca-bridge` commands, and the panel shows each command, the
screenshots the agent inspected and the answer. A line that starts with `/` (for example `/fit --model
gauss --visible`) runs a bridge command directly, without a model. `pymca-bridge ask "REQUEST"` sends a
request from the terminal. The agent follows [AGENTS.md](AGENTS.md), which is shipped in the package as
`assistant_instructions.md`.
| Provider | Requirement |
|---|---|
| `claude-code` (default) | [Claude Code](https://claude.com/claude-code) installed and logged in (Claude subscription), or an Anthropic API key |
| `codex` | [Codex CLI](https://github.com/openai/codex) installed and logged in (`codex login`), or an OpenAI API key |
| `anthropic` | an Anthropic API key (built-in agent; default model `claude-opus-5-5`) |
| `openai` | base URL, model and, if required, a key of an OpenAI-compatible API: OpenAI, OpenRouter, Google Gemini, Mistral, Groq, DeepSeek, or a local server (Ollama `http://localhost:11434/v1`, LM Studio `http://localhost:1234/v1`) |
| `command` | any command-line agent, given as a template containing `{prompt}` |
```sh
pymca-bridge setup # interactive: provider, key (hidden input), model, test
pymca-bridge config set provider anthropic
pymca-bridge config set api-key sk-ant-... # stored for the current provider
pymca-bridge config models # models offered by the configured provider
pymca-bridge config services # OpenAI-compatible services and their base URLs
pymca-bridge config # current settings, keys masked
```
Settings and keys are stored in `~/.pymca-bridge/settings.json` (file mode 0600; `PYMCA_BRIDGE_HOME`
moves the directory). `ANTHROPIC_API_KEY` and `OPENAI_API_KEY` are used when no key is stored. The
request, the state description, the command output and (if enabled) screenshots are sent to the
configured provider; with a local server they stay on the computer. `config set context off` disables
the state description; `config set vision off` stops sending screenshots to the built-in agents.
Permissions: with `claude-code` the agent may run `pymca-bridge` commands and read and write files
(permission mode `dontAsk`); other shell commands are refused. The built-in agents (`anthropic`,
`openai`) have a single tool that runs `pymca-bridge` command lines, excluding `serve`, `quit`,
`assistant`, `ask`, `config`, `doctor`, `mcp`, `setup` and `completion`. Because `exec` is available to
the agent, it can run Python code inside PyMca.
The panel position is set with `serve --assistant-area auto|right|left|bottom|top|window` or in the
panel's settings; `--no-assistant` starts PyMca without the panel, and `pymca-bridge assistant` opens it
as a separate window next to a running session. *Settings… → Test* (and `pymca-bridge doctor`) checks the
provider configuration: program and login, or API key and model through the provider's model list,
without a model request.
## MCP server
`pymca-bridge mcp` is a [Model Context Protocol](https://modelcontextprotocol.io) server on standard
input and output. It provides two tools: `pymca` (one bridge command; screenshots are returned as images)
and `start_pymca` (starts PyMca if no session is running). `pymca-bridge mcp --config` prints the entries
for common clients with the full path of the installation, for example:
```sh
claude mcp add pymca -- pymca-bridge mcp # Claude Code
```
```json
{"mcpServers": {"pymca": {"command": "/full/path/to/pymca-bridge", "args": ["mcp"]}}}
```
## Python API
```python
from pymca_bridge import PyMca
pm = PyMca() # session started with `pymca-bridge serve`
# pm = PyMca.start("example.dat") # or start a new PyMca window
pm.plot("1-2", "Det", x="2theta", m="I0", replace=True)
fit = pm.fit(model="gauss,lorentz,voigt", xmin=32.5, xmax=33.7)
fit["peaks"][0]["position"], fit["peaks"][0]["position_sigma"]
x, y = pm.xy("1.1 Det") # NumPy arrays of a curve (default: the active one)
pm.show() # image of the plot (inline in Jupyter)
pm # files, selection, curves
```
Every bridge command is a method with the option names as keyword arguments (`-` replaced by `_`);
`help(pm.fit)` shows the parameters, `dir(pm)` lists the commands, and results are dictionaries and
lists. The low-level client is `pymca_bridge.client.request(command, args)`.
## Data being written
PyMca re-reads SPEC files only on request (F5). `refresh` re-reads a file that is still being written:
new scans are listed and plotted curves receive their new points. `refresh --every 5 --follow` repeats
this every 5 s and plots each new scan with the counters of the active curve; `refresh --stop` ends it.
`batch fit --scan 40- … --trend COLUMN --live` repeats an analysis for every new scan and extends the
trend plot.
The work of a session is saved automatically 3 s after each change (at the latest 15 s after the first
unsaved change) in `~/.pymca-bridge/autosave`; the last 10 sessions are kept. `pymca-bridge load --last`
restores the files, curves and history of the previous session; `serve --no-autosave` disables this.
## Record, report, undo
Every command that changes the plot or computes a result is recorded with its command line, whether
typed, sent from Python or run by the assistant. Actions done with the mouse are not recorded.
```sh
pymca-bridge history # numbered steps with results
pymca-bridge history --script > steps.sh # shell script that repeats the steps
pymca-bridge history --notebook analysis.ipynb # Jupyter notebook, one cell per step
pymca-bridge report analysis.html # plot, data, results ± 1σ, steps (.md and .pdf as well)
pymca-bridge save analysis.pbw.json.gz # files, curves of both windows, axes, history
pymca-bridge load analysis.pbw.json.gz
pymca-bridge undo # reverts the last change of the plot (up to 20 steps)
```
## Troubleshooting
- `pymca-bridge doctor` checks the installation, the display, the running PyMca and the assistant
configuration (`--offline` skips the checks of API keys and servers).
- `PYMCA_BRIDGE_DEBUG=1 pymca-bridge serve` logs every request and reply with a time stamp.
- Commands also run while a PyMca dialog is open; a dialog that PyMca opens during a command (for example
an error message) is closed and its text is reported.
## Limitations
- Commands run in the GUI thread and block the window while they execute; long `exec` scripts do the same.
- Uncertainties are statistical only (see [Analysis methods](#analysis-methods)).
- Unweighted fits assume the same noise level at every point; use `--weight counts` for counting data.
- `fit --robust` removes isolated outliers (single points or pairs); it does not compensate for a model
that fails over whole regions.
- `math align` assumes that the curves are sampled finely compared with their features; for point
spacings larger than the width of an edge the shift can be biased by a fraction of the spacing.
- The peak search can report noise maxima on long noisy curves; give `--peaks N` when the number of peaks
is known.
## References
- Currie, L. A. (1968). Limits for qualitative detection and quantitative determination. Application to
radiochemistry. *Analytical Chemistry* 40, 586–593.
- Johnstone, I. M. (2001). On the distribution of the largest eigenvalue in principal components
analysis. *Annals of Statistics* 29, 295–327.
- Kass, R. E., Raftery, A. E. (1995). Bayes factors. *Journal of the American Statistical Association* 90,
773–795.
- Künsch, H. R. (1989). The jackknife and the bootstrap for general stationary observations. *Annals of
Statistics* 17, 1217–1241.
- Ryan, C. G., Clayton, E., Griffin, W. L., Sie, S. H., Cousens, D. R. (1988). SNIP, a
statistics-sensitive background treatment for the quantitative analysis of PIXE spectra in geoscience
applications. *Nuclear Instruments and Methods in Physics Research B* 34, 396–402.
- Savitzky, A., Golay, M. J. E. (1964). Smoothing and differentiation of data by simplified least squares
procedures. *Analytical Chemistry* 36, 1627–1639.
- Schwarz, G. (1978). Estimating the dimension of a model. *Annals of Statistics* 6, 461–464.
- Solé, V. A., Papillon, E., Cotte, M., Walter, Ph., Susini, J. (2007). A multiplatform code for the
analysis of energy-dispersive X-ray fluorescence spectra. *Spectrochimica Acta Part B* 62, 63–68.
## License
MIT, see [LICENSE](LICENSE). PyMca is © ESRF and licensed separately.