Pure-Python radial integration for area X-ray detectors (MIDAS) — DetectorMapper + CSR integration + streaming server, CPU/GPU selectable
Project description
midas-integrate
Pure-Python radial integration for area X-ray detectors. A drop-in, pip-installable replacement for the MIDAS C/CUDA radial integration pipeline — no compilers, no native libraries, no CMake.
pip install midas-integrate
What's in the box
| C/CUDA source | Python module |
|---|---|
MapperCore.c, DetectorGeometry.c, DetectorMapper.c |
midas_integrate.detector_mapper, midas_integrate.geometry |
IntegratorFitPeaksGPUStream.cu (GPU streaming) |
midas_integrate.kernels, midas_integrate.server, midas_integrate.pipeline |
IntegratorZarrOMP.c (CPU OMP, bilinear) |
midas_integrate.kernels (mode='bilinear') |
PeakFit.c |
midas_integrate.peakfit |
PeakFitIO.c |
midas_integrate.peak_io |
Map.bin / nMap.bin |
midas_integrate.bin_io |
CPU/GPU selection
Everything that touches arrays accepts a device argument that is forwarded
to PyTorch. CPU and CUDA are first-class:
from midas_integrate import build_csr, integrate, profile_1d, load_map
pixmap = load_map('Map.bin', 'nMap.bin')
geom_cpu = build_csr(pixmap, n_r=990, n_eta=72, n_pixels_y=1475, n_pixels_z=1679, device='cpu')
geom_cuda = build_csr(pixmap, ..., device='cuda')
import torch
img = torch.from_numpy(image_2d)
profile = profile_1d(integrate(img, geom_cuda, mode='bilinear'), geom_cuda)
Three integration modes (full parity with C codes)
mode |
Equivalent C kernel | Use when |
|---|---|---|
'floor' |
integrate_noMapMask in IntegratorFitPeaksGPUStream.cu |
streaming, max throughput |
'bilinear' |
pixel loop in IntegratorZarrOMP.c lines 1733–1744 |
offline analysis, max accuracy |
'gradient' |
GradientCorrection=1 branch in the GPU stream |
strong tilt + small R |
CLI
Three entry points mirror the C binaries:
# 1. Build Map.bin / nMap.bin from a parameter file (one-shot, slow):
midas-detector-mapper params.txt -j 8
# 2. Integrate one frame (one-shot, fast):
midas-integrate params.txt --image frame.tif --device cuda
# 3. Streaming socket server (matches the C wire protocol on port 60439):
midas-integrate-server params.txt --device cuda --num-streams 4
Numerical parity
- DetectorMapper output (
Map.bin/nMap.bin): byte-equivalent to the C version (entry counts, sums offracandareaWeightper bin agree to ULP; entry order within a bin may differ). - Per-frame integration: float32 ULP-level (median 1.7e-8 relative error
vs the C/CUDA
IntegratorFitPeaksGPUStreambinary on PILATUS3 2M with CeO₂ data; max 2.1e-7 relative). - Peak fitting: same model (pseudo-Voigt + global background, SNIP background subtraction), different optimizer (scipy LM vs NLopt Nelder-Mead). Fit parameters typically agree to ~1e-5 relative on noisy real data.
Performance (PILATUS3 2M, 1475×1679, NVIDIA H100)
| Throughput | |
|---|---|
| C MIDAS GPU stream (per the paper) | ~1,600 fps |
| midas-integrate (PyTorch CSR, FP32, CUDA) | ~3,250 fps |
| midas-integrate (PyTorch CSR, FP64, CPU) | ~675 fps |
| C MIDAS CPU (per the paper) | ~262 fps |
| pyFAI CSR-cython (per the paper) | ~7 fps |
Requirements
- Python ≥ 3.9
- numpy, scipy, torch, tifffile, h5py, joblib
CUDA support is automatic if your installed torch has CUDA. macOS Metal (MPS)
works for the integration kernel; sparse-CSR support on MPS is partial as of
torch 2.7.
License
BSD-3-Clause. See LICENSE.
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_integrate-0.1.0.tar.gz.
File metadata
- Download URL: midas_integrate-0.1.0.tar.gz
- Upload date:
- Size: 73.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aeaa795df681898fb019ac361435e16863c8090d13bcec6c65f7a02b9da822bc
|
|
| MD5 |
2acad3798818dab7293769b483fb7afa
|
|
| BLAKE2b-256 |
08c41ccc81a9803bd7eded813c40e17e292a6a6cca6cbf9768aaf3fd17aa98d9
|
Provenance
The following attestation bundles were made for midas_integrate-0.1.0.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_integrate-0.1.0.tar.gz -
Subject digest:
aeaa795df681898fb019ac361435e16863c8090d13bcec6c65f7a02b9da822bc - Sigstore transparency entry: 1397049314
- Sigstore integration time:
-
Permalink:
marinerhemant/MIDAS@bbd3aa6beec8ffcc33a86cb7a68445fb2cd36d23 -
Branch / Tag:
refs/tags/midas-integrate-v0.1.0 - Owner: https://github.com/marinerhemant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-packages.yml@bbd3aa6beec8ffcc33a86cb7a68445fb2cd36d23 -
Trigger Event:
release
-
Statement type:
File details
Details for the file midas_integrate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: midas_integrate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 66.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 |
bb25cc4fc373c75951c1b961fe518c43bc8c477645373bf0ad20a52e22b9ca22
|
|
| MD5 |
4665576cb4debe688d02d2209d108df1
|
|
| BLAKE2b-256 |
d17ccfc92b5b34c7b17aad4e63b65afe417829e4844a17cb0ed699eb83896257
|
Provenance
The following attestation bundles were made for midas_integrate-0.1.0-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_integrate-0.1.0-py3-none-any.whl -
Subject digest:
bb25cc4fc373c75951c1b961fe518c43bc8c477645373bf0ad20a52e22b9ca22 - Sigstore transparency entry: 1397049372
- Sigstore integration time:
-
Permalink:
marinerhemant/MIDAS@bbd3aa6beec8ffcc33a86cb7a68445fb2cd36d23 -
Branch / Tag:
refs/tags/midas-integrate-v0.1.0 - Owner: https://github.com/marinerhemant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-packages.yml@bbd3aa6beec8ffcc33a86cb7a68445fb2cd36d23 -
Trigger Event:
release
-
Statement type: