midas-transforms
Pure-Python / PyTorch FF-HEDM intermediate transforms — the four stages between peak-fitting and indexing in the MIDAS workflow.
Drop-in replacement for these C binaries:
| C binary | Python entry point |
|---|---|
MergeOverlappingPeaksAllZarr |
midas-merge-peaks |
CalcRadiusAllZarr |
midas-calc-radius |
FitSetupZarr |
midas-fit-setup |
SaveBinData |
midas-bin-data |
Plus an end-to-end midas-transforms pipeline <zarr> that runs all four on
GPU with no CSV / binary disk round-trips between stages.
Why
- Speed. Vectorised PyTorch kernels target ≥ 1× C on CPU and 5–50× on GPU at production scale. Binning and merge are the workflow's longest tails; both are now broadcast + scatter operations.
- Bit-matching with C. Every deterministic stage targets byte-exact
output at float64. The geometry refine (
DoFit==1) targets physics-meaningful tolerance viamidas-calibrate.refine_geometry(LM with ADAM fallback — no NLopt, no Nelder-Mead). - Differentiable. All geometry parameters that flow through detector
projection (
Lsd,BC_y,BC_z,tx/ty/tz,p0..p14,wedge,dLsd,dP2, residual-correction map values) carry full autograd throughapply_tilt_distortion— useful for joint calibration with downstream grain mapping. - CPU/GPU portable. Single
device=switch (cpu / cuda / mps). No separate.cucodebase. No C extensions, nocibuildwheel.
Install
pip install -e packages/midas_transforms
(Until uploaded to PyPI; once released, pip install midas-transforms.)
Notebooks
Worked-example Jupyter notebooks live in notebooks/. They are not shipped with pip install — get them by cloning the MIDAS repository.
Quick start
Per-stage CLI (drop-in for the C binaries)
midas-merge-peaks scan.zip
midas-calc-radius scan.zip
midas-fit-setup scan.zip
midas-bin-data --result-folder .
End-to-end Pipeline (intermediates stay on GPU)
midas-transforms pipeline scan.zip --device cuda --out-dir /scratch/run42
Library
from midas_transforms import Pipeline
pipe = Pipeline.from_zarr("scan.zip", device="cuda")
result = pipe.run()
result.merge # (N, 17) on GPU
result.radius # (N, 24) on GPU
result.fit_setup # InputAll/Extra tensors on GPU
result.bins # Spots/ExtraInfo/Data/nData tensors on GPU
pipe.dump("/scratch/run42")
Or use stages individually:
from midas_transforms import merge_overlapping_peaks, calc_radius, fit_setup, bin_data
merge_overlapping_peaks(zarr_path="scan.zip", device="cuda")
calc_radius(result_folder=".", zarr_params=..., device="cuda")
fit_setup(result_folder=".", zarr_params=..., device="cuda")
bin_data(result_folder=".", device="cuda")
Wiring into ff_MIDAS.py
ff_MIDAS.py accepts a --useTorchTransforms 1 flag (mirrors the
existing --useTorchIndexer / --peakFitGPU flags). When set, the
workflow's merge_overlaps, calc_radius, data_transform, and
binning stages dispatch to the Python entry points instead of the C
binaries. Outputs are byte-compatible (or numerically equivalent for
the DoFit geometry refine).
Limits
- Scanning workflows (
SaveBinDataScanning,MergeMultipleScans) are out of scope here; they belong with the broader scanning pipeline. - ResidualCorrectionMap filename is parsed from Zarr but the per-pixel
ΔR map isn't yet sampled in
apply_tilt_distortion(the bilinear sampler exists; thenp.fromfile(...).reshape(NrPixelsZ, NrPixelsY)load is a TODO infit_setup/core.py).
See also
dev/implementation_plan.md— full design, scope, and risk register.midas-peakfit— upstream peak-fitting (writes the consolidated HDF5).midas-index— downstream indexer (consumesSpots.bin/Data.bin).midas-calibrate— providesgeometry_torch.pixel_to_REta_torchandrefine_geometry(LM solver) used byfit_setup.midas-hkls— upstreamhkls.csvgeneration.
Metadata
Release files for midas-transforms 0.12.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| midas_transforms-0.12.0.tar.gz | 232.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| midas_transforms-0.12.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 395.5 kB
Release files / midas_transforms-0.12.0.tar.gz
| Download URL | midas_transforms-0.12.0.tar.gz |
|---|---|
| Size | 232.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9401f63e030ea863367b1f8ba685082d0cd7c4d05f7e04cc61c81ab6d409b83
|
|
BLAKE2b-256 checksum How to use checksums |
b37c77d2b07e53ff35aa6a68d3573fdb1aa77b4224df8c9cfe028d4bf7a4b022
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / midas_transforms-0.12.0-py3-none-any.whl
| Download URL | midas_transforms-0.12.0-py3-none-any.whl |
|---|---|
| Size | 163.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9dac7945a39f4823b8d25aed3711ccde2eed3c92176af972d7b0086eb6f9fe66
|
|
BLAKE2b-256 checksum How to use checksums |
6fedcdba6af651762649c997f701b4740fada8f7660c7012f5a5d1b99f5d3739
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency log