Skip to content

feat: exspy's window path for an SEM spectrum: lines in range, windows, intensities and Cliff-Lorimer - #154

Merged
Paullo9 merged 4 commits into
mainfrom
claude/project-thread-b2qyav
Nov 28, 2026
Merged

Paullo9 merged 4 commits into
mainfrom
claude/project-thread-b2qyav

Conversation

@Paullo9

@Paullo9 Paullo9 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Requested by Paul · project thread

Fixes #131

Step 3 of the kit move (EMSuite/Electron-Microscopy-Studio#848). This merges the app's SEMEDSLines into the kit. The kit's own functions are the only implementation, and the new public file sits in front of them.

Public API (Sources/SpectroEDX/EDSWindowPath.swift)

  • EDSWindowPath.Conditions holds the beam energy, resolution and angles, with eXSpy's defaults, plus the take-off angle.
  • lines(forElements:axis:beamEnergyKeV:onlyOne:onlyLines:) and linesInSpectralRange.
  • integrationWindows and backgroundWindows.
  • intensities(counts:axis:integrationWindows:backgroundWindows:) gives the raw and the net intensities.
  • cliffLorimer(intensities:kFactors:singleLine:) returns weight and atomic fractions. It has no default, so both behaviours are named:
    • .refuse is the kit's route and stays EDXQuantificationSetup's default.
    • .exspyHundredPercent is eXSpy's raw arithmetic, which the app's figure F17 pins.
  • EDSWindowPathError, plus a package-level ResolvedWindow.net(Double, Double, Double). The new overload does the same arithmetic as the integer form, and the existing callers are unchanged.

No kit default and no existing number changes.

Parity

  • Line table: the app's table (from exspy._misc.elements) and XRayLineData agree on all 947 lines (energy, weight and Z exact). Neither table has a line the other lacks.
  • Bundles m7/eds-lines-tm002 and m7/eds-quant-tm002 (BAM TM002) are moved with equal sha256. The line table and the channel rule are exact; everything else is checked at rtol 1e-7, as in the app's parity rows.
  • Channel rule: it is the kit's existing EnergyAxis.index, the same as HyperSpy 2.5.0 value2index. The reviewer checked [0, 10, 20, 21, 6] against HyperSpy.
  • Differences from the app, all checked against eXSpy 0.3.2, are listed in docs/parity.md:
    • H and He get no line in the kit (XRayLines.notRealLines, an existing deviation). eXSpy and the app give H_Ka and He_Ka.
    • A window narrower than one channel gives 0, as in eXSpy. The app refused it.
    • A NaN window edge throws WindowIntensityError.axis(.notANumber). eXSpy clamps a NaN integration edge and raises on a NaN background edge.
    • A NaN detector resolution throws widthUndefined. eXSpy gives NaN windows instead.

What stays app-side for the switch

  • SEMEDSLines.table/LineRow and quantify, with its refusals and their locale text. quantify refuses fewer than two rows and k-factors that are not finite and positive; cliffLorimer does not check k-factors.
  • A guard before building EnergyAxis: its precondition(scale > 0 && size > 0) traps, where the app's Axis did not.
  • Dropping the app's table and its generator. These belong to the app-side switch PR.

Review

I ran one independent review before the PR, as the rules require for numerics and public API. It found no compile errors. A Python port of the chain reproduced every array in both bundles exactly. Its two doc findings, on NaN behaviour, are fixed in 9d2ea18.

Tests are SEMEDSParityTests (XCTest beside the kit's swift-testing, the same pattern as FormatoKit's EDS tests). The test target gains FormatoCore and FormatoHDF5; the floor of 0.12.0 has every API used.


Generated by Claude Code

…s, intensities and Cliff-Lorimer

EDSWindowPath (public) puts the kit's own functions behind the calls
Electron Microscopy Studio's SEMEDSLines makes: the lines add_lines()
picks for a list of elements at a beam energy, the lines in the
spectral range, integration and background windows, line intensities
on Double counts through WindowIntensity.resolve, the acquisition
conditions with exspy's defaults and their take-off angle, and
Cliff-Lorimer with the single-line rule named by the caller
(.refuse, the kit's default, or .exspyHundredPercent, exspy's raw
arithmetic). No default of the kit changes and no number moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VkKZEUynSt6RczY9oKhrDU
Byte-identical copies (equal sha256) of Electron Microscopy Studio's
tools/parity/sem m7/eds-lines-tm002 and m7/eds-quant-tm002 bundles
and their input exspy_EDS_SEM_TM002.hspy (at e7212f9), under
Tests/SpectroEDXTests/Fixtures/sem. The moved tests run on
EDSWindowPath at the bundles' tolerances, unchanged; the hspy file is
read with FormatoHDF5. A new test holds the app's line table (the
bundle's db_ arrays) against XRayLines and QuantElementData.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VkKZEUynSt6RczY9oKhrDU
… NOTICE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VkKZEUynSt6RczY9oKhrDU
…iations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VkKZEUynSt6RczY9oKhrDU
@Paullo9 Paullo9 self-assigned this Nov 27, 2026
@Paullo9
Paullo9 enabled auto-merge (squash) November 27, 2026 18:39

Paullo9 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

test and test-floors both failed on the self-hosted runner Pauls-MacBook-Pro-kit. Each time the job stopped about 10 minutes into the "Gate" step, the step never finished, and there are no logs (404). That pattern means the runner lost the job; it is not a test failure.

The same gate (tools/test.sh, release) passed in 6.5 minutes on GitHub's macos-15 runner at this head (9d2ea18). Lint and the private-reference scan passed too.

I re-ran the failed jobs once.


Generated by Claude Code

@Paullo9
Paullo9 merged commit c9795ba into main Nov 28, 2026
25 of 28 checks passed
@Paullo9
Paullo9 deleted the claude/project-thread-b2qyav branch November 28, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: exspy's window path for an SEM spectrum: lines in range, windows, intensities and Cliff-Lorimer

2 participants