Repository navigation
feat: origin from the Bragg peaks (measure_origin, fit_origin) with a symmetry centre guess - #75
Merged
Merged
Conversation
Started for mac4DSTEM#138 and parked on 2026-11-05 at Paul's request (for later, not before the App Store launch). Untested draft: BraggOrigin.swift, its fixture and the pin script. Not for merge as is. Done: draft port parked on this branch. Next: finish, parity test, review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n) and a symmetry centre guess BraggOrigin.measure and BraggOrigin.fit port py4DSTEM's BraggVectors.measure_origin and fit_origin, pinned on planted peaks (tools/bragg-origin/pins.py). OriginFit.fit takes fit_origin's boolean mask. BraggOrigin.symmetryCenterGuess is a mac4DSTEM variant: the centre about which the map of peak counts is most point-symmetric, so a distance score finds the direct beam where a reflection is brighter than it (py4DSTEM's Si/SiGe tutorial cube). Refs mac4DSTEM/mac4DSTEM#138 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VkKZEUZ2RdEgWryyPgjZzR
A lattice whose disks are all detected equally often has equal counts at every disk, so a top-12 cut could leave its centre out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VkKZEUZ2RdEgWryyPgjZzR
…loop) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VkKZEUZ2RdEgWryyPgjZzR
…r fit_origin rows py4DSTEM fits by curve_fit, which stops about 1e-6 px from the least-squares surface on these pins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VkKZEUZ2RdEgWryyPgjZzR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Paul · project thread
What and why
For mac4DSTEM/mac4DSTEM#138: on py4DSTEM's Si/SiGe tutorial cube the centre-of-mass origin is pulled 6–10 px off the direct beam by strong disks, so the Bragg vector map smears and strain refuses. This adds the origin from the detected Bragg peaks.
BraggOrigin.measure/BraggOrigin.fit: py4DSTEM'sBraggVectors.measure_originandfit_origin, pinned on planted peaks (tools/bragg-origin/pins.py, fixturebraggorigin.json). Chosen peaks exact; raw map at assert_allclose Float64 (rtol 1e-7, atol 1e-12); fitted surfaces at np.allclose defaults like the existingfit_originrows (upstream'scurve_fitstops about 1e-6 px from the least-squares surface). Deviations are named in the doc comments anddocs/parity.md(upstream's guess is always (0, 0) because it passes the map object togaussian_filter).BraggOrigin.rawHistogram:histogram(mode="raw"), public.OriginFit.fit(mask:): fit_origin's boolean mask; the robust loop scores masked positions as upstream does. Defaultnil, so existing calls are unchanged.BraggOrigin.symmetryCenterGuess(mac4DSTEM variant, not in py4DSTEM): the maximum of the peak-count map about which that map is most point-symmetric (Friedel), over every maximum above 5%. Pinned to a NumPy/SciPy transcription in the same script.Additive only: no existing function changes its output.
Before / after on Si/SiGe, full scan (py4DSTEM 0.14.19, 50 × 200 scan, 128 × 128 detector)
downsample_Si_SiGe_exp.h5(md5 c363d362…). Peaks fromfind_Bragg_disks(synthetic sigmoid template, r = 3.74 px, 20.8 peaks per position). Origin fitted as a plane. "Top-40 share": share of the origin-corrected Bragg vector map in its 40 brightest pixels (sharp map = high). "Indexed": share of all peaks within 1 px of a maximum of that map.The CoM scatter (8.8 / 6.4 px) matches what #138 reported for py4DSTEM's
get_origin. The direct beam is at (64, 64); a first-order disk at (49, 69) is brighter, so py4DSTEM's guess and intensity score pick it.Checklist
swift test -c releasepasses (CI)BraggOriginTests)docs/parity.md) updated🤖 Generated with Claude Code
https://claude.ai/code/session_01VkKZEUZ2RdEgWryyPgjZzR