Native Python/Torch detector calibration for MIDAS — replaces AutoCalibrateZarr → CalibrantIntegratorOMP. CPU & GPU; LM-based refinement.
Project description
midas-calibrate
Native Python/Torch detector geometry calibration for MIDAS. Replaces
AutoCalibrateZarr → CalibrantIntegratorOMP → CalibrationCore. Same input
parameter file format, byte-compatible output, runs on CPU or GPU.
Quick start
import tifffile
from midas_calibrate import CalibrationParams, autocalibrate
params = CalibrationParams.from_file("calib.txt")
image = tifffile.imread("ceo2_calibrant.tif")
result = autocalibrate(params, image)
result.params.write("calib_refined.txt")
print(f"final mean strain: {result.history[-1].mean_strain_uE:.1f} μϵ")
CLI:
midas-autocalibrate calib.txt --image ceo2.tif --output calib_refined.txt
How it works
- E-step —
midas-integratebuilds a CSR pixel→bin map from the current geometry and integrates the image into a 2D (R, η) cake. Per (ring × η-bin) the radial peak position is extracted via weighted centroid. - M-step — fit detector geometry to the (Y_pix, Z_pix, ring) data using a
custom batched Levenberg-Marquardt solver (
midas_peakfit.lm_solve_generic) with sigmoid-bounded reparameterisation, Cholesky_ex, and optional Huber loss reshaping. - Orchestrator — alternating E↔M iterations with optional σ-clip outlier rejection between iterations.
The geometry forward model in geometry_torch.py
is a byte-for-byte port of midas_integrate.geometry.pixel_to_REta — verified
to fp64 epsilon by parity tests.
Dependencies
midas-hkls— pure-Python crystallography (sginfo replacement)midas-integrate— CSR pixel→bin mapper + integrationmidas-peakfit≥ 0.2.0 — generic LM solver
Synthetic-data parity test
The end-to-end synthetic test forward-simulates a CeO₂ calibrant image at known geometry, perturbs the seed (Lsd ±300μm, BC ±1.5px, tilts ±0.06°), and verifies recovery:
[iter 0] n_fits= 176 rc=0 strain= 105.2μϵ Lsd=1000219.4 BC=(512.20,511.91) ty=0.343 tz=0.180
[iter 1] n_fits= 176 rc=0 strain= 25.7μϵ Lsd= 999973.5 BC=(512.01,512.00) ty=0.403 tz=0.250
[iter 2] n_fits= 176 rc=0 strain= 19.4μϵ Lsd= 999946.1 BC=(511.99,512.00) ty=0.400 tz=0.267
[iter 3] n_fits= 176 rc=0 strain= 21.6μϵ Lsd= 999918.1 BC=(511.99,512.00) ty=0.392 tz=0.285
Final recovery: Lsd within 82μm of truth, BC within 0.01 px, tilts within 0.04°. Mean strain 21.6μϵ, well under the 50μϵ MIDAS calibration target.
Engines
autocalibrate is the alternating E↔M engine (default).
autocalibrate_joint will be the fully differentiable engine — geometry +
per-(ring × η-bin) peak-shape parameters jointly refined in one batched
Schur-complement-reduced LM (see §13 of the design doc). v0.1 ships with a
working stub that delegates to the alternating engine; the arrowhead-LM
infrastructure (midas_peakfit.lm_solve_arrowhead) is in place and tested.
Status
v0.1.0 — alternating engine production-ready, joint engine scaffolded.
See AutoCalibrate.md for the manual and
calibrate_torch_implementation_plan.md
for the full design and roadmap.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file midas_calibrate-0.2.1.tar.gz.
File metadata
- Download URL: midas_calibrate-0.2.1.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
961a95ea056082a64fd59ef41ce7eea35e3dbc7b959bbe9b09fd4e7ac0cb9ff0
|
|
| MD5 |
c320a8093f3b71c00042872c82075827
|
|
| BLAKE2b-256 |
3146189dbee77b7fc2fc34dadb2359cbd8aa469a99aa66a79577211130876758
|
Provenance
The following attestation bundles were made for midas_calibrate-0.2.1.tar.gz:
Publisher:
python-packages.yml on marinerhemant/MIDAS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
midas_calibrate-0.2.1.tar.gz -
Subject digest:
961a95ea056082a64fd59ef41ce7eea35e3dbc7b959bbe9b09fd4e7ac0cb9ff0 - Sigstore transparency entry: 1397422335
- Sigstore integration time:
-
Permalink:
marinerhemant/MIDAS@c6828f52154681a30609088c27370d7ddddc19e3 -
Branch / Tag:
refs/tags/midas-calibrate-v0.2.1 - Owner: https://github.com/marinerhemant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-packages.yml@c6828f52154681a30609088c27370d7ddddc19e3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file midas_calibrate-0.2.1-py3-none-any.whl.
File metadata
- Download URL: midas_calibrate-0.2.1-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37fa3fbd1a5bee47d4bbcf359e0d6352f1a39bef951586443338e98527acccab
|
|
| MD5 |
619e5455d26254961d61756854a02b1a
|
|
| BLAKE2b-256 |
61ce261d9b2e2e8f415ddf9e54fc1d8c2042741cd82f6077ed7f6eea6a9f9132
|
Provenance
The following attestation bundles were made for midas_calibrate-0.2.1-py3-none-any.whl:
Publisher:
python-packages.yml on marinerhemant/MIDAS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
midas_calibrate-0.2.1-py3-none-any.whl -
Subject digest:
37fa3fbd1a5bee47d4bbcf359e0d6352f1a39bef951586443338e98527acccab - Sigstore transparency entry: 1397422338
- Sigstore integration time:
-
Permalink:
marinerhemant/MIDAS@c6828f52154681a30609088c27370d7ddddc19e3 -
Branch / Tag:
refs/tags/midas-calibrate-v0.2.1 - Owner: https://github.com/marinerhemant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-packages.yml@c6828f52154681a30609088c27370d7ddddc19e3 -
Trigger Event:
release
-
Statement type: