Skip to main content

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 of frac and areaWeight per 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 IntegratorFitPeaksGPUStream binary 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

Using a calibration from midas-calibrate-v2

midas-calibrate-v2 (the differentiable Bayesian rewrite of the calibration framework) exposes parameters under canonical names (iso_R2, iso_R4, iso_R6, a1/phi1, …, a6/phi6) instead of v1's p0..p14. Two routes exist for getting a v2 result into this package:

# (a) In-memory: drop the v2 unpacked dict straight onto a v1 template
from midas_integrate.params import parse_params
from midas_integrate.compat.from_v2 import params_from_v2_unpacked

template = parse_params("seed_paramstest.txt")  # carries binning, masks, …
ip = params_from_v2_unpacked(res.unpacked, template=template)
# (b) High-level: spline + δr_k sidecars + paramstest in one call
from midas_calibrate_v2.compat.to_integrate import to_integrate_params

ip = to_integrate_params(
    res,                      # PVCalibrationResult or FourStageResult
    template=template,
    output_dir="./integrate_in",
    ring_d_spacing_A=ring_d, ring_two_theta_deg=ring_tt,  # for δr_k JSON
)

What the adapter does for you:

  • Remaps iso_R* / a* / phi* to v1's p0..p14 slots.
  • Carries Lsd, BC_y/BC_z, tx/ty/tz, Parallax, pxY/pxZ, Wavelength through unchanged.
  • Warns when v2-only parameters are dropped (per-panel blocks → use midas_calibrate_v2.compat.to_v1.write_panel_shifts_file; per-ring δr_k → use the JSON sidecar from to_integrate_params and apply at the peak-fit / Rietveld stage, since v1's radial map has no per-ring concept).
  • For a FourStageResult, evaluates the Stage 4 thin-plate spline on the detector grid and writes the binary ΔR(Y, Z) lookup that IntegrationParams.ResidualCorrectionMap consumes.

The cache hash (Map.bin / nMap.bin) covers all 15 distortion coefficients and Parallax / Wavelength unconditionally, so changing any v2 parameter will correctly invalidate stale caches.

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.

Download files

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

Source Distribution

midas_integrate-0.6.0.tar.gz (104.9 kB view details)

Uploaded Source

Built Distribution

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

midas_integrate-0.6.0-py3-none-any.whl (85.7 kB view details)

Uploaded Python 3

File details

Details for the file midas_integrate-0.6.0.tar.gz.

File metadata

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

File hashes

Hashes for midas_integrate-0.6.0.tar.gz
Algorithm Hash digest
SHA256 23c44f4cf22de58ca569b521de0f7b8c250e3f607b9533e5f8f2002ab91f1000
MD5 cfc5ee3e70f8180d6632103153324aa5
BLAKE2b-256 c762988ab26e40521ae1c94bf8d26a93fd85db43ba869442991a1497a37fe359

See more details on using hashes here.

Provenance

The following attestation bundles were made for midas_integrate-0.6.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_integrate-0.6.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for midas_integrate-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc1cb9cbb2a7deaf77a31ce9ee3028fb85a8adad2ac70273f3cb3b02c0260133
MD5 4ba16cfc9782982d5faf18451738b38a
BLAKE2b-256 01f40f136455eb488494ef773d40457a7aad1e7873aec6fe26cb8809c6a4937e

See more details on using hashes here.

Provenance

The following attestation bundles were made for midas_integrate-0.6.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.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 files

0.5.1

2 files

0.5.0

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

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