Skip to content

Add multidimensional drift correction and strip-based alignment - EDS, 4DSTEM prior to arXiv - #283

Open
bobleesj wants to merge 12 commits into
electronmicroscopy:driftfrom
bobleesj:drift-paper
Open

Add multidimensional drift correction and strip-based alignment - EDS, 4DSTEM prior to arXiv #283
bobleesj wants to merge 12 commits into
electronmicroscopy:driftfrom
bobleesj:drift-paper

Conversation

@bobleesj

@bobleesj bobleesj commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

What problem this PR addreseses

Support 3D, 4DSTEM drift correction.

PRs broken down as shown below:

Before

src/quantem/imaging/
├── drift.py              1,832 lines
└── drift_utils.py          664 lines

After

├── correction.py         orchestration
├── preprocess.py        input preparation
├── apply.py              dataset propagation
├── diagnostics.py        numerical diagnostics
├── report.py             structured summary
├── io.py                 EMD metadata and pairing
├── fourdstem.py           4D-STEM collection logic
├── plot.py               visual diagnostics
└── core/
    ├── affine.py
    ├── strip.py
    ├── nonrigid.py
    ├── knots.py
    └── warping.py

Public API change

existing usage proposed usage why
from_data(...) from_images(...) 2D images - different from from 4dstem, 3d dataset
align_translation() Same translation is align
align_affine() correct_affine() affine is correcting knots
align_nonrigid() correct_nonrigid() non-rigid is correcting knots
generate_corrected() corrected() concise, pythonic
number_knots, step num_knots, max_drift_rate clarifies the model count and physical search meaning

Affine speed:

metric scipy full, cpu (2016 paper) torch full, cuda torch automatic pyramid, cuda
algorithm time 2439.956 s 5.788 s 0.441 s
speedup vs scipy 421.5× 5536.0×
drift rate, row (px/line) -0.073000 -0.073000 -0.072461
drift rate, col (px/line) 0.139000 0.139000 0.139648

The pyramid downsampling strategy enables real-time drift correction on any personal laptops.

What should the reviewer(s) do

Tutorials are available here: https://github.com/bobleesj/quantem-tutorials/tree/drift-tutorial/tutorials/imaging/drift
.

Screenshot 2026-08-26 at 10 31 08 AM Screenshot 2026-08-26 at 10 42 46 AM

bobleesj and others added 12 commits August 24, 2026 21:25
refactor: split drift into a package without behavior changes
* feat: add drift registration diagnostics

* feat: add structured drift reports

* feat: add static drift diagnostic plots

* test: validate drift diagnostics on frozen results

* fix: keep drift diagnostics consistent with fitted state
* feat: add reference-based spectrum-image correction

* fix: reject ambiguous spectrum-image reference matches
* feat: add reference-based spectrum-image correction

* fix: reject ambiguous spectrum-image reference matches

* feat: propagate drift across 4D-STEM scan axes

* test: protect 4D-STEM detector coordinates

* test: compare full detector signature field

* test: verify 4D-STEM coverage and output residency

* fix: stream native 4D-STEM scan correction

* test: compare native detector frames across backends

* test: set float32 backend parity tolerance
* feat: add reference-based spectrum-image correction

* fix: reject ambiguous spectrum-image reference matches

* feat: propagate drift across 4D-STEM scan axes

* test: protect 4D-STEM detector coordinates

* test: compare full detector signature field

* test: verify 4D-STEM coverage and output residency

* fix: stream native 4D-STEM scan correction

* test: compare native detector frames across backends

* test: set float32 backend parity tolerance

* feat: preserve calibration during drift downsampling

* test: lock downsampled coordinate provenance

* perf: add average-pooled affine pyramid search

* test: compare native and pyramid affine rates

* feat: add strip-wise residual correction primitives

* fix: make nonrigid regularization portable across torch backends

* feat: propagate residual fields to calibrated element maps

* test: lock residual-correction publication contracts

* test: recover known strip residual shifts

* feat: complete automatic affine manuscript parity

* feat: complete multi-knot manuscript parity

* test: verify complete manuscript workflow parity

* fix: keep 4D-STEM integration usable without optional GPU package

* refactor: adopt the scientist-facing Drift API

* test: verify manuscript output frame contracts

* fix: preserve natural corrected output frames

* feat: expose manual translation alignment
@bobleesj

Copy link
Copy Markdown
Collaborator Author

@wwmills ready for review.

If you agree with the API proposed and folder architecture, we can probably merge so that you can add your new algo as needed and refactor with upcoming PRs. This PR is to enable further scaling of features and reproduce manuscript results.

@bobleesj
bobleesj requested a review from wwmills August 26, 2026 17:41
@bobleesj
bobleesj marked this pull request as ready for review August 26, 2026 17:41
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.

1 participant