Skip to content

Fit strain live against a reference pattern built once before the scan - #50

Open
CSSFrancis wants to merge 6 commits into
mainfrom
feat/strain-reference
Open

CSSFrancis wants to merge 6 commits into
mainfrom
feat/strain-reference

Conversation

@CSSFrancis

Copy link
Copy Markdown
Member

Summary

Strain against a real reference pattern, fitted over the whole pattern, fast enough to run live during a scan.

  • StrainReference (de_ebsd.index.live.reference), built once before a scan from the reference point's summed frames:
    • The frames are binned to at most 1024 rows and divided by their own blur.
    • The result is projected onto an equal-area texture over the sample frame, sampled through its cubic B-spline.
  • StrainReference.fit fits each pattern against that texture with the existing fused CUDA kernel:
    • eight trace-free numbers, over the interior pixels only (a 5% margin);
    • each pattern at its own pattern center;
    • optionally seeded with the lattice turn its orientation gives.
    • It returns the deviatoric strain, the lattice rotation and the score.
  • LiveIndexer.strain_reference and DynamicalIndexer.strain_reference build one from frames.
  • strain_from_reference takes a built reference.
    • DynamicalIndexer.strain_from_reference now returns (strain, rotation_vector, score) and takes pattern_centers.
    • Without CUDA it falls back to fit_reference, the pyramid fit added here, with a polynomial contrast surface.

Measured

  • Real data (Si nano-indent, DE Meridian 2048², 64×64 scan, 25 nm step). Rows 5 and 60 were compared against the research maps at 1024:
    • slope 0.986–1.010 and correlation ≥ 0.995 in every component;
    • median difference 0.6–1.8e-5.
  • Speed: about 20 ms per pattern at 1024 in batches of 64, of which about 8.5 ms is the background blur. Building the reference takes 1.8 s.
  • Synthetic error: 4e-5 with the lattice not turned, 2.7e-4 at a 2° turn; tolerances are set from these.
    • Dividing a pattern by its own blur takes a few percent of the strain at turns of degrees, which is noted on FLATTEN_SIGMA.
    • Callers should keep the grain small; Autopilot uses 1.5°.

Tests

  • tests/index/test_strain_reference.py (CUDA).
  • tests/index/test_reference_fit.py, test_live.py and test_multiphase.py.
  • tests/test_dynamical_indexer_seam.py, which adds a CUDA seam test.
  • 94 pass.
  • test_kinematic_indexing.py::test_invariant_to_gain_and_offset already fails on main.

Autopilot's PR, which uses this, follows. It needs a release containing this one.

…entations

strain_from_reference fitted regions' shifts; it now fits every pixel inside the
margin by Gauss-Newton on a pyramid (integrated DIC against a real reference),
seeded from the lattice rotation the indexed orientations give. On synthetic
patterns a 2e-3 strain came back within about 1e-4 out to 5 degrees, where the
region correlation was off by 1.6e-3 at half a degree.
…n's soft directions

On a real Si indent the fit of a pattern against itself left the identity,
tenfold an iteration, once a call held two patterns on CUDA: the ill-conditioned
normal equations, summed in single over the pattern, carried 1.5e-4 of rounding.
They are summed in single by chunks of 4096 pixels and the chunks in double,
as accurate as double throughout and six times faster on a workstation GPU.

Gauss-Newton wandered along the rotations a single pattern barely tells from a
moved pattern center; each level is Levenberg-Marquardt now, a step kept only
if it lowers the residual, with 50 iterations a level.
…re it

StrainReference projects the summed reference onto an equal-area texture by
its cubic B-spline and fits each pattern, binned to at most 1024 rows and
flattened by its own blur, on the fused CUDA kernel, seeded from the
orientations and at each point's pattern center. LiveIndexer and
DynamicalIndexer build one with strain_reference; DynamicalIndexer's
strain_from_reference takes it and returns strain, rotation and score.
At 1024 x 1024 the 64-pixel Gaussian took 8.5 ms a pattern, as long as the fit
itself; averaged down by 8 and drawn back up it takes 0.17 ms. On 16 Si indent
patterns against a 25-frame reference the strain moved by 3e-6 (median), 1.6e-5
at most: the differences sit at the screen's edges, which the fit leaves out.
The fit's cost goes with its pixels: 0.9, 2.6 and 11 ms a pattern at 256, 512
and 1024 on a TITAN X, so an application picks the size its scan's frame rate
allows.
…y binned

A fit call costs about the same for 8 patterns as for 32, so a live consumer
that gets a dozen frames at a time gathers them, binned, and fits them together.

This branch has not been deployed

No deployments
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