Skip to content

Commit 9a2d5ef

Browse files
committed
defect: pass the pipeline distortion coefficients to the forward model
build_forward_model negated the amplitudes of the converted distortion coefficients before handing them to midas_diffract's HEDMForwardModel. That was a first-order inverse written for a forward model that applied the pipeline's correction (raw -> ideal) in the wrong direction. The midas_diffract commit "FF tilt convention and forward distortion direction" makes the model invert the correction itself, with a fixed point, so the compensation now double-inverts: with a tilted and distorted geometry (p0 = 1e-4) the forward model and the reference predictor raster.predict_reflections disagreed by 0.078 px, against the 1e-2 px the test requires. CI caught it on the first run after that change: test_forward_model_matches_reference_predictor for the "tilted+distortion" and "tilted+distortion+wedge" cases. The coefficients are now passed as md.v1_to_v2_coeffs returns them. This also removes the O(delta^2) residual the negation left (about 2e-3 px for realistic coefficients). The two predictors are independent implementations (the reference path uses midas_transforms apply_tilt_distortion), so their agreement without the negation is a second check that the midas_diffract direction is right. Needs midas-diffract >= 0.10.0: the floor is raised from 0.9.0 and midas-defect goes from 0.9.0 to 0.9.1. With an older midas_diffract the distortion would now be applied in the wrong direction. Behaviour change: spot positions predicted by build_forward_model for a geometry with distortion move by up to the size of the distortion (about 0.08 px for the test geometry), toward the reference predictor. Index-from-cloud results that used distortion on a calibrated geometry should be re-checked. Tests: tests/test_indexing_forward_conventions.py passes for all four cases (flat, tilted, tilted+distortion, tilted+distortion+wedge).
1 parent 928d07b commit 9a2d5ef

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

‎packages/midas_defect/midas_defect/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# time (before either runtime initializes) so callers don't hit a hard crash.
1414
os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "TRUE")
1515

16-
__version__ = "0.9.0"
16+
__version__ = "0.9.1"

‎packages/midas_defect/midas_defect/indexing.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,18 @@ def build_forward_model(crystal, geom: Geometry, *,
113113
# multi_mode="panel"; the default "layered" mode applies the NF ray-plane intersection,
114114
# which put spots a median 7.6 px off at tilts (0.3, 0.15, 0.37) deg.
115115
# * distortion: the 15-term p_coeffs were not passed at all. They are LEGACY paramstest
116-
# p0..p14 applied raw -> ideal by midas_transforms; HEDMForwardModel applies the
117-
# midas_distortion v2 layout ideal -> raw. The bridge is v1_to_v2_coeffs (a reindex) with
118-
# the AMPLITUDES negated and the phases kept: the first-order inverse of D = 1 + delta,
119-
# leaving an O(delta^2) residual (~2e-3 px for realistic coefficients).
116+
# p0..p14 applied raw -> ideal by midas_transforms. HEDMForwardModel (midas_diffract >= 0.10.0)
117+
# takes those same coefficients (v1_to_v2_coeffs is a reindex) and inverts the correction itself
118+
# (fixed point), so they are passed as they are. Before 0.10.0 the model applied the correction
119+
# in the wrong direction and this code compensated with negated AMPLITUDES (a first-order
120+
# inverse with an O(delta^2) residual); with 0.10.0 that compensation would double-invert.
120121
# With all three, the two predictors agree to <1e-2 px (tests/test_indexing_forward_conventions.py).
121122
omega_edge = geom.omega_first_deg - 0.5 * geom.omega_step_deg
122123
has_dist = any(abs(float(p)) > 0 for p in geom.p_coeffs)
123124
p_ideal_to_raw = None
124125
if has_dist:
125126
import midas_distortion as md
126-
v2 = np.asarray(md.v1_to_v2_coeffs(np.asarray(geom.p_coeffs, float)), float)
127-
amp = np.array([not n.startswith("phi") for n in md.P_COEF_NAMES])
128-
p_ideal_to_raw = np.where(amp, -v2, v2).tolist()
127+
p_ideal_to_raw = np.asarray(md.v1_to_v2_coeffs(np.asarray(geom.p_coeffs, float)), float).tolist()
129128
hgeom = HEDMGeometry(
130129
Lsd=geom.lsd_um, y_BC=geom.bcy_px, z_BC=geom.bcz_px, px=geom.px_um,
131130
omega_start=omega_edge, omega_step=geom.omega_step_deg,

‎packages/midas_defect/pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "midas-defect"
7-
version = "0.9.0"
7+
version = "0.9.1"
88
description = "Differentiable, phase-agnostic diffuse-scattering defect metrology on top of standard FF-HEDM: intensity-budget closure, per-grain dislocation density, fault-rod and selection-rule tests."
99
readme = "README.md"
1010
license = "BSD-3-Clause"
@@ -41,7 +41,7 @@ dependencies = [
4141
# midas_hkls.asymmetry_sign_test, added there;
4242
# >=0.11 for centring_allowed, which rows.py now delegates to
4343
"midas-stress>=0.1", # quat / rotation / misorientation primitives
44-
"midas-diffract>=0.9.0", # HEDMForwardModel for predicted spot positions; >=0.2.0 for the
44+
"midas-diffract>=0.10.0", # HEDMForwardModel for predicted spot positions; >=0.2.0 for the
4545
# distortion layer and FF-panel tilts build_forward_model now uses
4646
"midas-distortion>=0.2.0", # v1 -> v2 coefficient bridge in indexing.build_forward_model
4747
"midas-index>=0.1", # initial-pass indexer for seed_index.py

0 commit comments

Comments
 (0)