Skip to main content

Differentiable forward + inverse for Dark-Field X-ray Microscopy (DFXM): deformation-gradient field imaging through a magnifying objective, and per-dislocation defect-type discrimination, on top of midas-stress / midas-hkls / midas-defect.

Project description

midas-dfxm

Differentiable forward + inverse for Dark-Field X-ray Microscopy (DFXM).

DFXM images a bulk grain through a magnifying objective (CRL / MLL) placed on one diffracted beam. The objective is a reciprocal-space bandpass: a sample voxel contributes intensity to its magnified detector pixel only if its local scattering vector falls inside the instrument's resolution function for the current goniometer setting. Rocking the sample (a mosaicity scan) maps local orientation; scanning 2θ / energy (a strain scan) maps local d-spacing; weak-beam settings image individual dislocations.

This package models that signal from a voxelised deformation-gradient field F(r), and (later phases) inverts a DFXM image stack back to F(r) and to per-dislocation defect types (edge/screw, Burgers vector, slip system).

Reuse-first, no re-porting. Built on the MIDAS differentiable stack: midas-stress (orientation/strain), midas-hkls (structure factors, form factors, DWF), midas-2d (continuous-q structure factor, resolution convolution), midas-defect (Stroh anisotropic-elasticity contrast solver, slip systems, GND, planar-defect rods), midas-invert (fit / UQ / experiment design), midas-distortion (detector model). Everything is torch-differentiable and device-portable (CPU / CUDA / MPS).

See implementation_plan.md for the full roadmap, physics reuse map, phase gates, and honest scope/novelty gates.

Status

Pre-alpha (v0.0.1a0). Phases 0,1,3,4,5 + a simulation-anchored roadmap implemented and tested — 64 tests pass (CPU + MPS; 3 CUDA-skipped), ~2400 LOC.

Highlights:

  • Phase 4 (defect typing): anisotropic-elasticity (Stroh) per-dislocation forward; g·b invisibility; edge/screw character; Burgers-vector recovery.
  • Phase 5 (inverse typing): identify_dislocation recovers slip system, character, core position, and the Burgers-vector sign (the gap Borgi 2025 leaves open) from multi-reflection weak-beam images.
  • Phase 3 (field inverse): full strain-tensor recovery + identifiability + UQ; honest finding — regularisation helps at low SNR, ~neutral at high SNR.
  • #1 physics coupling: recover a GND density end-to-end through the forward (Nye κ = ρb) — the DFXM↔DDD/CP interface, differentiably.
  • #2 credibility anchor: independent numpy oracle agrees bit-for-bit (~1e-16).
  • Borbély-ready: field_from_deformation_gradient consumes an external F(r) with zero rework.

See SIMULATION_CATALOG.md and examples/ (figures land in dev/paper/figures/).

Earlier milestone note

Phases 0–1 implemented and tested (30 passing, CPU + MPS):

  • Phase 0 — conventions + field. conventions.py (lab/sample/imaging frames, goniometer), field.py (DeformationField, the kinematic deform operator Q = F⁻ᵀ G0, polar decomposition F = R·U), io.py (synthetic-field generators: perfect crystal, orientation gradient, uniform strain, isotropic screw dislocation; plus a stub loader for Borbély's field).
  • Phase 1 — geometrical-optics forward. resolution.py (anisotropic-Gaussian reciprocal-space acceptance), optics.py (magnifying inclined projection + bilinear detector splat), scan.py (mosaicity / rocking / strain scan builders, Bragg-angle helpers), forward.py (dfxm_image, dfxm_stack, mosaicity_curve).

Validated analytic limits: rocking-curve FWHM = 2√(2ln2)·σ⊥ / |axis×q|, FCC forbidden reflection is dark, uniaxial strain shifts |Q| correctly; plus gradcheck on the deform operator and end-to-end autograd to F and the instrument widths.

Next: Phase 2 (field forward on Borbély's realistic F(r) when it lands), Phase 3 (field inverse + identifiability study), Phase 4 (per-dislocation forward via the Stroh solver + g·b defect typing), Phase 5 (inverse defect discovery).

Quickstart

import torch
from midas_dfxm import (
    make_uniform_field, with_orientation_gradient,
    GoniometerSetting, reference_q_nom, aligned_resolution,
    ObjectiveOptics, bragg_two_theta_deg, dfxm_image,
)

# A curved crystal grain (smooth lattice rotation across x).
field = make_uniform_field(shape=(64, 64, 1), spacing_um=0.5)
field = with_orientation_gradient(field, axis=(0, 0, 1), deg_per_um=0.01, along=0)

hkl, center = (1, 1, 1), GoniometerSetting()
q_nom = reference_q_nom(field, hkl, center)
res = aligned_resolution(q_nom, sigma_par=5e-3, sigma_perp=5e-3)
tt = bragg_two_theta_deg(float(torch.linalg.vector_norm(q_nom)), wavelength_A=0.172979)
optics = ObjectiveOptics(two_theta_deg=tt, magnification=10.0, detector_shape=(256, 256))

image = dfxm_image(field, hkl, center, res, optics)   # (256, 256), differentiable

Tests

# macOS: work around the duplicate-OpenMP-runtime abort (torch + MIDAS siblings).
export KMP_DUPLICATE_LIB_OK=TRUE
python -m pytest tests/ -q

Markers: unit (analytic correctness), autograd (gradcheck / autograd), device (CPU/CUDA/MPS parity), slow (heavy integration).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

midas_dfxm-0.2.0.tar.gz (105.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

midas_dfxm-0.2.0-py3-none-any.whl (91.5 kB view details)

Uploaded Python 3

File details

Details for the file midas_dfxm-0.2.0.tar.gz.

File metadata

  • Download URL: midas_dfxm-0.2.0.tar.gz
  • Upload date:
  • Size: 105.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for midas_dfxm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 abe3c5d29bbf1bfef5f1c2b6a410c9d96c4e3fdfe4b2612ab007371279e71a77
MD5 d3afe0bc5e3546312dd74ee8d42bd030
BLAKE2b-256 419f37581b1fa0f666bb815ed6ff9310aa244d3bb86f155c69ebb705bebf68d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for midas_dfxm-0.2.0.tar.gz:

Publisher: python-packages.yml on marinerhemant/MIDAS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file midas_dfxm-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: midas_dfxm-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 91.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for midas_dfxm-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b25dea3e19905a10f4735a0d2760f4d24df7c886018ce95db37f6c9ca5482e5
MD5 9340d70960e5cf2c42448c34d37fccff
BLAKE2b-256 2a1b209f046e8112f85eae60554ba8b0d575757ff2b53e1aab29cf1e8f30bb14

See more details on using hashes here.

Provenance

The following attestation bundles were made for midas_dfxm-0.2.0-py3-none-any.whl:

Publisher: python-packages.yml on marinerhemant/MIDAS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page