Repository files navigation

MIDAS Logo

MIDAS — Microstructural Imaging using Diffraction Analysis Software

License

MIDAS is an open-source suite for reconstructing three-dimensional microstructures from High-Energy Diffraction Microscopy (HEDM) data. Developed at the Advanced Photon Source at Argonne National Laboratory, it supports the complete data-reduction pipeline — from raw detector frames to grain maps, strain tensors, spatially resolved orientation fields, and tomographic reconstructions.

Version: 11.0 Contact:Hemant Sharma (hsharma@anl.gov)


Key Capabilities

TechniqueWhat It ProducesDetector Distance
Far-Field HEDM (FF-HEDM)Grain centroids, average orientations, full elastic strain tensors≈ 1 m
Near-Field HEDM (NF-HEDM)Spatially resolved 3D orientation maps, grain morphology, grain boundary networks≈ 5–10 mm
Point-Focus HEDM (PF-HEDM)High-resolution grain orientations from focused beam≈ 1 m
Radial Integration (Caking)1D intensity vs. 2θ profiles for Rietveld refinement (GSAS-II)
Grain Matching & StitchingTrack grains across load states; combine multi-layer scans
Tomography (CT)Absorption-contrast cross-sections via gridrec algorithm

Version 11 Highlights

  • GPU acceleration — CUDA-accelerated indexing (IndexerGPU), strain fitting (FitPosOrStrainsGPU), NF orientation fitting (FitOrientationGPU), scanning HEDM (IndexerScanningGPU, FitOrStrainsScanningGPU), radial integration (IntegratorFitPeaksGPUStream), and tomographic reconstruction (tomo_gpu). See GPU_Acceleration
  • Consolidated binary I/O — PF/scanning HEDM replaces ~30K+ per-voxel files with 3 consolidated binary files per scan via IndexerConsolidatedIO.h
  • CalibrantIntegratorOMP — new primary calibration executable (replaces archived CalibrantPanelShiftsOMP)
  • Switchable peak fitting — unified pseudo-Voigt (pV) and Thompson-Cox-Hastings (TCH) modes across calibration, integration, and auto-calibration
  • Physical corrections — parallax, solid-angle, and polarization corrections in DetectorMapper (matching pyFAI convention)
  • Q-spacing integration — radial bins equally spaced in Q (Å⁻¹) via QBinSize/QMin/QMax parameters
  • CBF file format — new ReadCBFFrame() reader for CBF detector data
  • Streaming median — histogram-based streaming median for NF image processing (~500 MB vs 11.5 GB)
  • Stripe artifact removal — Vo et al. (2018) algorithms for tomography ring/stripe correction
  • Shared integration library — extracted IntegrationCore, MapperCore, CalibrationCore, CalibPeakFit modules
  • Centralized MIDAS_ParamParser — unified parameter file parsing across all executables
  • Gradient-aware pixel splitting — sub-pixel radial resampling for improved integration accuracy

Recent GUI Update (May 2026)

  • FF viewer caking overlay workflow — added load/save/edit support for cake_parameters*.csv, per-detector caking metadata, and composite-sector overlay drawing.
  • Plot/Clear + keyboard toggle — caking overlay can now be toggled directly from the GUI and with the C shortcut.
  • Multi-detector caking controls — HYDRA mode now includes per-GE cake rows and a dedicated cake parameter editor panel.
  • Path precedence hardening — explicit user selections (first file, dark file, HDF5 data/dark dataset paths) are preserved and no longer overwritten by later parameter-file loads.
  • Dark subtraction fallback — when no separate dark file is configured, dark data can be read from the current HDF5 data file path.
  • Overlay readability improvements — lab-frame axes were restyled for clearer on-image visibility.

Version 10 Highlights

  • Consolidated HDF5 output — all FF-HEDM results (grains, spots, strains, peak provenance) in a single .h5 file
  • Pipeline restart--resume and --restart-from flags on all workflows (FF, PF, NF, dual-dataset, multi-resolution) allow resuming from any completed stage using the HDF5 checkpoint
  • Version & provenance tracking — every C binary and Python workflow embeds MIDAS v11.0 (<git-hash>) into output files, HDF5 attributes, and Zarr metadata for full reproducibility
  • Pseudo-Voigt peak fitting — two-stage decomposed fitting (Lorentzian + Gaussian) with mu-weighted effective widths
  • Grain matching & stitching — Python-native optimal (Hungarian) matching across load states with affine deformation support
  • Reprocess mode — regenerate MergeMap.csv and consolidated HDF5 on old datasets (-reprocess 1)
  • Dynamic detector sizes — auto-detected from data, no hardcoded dimensions
  • Zarr-ZIP data format — compressed, portable, self-contained analysis archives
  • Forward simulation engine — compressed output with OpenMP parallelism
  • Multi-resolution NF-HEDM — iterative reconstruction at increasing grid resolution
  • Interactive GUI — browser-based visualization of NF calibration, microstructure, and FF results
  • Multi-stage auto-calibration — geometry-first calibration strategy with panel auto-detection from masks

Repository Layout

MIDAS/
├── FF_HEDM/ # Far-field HEDM (calibration, indexing, fitting, integration)
│ ├── src/ # C source code (peak search, fitting, merging, indexing, grains)
│ ├── workflows/ # Python workflow drivers (ff_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ └── Example/ # Example dataset for testing
├── NF_HEDM/ # Near-field HEDM reconstruction
│ ├── src/ # C source code (forward model, grid reconstruction)
│ ├── workflows/ # Python workflow drivers (nf_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ ├── v7/ # Workflow templates
│ ├── seedOrientations/ # Orientation seed files (downloaded by build)
│ └── Example/ # Example dataset for testing
├── DT/ # Diffraction tomography (peak-fit integrator)
├── TOMO/ # Tomographic reconstruction (gridrec CT engine)
├── utils/ # Python utilities
│ ├── AutoCalibrateZarr.py # FF-HEDM auto-calibration
│ ├── match_grains.py # Grain matching and layer stitching
│ ├── calcMiso.py # Crystallographic misorientation calculations
│ ├── gsas_ii_refine.py # GSAS-II integration
│ └── ...
├── gui/ # Interactive visualization GUI
├── manuals/ # Comprehensive documentation (see below)
├── cmake/ # CMake build configuration and dependency management
├── build.sh # Build script (Linux / macOS)
├── build_wsl_windows.sh # Build script (Windows via WSL)
├── environment.yml # Conda environment specification
├── CMakeLists.txt # Top-level CMake configuration
└── LICENSE # UChicago Argonne open-source license

Documentation

Full manuals are in the manuals/ directory. Start with the manuals README for an overview of all HEDM techniques, coordinate systems, and a getting-started checklist.

ManualTopic
GPU_AccelerationGPU-accelerated computation (CUDA)
FF_CalibrationFF-HEDM geometry calibration
FF_AnalysisFF-HEDM grain indexing and fitting
FF_Match_Stack_ReconstructionsGrain matching across load states and layer stitching
FF_Radial_IntegrationRadial integration / caking
FF_Interactive_PlottingInteractive FF-HEDM visualization
FF_VisualizationFF-HEDM result visualization
FF_Dual_DatasetsDual-dataset FF-HEDM analysis
PF_AnalysisPoint-Focus HEDM analysis
NF_CalibrationNF-HEDM detector calibration
NF_AnalysisNF-HEDM reconstruction workflow
NF_MultiResolution_AnalysisMulti-resolution NF-HEDM
NF_GUINF-HEDM interactive GUI
Forward_SimulationForward simulation for validation
GSAS-II_IntegrationImporting MIDAS output into GSAS-II
Tomography_ReconstructionAbsorption-contrast CT reconstruction
FF_BenchmarkFF-HEDM benchmark testing
NF_BenchmarkNF-HEDM benchmark testing

Installation

Python packages via pip (no source build)

The Python pipeline — calibration, integration, indexing, refinement, grain processing — installs from PyPI and does not need the source build below:

pip install "midas-suite[all]"

midas-index and midas-fit-grain bundle C/OpenMP executables (midas_indexer, midas_fitgrain) and are published as sdist, so pip compiles them during install. CMake and ninja come along automatically; you need a C compiler and OpenMP (macOS: brew install libomp gcc; Linux: gcc; Windows: Visual Studio Build Tools). If either is missing the install still succeeds and silently leaves you on the much slower Python-only path — so check:

importmidas_index.backend_casb; print(b.available()) # True = c-omp indexer presentimportmidas_fit_grain.backend_casf; print(f.available()) # True = c-omp refiner present

See packages/midas_suite/README.md for the full breakdown of what pip does and does not give you.

Prerequisites

PlatformRequirements
macOSHomebrew, LLVM, libomp, GCC, CMake, jemalloc
LinuxGCC ≥ 9, CMake ≥ 3.16
WindowsWSL with Ubuntu

MIDAS automatically downloads and builds these C/C++ dependencies during compilation: NLOPT, LIBTIFF, FFTW, HDF5, BLOSC, BLOSC-2, ZLIB, LIBZIP.

Clone

git clone https://github.com/marinerhemant/MIDAS.git
cd MIDAS

macOS

  1. Install Homebrew (if not already installed):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Without sudo access, install to your home directory:

    mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/main | tar xz --strip-components 1 -C homebrew
    eval"$(homebrew/bin/brew shellenv)"
    brew update --force --quiet
    chmod -R go-w "$(brew --prefix)/share/zsh"

    Add Homebrew to your PATH:

    echo'eval $(/opt/homebrew/bin/brew shellenv)'>>~/.zshrc
    source~/.zshrc
  2. Install dependencies:

    brew install llvm libomp gcc cmake jemalloc
  3. Configure environment variables:

    echo'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include $CPPFLAGS"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/libomp/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/libomp/include $CPPFLAGS"'>>~/.zshrc
    echo'CC=/opt/homebrew/opt/gcc/bin/gcc-15'>>~/.zshrc
    echo'export CC'>>~/.zshrc
    echo'CXX=/opt/homebrew/opt/gcc/bin/g++-15'>>~/.zshrc
    echo'export CXX'>>~/.zshrc
    source~/.zshrc
  4. Build:

    ./build.sh

Linux

./build.sh

Windows (WSL)

sudo ./build_wsl_windows.sh

Build Options

# Disable CUDA support
./build.sh --cuda OFF
# Specify a custom nvcc compiler path
./build.sh --nvcc /usr/local/cuda-12/bin/nvcc
# Or pass it directly to cmakecd build && cmake .. -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc && cmake --build . -j
# Specify target CUDA architectures (default is "86;90")cd build && cmake .. -DCMAKE_CUDA_ARCHITECTURES="75;80"&& cmake --build . -j
# Build and run benchmarks
./build.sh --test all
# Build a single targetcd build
cmake --build . --target IntegratorFitPeaksGPUStream

Updating After git pull

Each time you pull the latest changes, rebuild the C binaries:

cd MIDAS/build
cmake --build .

Python Environment

conda env create -f environment.yml
conda activate midas_env

Or install the required packages manually:

pip install numpy scipy h5py parsl

Quick Start

  1. Calibrate the detector geometry → FF_Calibration
  2. Run FF-HEDM grain indexing and fitting → FF_Analysis
  3. Visualize results interactively → FF_Interactive_Plotting
  4. Match/stitch grains across load states or layers → FF_Match_Stack_Reconstructions
  5. Reconstruct NF-HEDM orientation maps → NF_Analysis
  6. Validate with forward simulation → Forward_Simulation

See the manuals README for the full step-by-step checklist.

Example: Run FF-HEDM on the included test dataset

conda activate midas_env
cd FF_HEDM/Example
python ../workflows/ff_MIDAS.py -paramFN ps_ff.txt

Example: Run FF-HEDM with GPU acceleration

python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -useGPU 1

Example: Resume a failed pipeline from its last checkpoint

# Auto-detect last completed stage and resume:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -resume /path/to/consolidated.h5
# Or restart from a specific stage:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -restartFrom refinement

Example: Reprocess old results (generate MergeMap.csv + consolidated HDF5)

python FF_HEDM/workflows/ff_MIDAS.py -reprocess 1 -resultFolder /path/to/results/

Example: Match grains across load states

python utils/match_grains.py match \
--state1 unloaded/Grains.csv \
--state2 loaded/Grains.csv \
--space-group 225 --mode combined --weights 2.0 50.0

Benchmark Testing

MIDAS includes automated benchmark tests that validate every pipeline using synthetic data and built-in reference comparisons. Each test also runs pre-flight checks (binary existence, staleness, package availability) and prints an environment fingerprint to make failures easy to diagnose.

Quick Start

# Build and run all benchmarks
./build.sh --test all
# Or run benchmarks individually:
./build.sh --test ff # FF-HEDM only
./build.sh --test nf # NF-HEDM only

Running Benchmarks Separately

conda activate midas_env
# FF-HEDM: Forward simulation → indexing → grain recovery (6-stage HDF5 comparison)
python tests/test_ff_hedm.py -nCPUs 4
# NF-HEDM: Forward simulation → reconstruction → orientation comparison (>80% < 0.25°)
python tests/test_nf_hedm.py -nCPUs 8
# Calibration + Integration: CeO2 ring fitting + peak strain residual
python tests/test_calibration_integration.py -nCPUs 4
# Phase ID: CeO2 detected, Au absent, lattice constant within 500 ppm
python tests/test_phase_id.py -nCPUs 4
# Tomography: Shepp-Logan phantom → FBP reconstruction → Pearson correlation > 0.85
python tests/test_tomo.py -nCPUs 4

If a Test Fails

All tests support built-in diagnostic flags for troubleshooting:

# Generate a JSON diagnostic report with full environment and comparison details
python tests/test_ff_hedm.py -nCPUs 4 --diagnose
# Save the generated output file alongside the reference for manual comparison
python tests/test_ff_hedm.py -nCPUs 4 --save-on-fail

Send the generated diagnostic report to hsharma@anl.gov for assistance.

See tests/README.md for detailed documentation on what each test computes, how results are compared, and exact pass/fail criteria.


Citing MIDAS

If you use MIDAS in your research, please cite:

In review, citations coming soon.

FF-HEDM methodology:

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. I. Overlapping diffraction peaks and parameters of the experimental setup," J. Appl. Cryst.45, 693–704 (2012). DOI: 10.1107/S0021889812025563

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. II. Volume, centre-of-mass position, crystallographic orientation and strain state of grains," J. Appl. Cryst.45, 705–718 (2012). DOI: 10.1107/S0021889812025599


Acknowledgments

  • SGInfo library for HKL calculations
  • ODFPF package (Cornell) for misorientation functions

License

MIDAS is released under the UChicago Argonne open-source license.

Copyright © 2012, UChicago Argonne, LLC. All rights reserved.

This product includes software produced by UChicago Argonne, LLC under Contract No. DE-AC02-06CH11357 with the Department of Energy.

About

No description, website, or topics provided.

Resources

Contributing

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

MIDAS Logo

MIDAS — Microstructural Imaging using Diffraction Analysis Software

License

MIDAS is an open-source suite for reconstructing three-dimensional microstructures from High-Energy Diffraction Microscopy (HEDM) data. Developed at the Advanced Photon Source at Argonne National Laboratory, it supports the complete data-reduction pipeline — from raw detector frames to grain maps, strain tensors, spatially resolved orientation fields, and tomographic reconstructions.

Version: 11.0 Contact:Hemant Sharma (hsharma@anl.gov)


Key Capabilities

TechniqueWhat It ProducesDetector Distance
Far-Field HEDM (FF-HEDM)Grain centroids, average orientations, full elastic strain tensors≈ 1 m
Near-Field HEDM (NF-HEDM)Spatially resolved 3D orientation maps, grain morphology, grain boundary networks≈ 5–10 mm
Point-Focus HEDM (PF-HEDM)High-resolution grain orientations from focused beam≈ 1 m
Radial Integration (Caking)1D intensity vs. 2θ profiles for Rietveld refinement (GSAS-II)
Grain Matching & StitchingTrack grains across load states; combine multi-layer scans
Tomography (CT)Absorption-contrast cross-sections via gridrec algorithm

Version 11 Highlights

  • GPU acceleration — CUDA-accelerated indexing (IndexerGPU), strain fitting (FitPosOrStrainsGPU), NF orientation fitting (FitOrientationGPU), scanning HEDM (IndexerScanningGPU, FitOrStrainsScanningGPU), radial integration (IntegratorFitPeaksGPUStream), and tomographic reconstruction (tomo_gpu). See GPU_Acceleration
  • Consolidated binary I/O — PF/scanning HEDM replaces ~30K+ per-voxel files with 3 consolidated binary files per scan via IndexerConsolidatedIO.h
  • CalibrantIntegratorOMP — new primary calibration executable (replaces archived CalibrantPanelShiftsOMP)
  • Switchable peak fitting — unified pseudo-Voigt (pV) and Thompson-Cox-Hastings (TCH) modes across calibration, integration, and auto-calibration
  • Physical corrections — parallax, solid-angle, and polarization corrections in DetectorMapper (matching pyFAI convention)
  • Q-spacing integration — radial bins equally spaced in Q (Å⁻¹) via QBinSize/QMin/QMax parameters
  • CBF file format — new ReadCBFFrame() reader for CBF detector data
  • Streaming median — histogram-based streaming median for NF image processing (~500 MB vs 11.5 GB)
  • Stripe artifact removal — Vo et al. (2018) algorithms for tomography ring/stripe correction
  • Shared integration library — extracted IntegrationCore, MapperCore, CalibrationCore, CalibPeakFit modules
  • Centralized MIDAS_ParamParser — unified parameter file parsing across all executables
  • Gradient-aware pixel splitting — sub-pixel radial resampling for improved integration accuracy

Recent GUI Update (May 2026)

  • FF viewer caking overlay workflow — added load/save/edit support for cake_parameters*.csv, per-detector caking metadata, and composite-sector overlay drawing.
  • Plot/Clear + keyboard toggle — caking overlay can now be toggled directly from the GUI and with the C shortcut.
  • Multi-detector caking controls — HYDRA mode now includes per-GE cake rows and a dedicated cake parameter editor panel.
  • Path precedence hardening — explicit user selections (first file, dark file, HDF5 data/dark dataset paths) are preserved and no longer overwritten by later parameter-file loads.
  • Dark subtraction fallback — when no separate dark file is configured, dark data can be read from the current HDF5 data file path.
  • Overlay readability improvements — lab-frame axes were restyled for clearer on-image visibility.

Version 10 Highlights

  • Consolidated HDF5 output — all FF-HEDM results (grains, spots, strains, peak provenance) in a single .h5 file
  • Pipeline restart--resume and --restart-from flags on all workflows (FF, PF, NF, dual-dataset, multi-resolution) allow resuming from any completed stage using the HDF5 checkpoint
  • Version & provenance tracking — every C binary and Python workflow embeds MIDAS v11.0 (<git-hash>) into output files, HDF5 attributes, and Zarr metadata for full reproducibility
  • Pseudo-Voigt peak fitting — two-stage decomposed fitting (Lorentzian + Gaussian) with mu-weighted effective widths
  • Grain matching & stitching — Python-native optimal (Hungarian) matching across load states with affine deformation support
  • Reprocess mode — regenerate MergeMap.csv and consolidated HDF5 on old datasets (-reprocess 1)
  • Dynamic detector sizes — auto-detected from data, no hardcoded dimensions
  • Zarr-ZIP data format — compressed, portable, self-contained analysis archives
  • Forward simulation engine — compressed output with OpenMP parallelism
  • Multi-resolution NF-HEDM — iterative reconstruction at increasing grid resolution
  • Interactive GUI — browser-based visualization of NF calibration, microstructure, and FF results
  • Multi-stage auto-calibration — geometry-first calibration strategy with panel auto-detection from masks

Repository Layout

MIDAS/
├── FF_HEDM/ # Far-field HEDM (calibration, indexing, fitting, integration)
│ ├── src/ # C source code (peak search, fitting, merging, indexing, grains)
│ ├── workflows/ # Python workflow drivers (ff_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ └── Example/ # Example dataset for testing
├── NF_HEDM/ # Near-field HEDM reconstruction
│ ├── src/ # C source code (forward model, grid reconstruction)
│ ├── workflows/ # Python workflow drivers (nf_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ ├── v7/ # Workflow templates
│ ├── seedOrientations/ # Orientation seed files (downloaded by build)
│ └── Example/ # Example dataset for testing
├── DT/ # Diffraction tomography (peak-fit integrator)
├── TOMO/ # Tomographic reconstruction (gridrec CT engine)
├── utils/ # Python utilities
│ ├── AutoCalibrateZarr.py # FF-HEDM auto-calibration
│ ├── match_grains.py # Grain matching and layer stitching
│ ├── calcMiso.py # Crystallographic misorientation calculations
│ ├── gsas_ii_refine.py # GSAS-II integration
│ └── ...
├── gui/ # Interactive visualization GUI
├── manuals/ # Comprehensive documentation (see below)
├── cmake/ # CMake build configuration and dependency management
├── build.sh # Build script (Linux / macOS)
├── build_wsl_windows.sh # Build script (Windows via WSL)
├── environment.yml # Conda environment specification
├── CMakeLists.txt # Top-level CMake configuration
└── LICENSE # UChicago Argonne open-source license

Documentation

Full manuals are in the manuals/ directory. Start with the manuals README for an overview of all HEDM techniques, coordinate systems, and a getting-started checklist.

ManualTopic
GPU_AccelerationGPU-accelerated computation (CUDA)
FF_CalibrationFF-HEDM geometry calibration
FF_AnalysisFF-HEDM grain indexing and fitting
FF_Match_Stack_ReconstructionsGrain matching across load states and layer stitching
FF_Radial_IntegrationRadial integration / caking
FF_Interactive_PlottingInteractive FF-HEDM visualization
FF_VisualizationFF-HEDM result visualization
FF_Dual_DatasetsDual-dataset FF-HEDM analysis
PF_AnalysisPoint-Focus HEDM analysis
NF_CalibrationNF-HEDM detector calibration
NF_AnalysisNF-HEDM reconstruction workflow
NF_MultiResolution_AnalysisMulti-resolution NF-HEDM
NF_GUINF-HEDM interactive GUI
Forward_SimulationForward simulation for validation
GSAS-II_IntegrationImporting MIDAS output into GSAS-II
Tomography_ReconstructionAbsorption-contrast CT reconstruction
FF_BenchmarkFF-HEDM benchmark testing
NF_BenchmarkNF-HEDM benchmark testing

Installation

Python packages via pip (no source build)

The Python pipeline — calibration, integration, indexing, refinement, grain processing — installs from PyPI and does not need the source build below:

pip install "midas-suite[all]"

midas-index and midas-fit-grain bundle C/OpenMP executables (midas_indexer, midas_fitgrain) and are published as sdist, so pip compiles them during install. CMake and ninja come along automatically; you need a C compiler and OpenMP (macOS: brew install libomp gcc; Linux: gcc; Windows: Visual Studio Build Tools). If either is missing the install still succeeds and silently leaves you on the much slower Python-only path — so check:

importmidas_index.backend_casb; print(b.available()) # True = c-omp indexer presentimportmidas_fit_grain.backend_casf; print(f.available()) # True = c-omp refiner present

See packages/midas_suite/README.md for the full breakdown of what pip does and does not give you.

Prerequisites

PlatformRequirements
macOSHomebrew, LLVM, libomp, GCC, CMake, jemalloc
LinuxGCC ≥ 9, CMake ≥ 3.16
WindowsWSL with Ubuntu

MIDAS automatically downloads and builds these C/C++ dependencies during compilation: NLOPT, LIBTIFF, FFTW, HDF5, BLOSC, BLOSC-2, ZLIB, LIBZIP.

Clone

git clone https://github.com/marinerhemant/MIDAS.git
cd MIDAS

macOS

  1. Install Homebrew (if not already installed):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Without sudo access, install to your home directory:

    mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/main | tar xz --strip-components 1 -C homebrew
    eval"$(homebrew/bin/brew shellenv)"
    brew update --force --quiet
    chmod -R go-w "$(brew --prefix)/share/zsh"

    Add Homebrew to your PATH:

    echo'eval $(/opt/homebrew/bin/brew shellenv)'>>~/.zshrc
    source~/.zshrc
  2. Install dependencies:

    brew install llvm libomp gcc cmake jemalloc
  3. Configure environment variables:

    echo'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include $CPPFLAGS"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/libomp/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/libomp/include $CPPFLAGS"'>>~/.zshrc
    echo'CC=/opt/homebrew/opt/gcc/bin/gcc-15'>>~/.zshrc
    echo'export CC'>>~/.zshrc
    echo'CXX=/opt/homebrew/opt/gcc/bin/g++-15'>>~/.zshrc
    echo'export CXX'>>~/.zshrc
    source~/.zshrc
  4. Build:

    ./build.sh

Linux

./build.sh

Windows (WSL)

sudo ./build_wsl_windows.sh

Build Options

# Disable CUDA support
./build.sh --cuda OFF
# Specify a custom nvcc compiler path
./build.sh --nvcc /usr/local/cuda-12/bin/nvcc
# Or pass it directly to cmakecd build && cmake .. -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc && cmake --build . -j
# Specify target CUDA architectures (default is "86;90")cd build && cmake .. -DCMAKE_CUDA_ARCHITECTURES="75;80"&& cmake --build . -j
# Build and run benchmarks
./build.sh --test all
# Build a single targetcd build
cmake --build . --target IntegratorFitPeaksGPUStream

Updating After git pull

Each time you pull the latest changes, rebuild the C binaries:

cd MIDAS/build
cmake --build .

Python Environment

conda env create -f environment.yml
conda activate midas_env

Or install the required packages manually:

pip install numpy scipy h5py parsl

Quick Start

  1. Calibrate the detector geometry → FF_Calibration
  2. Run FF-HEDM grain indexing and fitting → FF_Analysis
  3. Visualize results interactively → FF_Interactive_Plotting
  4. Match/stitch grains across load states or layers → FF_Match_Stack_Reconstructions
  5. Reconstruct NF-HEDM orientation maps → NF_Analysis
  6. Validate with forward simulation → Forward_Simulation

See the manuals README for the full step-by-step checklist.

Example: Run FF-HEDM on the included test dataset

conda activate midas_env
cd FF_HEDM/Example
python ../workflows/ff_MIDAS.py -paramFN ps_ff.txt

Example: Run FF-HEDM with GPU acceleration

python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -useGPU 1

Example: Resume a failed pipeline from its last checkpoint

# Auto-detect last completed stage and resume:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -resume /path/to/consolidated.h5
# Or restart from a specific stage:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -restartFrom refinement

Example: Reprocess old results (generate MergeMap.csv + consolidated HDF5)

python FF_HEDM/workflows/ff_MIDAS.py -reprocess 1 -resultFolder /path/to/results/

Example: Match grains across load states

python utils/match_grains.py match \
--state1 unloaded/Grains.csv \
--state2 loaded/Grains.csv \
--space-group 225 --mode combined --weights 2.0 50.0

Benchmark Testing

MIDAS includes automated benchmark tests that validate every pipeline using synthetic data and built-in reference comparisons. Each test also runs pre-flight checks (binary existence, staleness, package availability) and prints an environment fingerprint to make failures easy to diagnose.

Quick Start

# Build and run all benchmarks
./build.sh --test all
# Or run benchmarks individually:
./build.sh --test ff # FF-HEDM only
./build.sh --test nf # NF-HEDM only

Running Benchmarks Separately

conda activate midas_env
# FF-HEDM: Forward simulation → indexing → grain recovery (6-stage HDF5 comparison)
python tests/test_ff_hedm.py -nCPUs 4
# NF-HEDM: Forward simulation → reconstruction → orientation comparison (>80% < 0.25°)
python tests/test_nf_hedm.py -nCPUs 8
# Calibration + Integration: CeO2 ring fitting + peak strain residual
python tests/test_calibration_integration.py -nCPUs 4
# Phase ID: CeO2 detected, Au absent, lattice constant within 500 ppm
python tests/test_phase_id.py -nCPUs 4
# Tomography: Shepp-Logan phantom → FBP reconstruction → Pearson correlation > 0.85
python tests/test_tomo.py -nCPUs 4

If a Test Fails

All tests support built-in diagnostic flags for troubleshooting:

# Generate a JSON diagnostic report with full environment and comparison details
python tests/test_ff_hedm.py -nCPUs 4 --diagnose
# Save the generated output file alongside the reference for manual comparison
python tests/test_ff_hedm.py -nCPUs 4 --save-on-fail

Send the generated diagnostic report to hsharma@anl.gov for assistance.

See tests/README.md for detailed documentation on what each test computes, how results are compared, and exact pass/fail criteria.


Citing MIDAS

If you use MIDAS in your research, please cite:

In review, citations coming soon.

FF-HEDM methodology:

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. I. Overlapping diffraction peaks and parameters of the experimental setup," J. Appl. Cryst.45, 693–704 (2012). DOI: 10.1107/S0021889812025563

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. II. Volume, centre-of-mass position, crystallographic orientation and strain state of grains," J. Appl. Cryst.45, 705–718 (2012). DOI: 10.1107/S0021889812025599


Acknowledgments

  • SGInfo library for HKL calculations
  • ODFPF package (Cornell) for misorientation functions

License

MIDAS is released under the UChicago Argonne open-source license.

Copyright © 2012, UChicago Argonne, LLC. All rights reserved.

This product includes software produced by UChicago Argonne, LLC under Contract No. DE-AC02-06CH11357 with the Department of Energy.

About

No description, website, or topics provided.

Resources

Contributing

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

MIDAS Logo

MIDAS — Microstructural Imaging using Diffraction Analysis Software

License

MIDAS is an open-source suite for reconstructing three-dimensional microstructures from High-Energy Diffraction Microscopy (HEDM) data. Developed at the Advanced Photon Source at Argonne National Laboratory, it supports the complete data-reduction pipeline — from raw detector frames to grain maps, strain tensors, spatially resolved orientation fields, and tomographic reconstructions.

Version: 11.0 Contact:Hemant Sharma (hsharma@anl.gov)


Key Capabilities

TechniqueWhat It ProducesDetector Distance
Far-Field HEDM (FF-HEDM)Grain centroids, average orientations, full elastic strain tensors≈ 1 m
Near-Field HEDM (NF-HEDM)Spatially resolved 3D orientation maps, grain morphology, grain boundary networks≈ 5–10 mm
Point-Focus HEDM (PF-HEDM)High-resolution grain orientations from focused beam≈ 1 m
Radial Integration (Caking)1D intensity vs. 2θ profiles for Rietveld refinement (GSAS-II)
Grain Matching & StitchingTrack grains across load states; combine multi-layer scans
Tomography (CT)Absorption-contrast cross-sections via gridrec algorithm

Version 11 Highlights

  • GPU acceleration — CUDA-accelerated indexing (IndexerGPU), strain fitting (FitPosOrStrainsGPU), NF orientation fitting (FitOrientationGPU), scanning HEDM (IndexerScanningGPU, FitOrStrainsScanningGPU), radial integration (IntegratorFitPeaksGPUStream), and tomographic reconstruction (tomo_gpu). See GPU_Acceleration
  • Consolidated binary I/O — PF/scanning HEDM replaces ~30K+ per-voxel files with 3 consolidated binary files per scan via IndexerConsolidatedIO.h
  • CalibrantIntegratorOMP — new primary calibration executable (replaces archived CalibrantPanelShiftsOMP)
  • Switchable peak fitting — unified pseudo-Voigt (pV) and Thompson-Cox-Hastings (TCH) modes across calibration, integration, and auto-calibration
  • Physical corrections — parallax, solid-angle, and polarization corrections in DetectorMapper (matching pyFAI convention)
  • Q-spacing integration — radial bins equally spaced in Q (Å⁻¹) via QBinSize/QMin/QMax parameters
  • CBF file format — new ReadCBFFrame() reader for CBF detector data
  • Streaming median — histogram-based streaming median for NF image processing (~500 MB vs 11.5 GB)
  • Stripe artifact removal — Vo et al. (2018) algorithms for tomography ring/stripe correction
  • Shared integration library — extracted IntegrationCore, MapperCore, CalibrationCore, CalibPeakFit modules
  • Centralized MIDAS_ParamParser — unified parameter file parsing across all executables
  • Gradient-aware pixel splitting — sub-pixel radial resampling for improved integration accuracy

Recent GUI Update (May 2026)

  • FF viewer caking overlay workflow — added load/save/edit support for cake_parameters*.csv, per-detector caking metadata, and composite-sector overlay drawing.
  • Plot/Clear + keyboard toggle — caking overlay can now be toggled directly from the GUI and with the C shortcut.
  • Multi-detector caking controls — HYDRA mode now includes per-GE cake rows and a dedicated cake parameter editor panel.
  • Path precedence hardening — explicit user selections (first file, dark file, HDF5 data/dark dataset paths) are preserved and no longer overwritten by later parameter-file loads.
  • Dark subtraction fallback — when no separate dark file is configured, dark data can be read from the current HDF5 data file path.
  • Overlay readability improvements — lab-frame axes were restyled for clearer on-image visibility.

Version 10 Highlights

  • Consolidated HDF5 output — all FF-HEDM results (grains, spots, strains, peak provenance) in a single .h5 file
  • Pipeline restart--resume and --restart-from flags on all workflows (FF, PF, NF, dual-dataset, multi-resolution) allow resuming from any completed stage using the HDF5 checkpoint
  • Version & provenance tracking — every C binary and Python workflow embeds MIDAS v11.0 (<git-hash>) into output files, HDF5 attributes, and Zarr metadata for full reproducibility
  • Pseudo-Voigt peak fitting — two-stage decomposed fitting (Lorentzian + Gaussian) with mu-weighted effective widths
  • Grain matching & stitching — Python-native optimal (Hungarian) matching across load states with affine deformation support
  • Reprocess mode — regenerate MergeMap.csv and consolidated HDF5 on old datasets (-reprocess 1)
  • Dynamic detector sizes — auto-detected from data, no hardcoded dimensions
  • Zarr-ZIP data format — compressed, portable, self-contained analysis archives
  • Forward simulation engine — compressed output with OpenMP parallelism
  • Multi-resolution NF-HEDM — iterative reconstruction at increasing grid resolution
  • Interactive GUI — browser-based visualization of NF calibration, microstructure, and FF results
  • Multi-stage auto-calibration — geometry-first calibration strategy with panel auto-detection from masks

Repository Layout

MIDAS/
├── FF_HEDM/ # Far-field HEDM (calibration, indexing, fitting, integration)
│ ├── src/ # C source code (peak search, fitting, merging, indexing, grains)
│ ├── workflows/ # Python workflow drivers (ff_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ └── Example/ # Example dataset for testing
├── NF_HEDM/ # Near-field HEDM reconstruction
│ ├── src/ # C source code (forward model, grid reconstruction)
│ ├── workflows/ # Python workflow drivers (nf_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ ├── v7/ # Workflow templates
│ ├── seedOrientations/ # Orientation seed files (downloaded by build)
│ └── Example/ # Example dataset for testing
├── DT/ # Diffraction tomography (peak-fit integrator)
├── TOMO/ # Tomographic reconstruction (gridrec CT engine)
├── utils/ # Python utilities
│ ├── AutoCalibrateZarr.py # FF-HEDM auto-calibration
│ ├── match_grains.py # Grain matching and layer stitching
│ ├── calcMiso.py # Crystallographic misorientation calculations
│ ├── gsas_ii_refine.py # GSAS-II integration
│ └── ...
├── gui/ # Interactive visualization GUI
├── manuals/ # Comprehensive documentation (see below)
├── cmake/ # CMake build configuration and dependency management
├── build.sh # Build script (Linux / macOS)
├── build_wsl_windows.sh # Build script (Windows via WSL)
├── environment.yml # Conda environment specification
├── CMakeLists.txt # Top-level CMake configuration
└── LICENSE # UChicago Argonne open-source license

Documentation

Full manuals are in the manuals/ directory. Start with the manuals README for an overview of all HEDM techniques, coordinate systems, and a getting-started checklist.

ManualTopic
GPU_AccelerationGPU-accelerated computation (CUDA)
FF_CalibrationFF-HEDM geometry calibration
FF_AnalysisFF-HEDM grain indexing and fitting
FF_Match_Stack_ReconstructionsGrain matching across load states and layer stitching
FF_Radial_IntegrationRadial integration / caking
FF_Interactive_PlottingInteractive FF-HEDM visualization
FF_VisualizationFF-HEDM result visualization
FF_Dual_DatasetsDual-dataset FF-HEDM analysis
PF_AnalysisPoint-Focus HEDM analysis
NF_CalibrationNF-HEDM detector calibration
NF_AnalysisNF-HEDM reconstruction workflow
NF_MultiResolution_AnalysisMulti-resolution NF-HEDM
NF_GUINF-HEDM interactive GUI
Forward_SimulationForward simulation for validation
GSAS-II_IntegrationImporting MIDAS output into GSAS-II
Tomography_ReconstructionAbsorption-contrast CT reconstruction
FF_BenchmarkFF-HEDM benchmark testing
NF_BenchmarkNF-HEDM benchmark testing

Installation

Python packages via pip (no source build)

The Python pipeline — calibration, integration, indexing, refinement, grain processing — installs from PyPI and does not need the source build below:

pip install "midas-suite[all]"

midas-index and midas-fit-grain bundle C/OpenMP executables (midas_indexer, midas_fitgrain) and are published as sdist, so pip compiles them during install. CMake and ninja come along automatically; you need a C compiler and OpenMP (macOS: brew install libomp gcc; Linux: gcc; Windows: Visual Studio Build Tools). If either is missing the install still succeeds and silently leaves you on the much slower Python-only path — so check:

importmidas_index.backend_casb; print(b.available()) # True = c-omp indexer presentimportmidas_fit_grain.backend_casf; print(f.available()) # True = c-omp refiner present

See packages/midas_suite/README.md for the full breakdown of what pip does and does not give you.

Prerequisites

PlatformRequirements
macOSHomebrew, LLVM, libomp, GCC, CMake, jemalloc
LinuxGCC ≥ 9, CMake ≥ 3.16
WindowsWSL with Ubuntu

MIDAS automatically downloads and builds these C/C++ dependencies during compilation: NLOPT, LIBTIFF, FFTW, HDF5, BLOSC, BLOSC-2, ZLIB, LIBZIP.

Clone

git clone https://github.com/marinerhemant/MIDAS.git
cd MIDAS

macOS

  1. Install Homebrew (if not already installed):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Without sudo access, install to your home directory:

    mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/main | tar xz --strip-components 1 -C homebrew
    eval"$(homebrew/bin/brew shellenv)"
    brew update --force --quiet
    chmod -R go-w "$(brew --prefix)/share/zsh"

    Add Homebrew to your PATH:

    echo'eval $(/opt/homebrew/bin/brew shellenv)'>>~/.zshrc
    source~/.zshrc
  2. Install dependencies:

    brew install llvm libomp gcc cmake jemalloc
  3. Configure environment variables:

    echo'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include $CPPFLAGS"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/libomp/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/libomp/include $CPPFLAGS"'>>~/.zshrc
    echo'CC=/opt/homebrew/opt/gcc/bin/gcc-15'>>~/.zshrc
    echo'export CC'>>~/.zshrc
    echo'CXX=/opt/homebrew/opt/gcc/bin/g++-15'>>~/.zshrc
    echo'export CXX'>>~/.zshrc
    source~/.zshrc
  4. Build:

    ./build.sh

Linux

./build.sh

Windows (WSL)

sudo ./build_wsl_windows.sh

Build Options

# Disable CUDA support
./build.sh --cuda OFF
# Specify a custom nvcc compiler path
./build.sh --nvcc /usr/local/cuda-12/bin/nvcc
# Or pass it directly to cmakecd build && cmake .. -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc && cmake --build . -j
# Specify target CUDA architectures (default is "86;90")cd build && cmake .. -DCMAKE_CUDA_ARCHITECTURES="75;80"&& cmake --build . -j
# Build and run benchmarks
./build.sh --test all
# Build a single targetcd build
cmake --build . --target IntegratorFitPeaksGPUStream

Updating After git pull

Each time you pull the latest changes, rebuild the C binaries:

cd MIDAS/build
cmake --build .

Python Environment

conda env create -f environment.yml
conda activate midas_env

Or install the required packages manually:

pip install numpy scipy h5py parsl

Quick Start

  1. Calibrate the detector geometry → FF_Calibration
  2. Run FF-HEDM grain indexing and fitting → FF_Analysis
  3. Visualize results interactively → FF_Interactive_Plotting
  4. Match/stitch grains across load states or layers → FF_Match_Stack_Reconstructions
  5. Reconstruct NF-HEDM orientation maps → NF_Analysis
  6. Validate with forward simulation → Forward_Simulation

See the manuals README for the full step-by-step checklist.

Example: Run FF-HEDM on the included test dataset

conda activate midas_env
cd FF_HEDM/Example
python ../workflows/ff_MIDAS.py -paramFN ps_ff.txt

Example: Run FF-HEDM with GPU acceleration

python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -useGPU 1

Example: Resume a failed pipeline from its last checkpoint

# Auto-detect last completed stage and resume:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -resume /path/to/consolidated.h5
# Or restart from a specific stage:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -restartFrom refinement

Example: Reprocess old results (generate MergeMap.csv + consolidated HDF5)

python FF_HEDM/workflows/ff_MIDAS.py -reprocess 1 -resultFolder /path/to/results/

Example: Match grains across load states

python utils/match_grains.py match \
--state1 unloaded/Grains.csv \
--state2 loaded/Grains.csv \
--space-group 225 --mode combined --weights 2.0 50.0

Benchmark Testing

MIDAS includes automated benchmark tests that validate every pipeline using synthetic data and built-in reference comparisons. Each test also runs pre-flight checks (binary existence, staleness, package availability) and prints an environment fingerprint to make failures easy to diagnose.

Quick Start

# Build and run all benchmarks
./build.sh --test all
# Or run benchmarks individually:
./build.sh --test ff # FF-HEDM only
./build.sh --test nf # NF-HEDM only

Running Benchmarks Separately

conda activate midas_env
# FF-HEDM: Forward simulation → indexing → grain recovery (6-stage HDF5 comparison)
python tests/test_ff_hedm.py -nCPUs 4
# NF-HEDM: Forward simulation → reconstruction → orientation comparison (>80% < 0.25°)
python tests/test_nf_hedm.py -nCPUs 8
# Calibration + Integration: CeO2 ring fitting + peak strain residual
python tests/test_calibration_integration.py -nCPUs 4
# Phase ID: CeO2 detected, Au absent, lattice constant within 500 ppm
python tests/test_phase_id.py -nCPUs 4
# Tomography: Shepp-Logan phantom → FBP reconstruction → Pearson correlation > 0.85
python tests/test_tomo.py -nCPUs 4

If a Test Fails

All tests support built-in diagnostic flags for troubleshooting:

# Generate a JSON diagnostic report with full environment and comparison details
python tests/test_ff_hedm.py -nCPUs 4 --diagnose
# Save the generated output file alongside the reference for manual comparison
python tests/test_ff_hedm.py -nCPUs 4 --save-on-fail

Send the generated diagnostic report to hsharma@anl.gov for assistance.

See tests/README.md for detailed documentation on what each test computes, how results are compared, and exact pass/fail criteria.


Citing MIDAS

If you use MIDAS in your research, please cite:

In review, citations coming soon.

FF-HEDM methodology:

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. I. Overlapping diffraction peaks and parameters of the experimental setup," J. Appl. Cryst.45, 693–704 (2012). DOI: 10.1107/S0021889812025563

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. II. Volume, centre-of-mass position, crystallographic orientation and strain state of grains," J. Appl. Cryst.45, 705–718 (2012). DOI: 10.1107/S0021889812025599


Acknowledgments

  • SGInfo library for HKL calculations
  • ODFPF package (Cornell) for misorientation functions

License

MIDAS is released under the UChicago Argonne open-source license.

Copyright © 2012, UChicago Argonne, LLC. All rights reserved.

This product includes software produced by UChicago Argonne, LLC under Contract No. DE-AC02-06CH11357 with the Department of Energy.

About

No description, website, or topics provided.

Resources

Contributing

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

MIDAS Logo

MIDAS — Microstructural Imaging using Diffraction Analysis Software

License

MIDAS is an open-source suite for reconstructing three-dimensional microstructures from High-Energy Diffraction Microscopy (HEDM) data. Developed at the Advanced Photon Source at Argonne National Laboratory, it supports the complete data-reduction pipeline — from raw detector frames to grain maps, strain tensors, spatially resolved orientation fields, and tomographic reconstructions.

Version: 11.0 Contact:Hemant Sharma (hsharma@anl.gov)


Key Capabilities

TechniqueWhat It ProducesDetector Distance
Far-Field HEDM (FF-HEDM)Grain centroids, average orientations, full elastic strain tensors≈ 1 m
Near-Field HEDM (NF-HEDM)Spatially resolved 3D orientation maps, grain morphology, grain boundary networks≈ 5–10 mm
Point-Focus HEDM (PF-HEDM)High-resolution grain orientations from focused beam≈ 1 m
Radial Integration (Caking)1D intensity vs. 2θ profiles for Rietveld refinement (GSAS-II)
Grain Matching & StitchingTrack grains across load states; combine multi-layer scans
Tomography (CT)Absorption-contrast cross-sections via gridrec algorithm

Version 11 Highlights

  • GPU acceleration — CUDA-accelerated indexing (IndexerGPU), strain fitting (FitPosOrStrainsGPU), NF orientation fitting (FitOrientationGPU), scanning HEDM (IndexerScanningGPU, FitOrStrainsScanningGPU), radial integration (IntegratorFitPeaksGPUStream), and tomographic reconstruction (tomo_gpu). See GPU_Acceleration
  • Consolidated binary I/O — PF/scanning HEDM replaces ~30K+ per-voxel files with 3 consolidated binary files per scan via IndexerConsolidatedIO.h
  • CalibrantIntegratorOMP — new primary calibration executable (replaces archived CalibrantPanelShiftsOMP)
  • Switchable peak fitting — unified pseudo-Voigt (pV) and Thompson-Cox-Hastings (TCH) modes across calibration, integration, and auto-calibration
  • Physical corrections — parallax, solid-angle, and polarization corrections in DetectorMapper (matching pyFAI convention)
  • Q-spacing integration — radial bins equally spaced in Q (Å⁻¹) via QBinSize/QMin/QMax parameters
  • CBF file format — new ReadCBFFrame() reader for CBF detector data
  • Streaming median — histogram-based streaming median for NF image processing (~500 MB vs 11.5 GB)
  • Stripe artifact removal — Vo et al. (2018) algorithms for tomography ring/stripe correction
  • Shared integration library — extracted IntegrationCore, MapperCore, CalibrationCore, CalibPeakFit modules
  • Centralized MIDAS_ParamParser — unified parameter file parsing across all executables
  • Gradient-aware pixel splitting — sub-pixel radial resampling for improved integration accuracy

Recent GUI Update (May 2026)

  • FF viewer caking overlay workflow — added load/save/edit support for cake_parameters*.csv, per-detector caking metadata, and composite-sector overlay drawing.
  • Plot/Clear + keyboard toggle — caking overlay can now be toggled directly from the GUI and with the C shortcut.
  • Multi-detector caking controls — HYDRA mode now includes per-GE cake rows and a dedicated cake parameter editor panel.
  • Path precedence hardening — explicit user selections (first file, dark file, HDF5 data/dark dataset paths) are preserved and no longer overwritten by later parameter-file loads.
  • Dark subtraction fallback — when no separate dark file is configured, dark data can be read from the current HDF5 data file path.
  • Overlay readability improvements — lab-frame axes were restyled for clearer on-image visibility.

Version 10 Highlights

  • Consolidated HDF5 output — all FF-HEDM results (grains, spots, strains, peak provenance) in a single .h5 file
  • Pipeline restart--resume and --restart-from flags on all workflows (FF, PF, NF, dual-dataset, multi-resolution) allow resuming from any completed stage using the HDF5 checkpoint
  • Version & provenance tracking — every C binary and Python workflow embeds MIDAS v11.0 (<git-hash>) into output files, HDF5 attributes, and Zarr metadata for full reproducibility
  • Pseudo-Voigt peak fitting — two-stage decomposed fitting (Lorentzian + Gaussian) with mu-weighted effective widths
  • Grain matching & stitching — Python-native optimal (Hungarian) matching across load states with affine deformation support
  • Reprocess mode — regenerate MergeMap.csv and consolidated HDF5 on old datasets (-reprocess 1)
  • Dynamic detector sizes — auto-detected from data, no hardcoded dimensions
  • Zarr-ZIP data format — compressed, portable, self-contained analysis archives
  • Forward simulation engine — compressed output with OpenMP parallelism
  • Multi-resolution NF-HEDM — iterative reconstruction at increasing grid resolution
  • Interactive GUI — browser-based visualization of NF calibration, microstructure, and FF results
  • Multi-stage auto-calibration — geometry-first calibration strategy with panel auto-detection from masks

Repository Layout

MIDAS/
├── FF_HEDM/ # Far-field HEDM (calibration, indexing, fitting, integration)
│ ├── src/ # C source code (peak search, fitting, merging, indexing, grains)
│ ├── workflows/ # Python workflow drivers (ff_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ └── Example/ # Example dataset for testing
├── NF_HEDM/ # Near-field HEDM reconstruction
│ ├── src/ # C source code (forward model, grid reconstruction)
│ ├── workflows/ # Python workflow drivers (nf_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ ├── v7/ # Workflow templates
│ ├── seedOrientations/ # Orientation seed files (downloaded by build)
│ └── Example/ # Example dataset for testing
├── DT/ # Diffraction tomography (peak-fit integrator)
├── TOMO/ # Tomographic reconstruction (gridrec CT engine)
├── utils/ # Python utilities
│ ├── AutoCalibrateZarr.py # FF-HEDM auto-calibration
│ ├── match_grains.py # Grain matching and layer stitching
│ ├── calcMiso.py # Crystallographic misorientation calculations
│ ├── gsas_ii_refine.py # GSAS-II integration
│ └── ...
├── gui/ # Interactive visualization GUI
├── manuals/ # Comprehensive documentation (see below)
├── cmake/ # CMake build configuration and dependency management
├── build.sh # Build script (Linux / macOS)
├── build_wsl_windows.sh # Build script (Windows via WSL)
├── environment.yml # Conda environment specification
├── CMakeLists.txt # Top-level CMake configuration
└── LICENSE # UChicago Argonne open-source license

Documentation

Full manuals are in the manuals/ directory. Start with the manuals README for an overview of all HEDM techniques, coordinate systems, and a getting-started checklist.

ManualTopic
GPU_AccelerationGPU-accelerated computation (CUDA)
FF_CalibrationFF-HEDM geometry calibration
FF_AnalysisFF-HEDM grain indexing and fitting
FF_Match_Stack_ReconstructionsGrain matching across load states and layer stitching
FF_Radial_IntegrationRadial integration / caking
FF_Interactive_PlottingInteractive FF-HEDM visualization
FF_VisualizationFF-HEDM result visualization
FF_Dual_DatasetsDual-dataset FF-HEDM analysis
PF_AnalysisPoint-Focus HEDM analysis
NF_CalibrationNF-HEDM detector calibration
NF_AnalysisNF-HEDM reconstruction workflow
NF_MultiResolution_AnalysisMulti-resolution NF-HEDM
NF_GUINF-HEDM interactive GUI
Forward_SimulationForward simulation for validation
GSAS-II_IntegrationImporting MIDAS output into GSAS-II
Tomography_ReconstructionAbsorption-contrast CT reconstruction
FF_BenchmarkFF-HEDM benchmark testing
NF_BenchmarkNF-HEDM benchmark testing

Installation

Python packages via pip (no source build)

The Python pipeline — calibration, integration, indexing, refinement, grain processing — installs from PyPI and does not need the source build below:

pip install "midas-suite[all]"

midas-index and midas-fit-grain bundle C/OpenMP executables (midas_indexer, midas_fitgrain) and are published as sdist, so pip compiles them during install. CMake and ninja come along automatically; you need a C compiler and OpenMP (macOS: brew install libomp gcc; Linux: gcc; Windows: Visual Studio Build Tools). If either is missing the install still succeeds and silently leaves you on the much slower Python-only path — so check:

importmidas_index.backend_casb; print(b.available()) # True = c-omp indexer presentimportmidas_fit_grain.backend_casf; print(f.available()) # True = c-omp refiner present

See packages/midas_suite/README.md for the full breakdown of what pip does and does not give you.

Prerequisites

PlatformRequirements
macOSHomebrew, LLVM, libomp, GCC, CMake, jemalloc
LinuxGCC ≥ 9, CMake ≥ 3.16
WindowsWSL with Ubuntu

MIDAS automatically downloads and builds these C/C++ dependencies during compilation: NLOPT, LIBTIFF, FFTW, HDF5, BLOSC, BLOSC-2, ZLIB, LIBZIP.

Clone

git clone https://github.com/marinerhemant/MIDAS.git
cd MIDAS

macOS

  1. Install Homebrew (if not already installed):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Without sudo access, install to your home directory:

    mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/main | tar xz --strip-components 1 -C homebrew
    eval"$(homebrew/bin/brew shellenv)"
    brew update --force --quiet
    chmod -R go-w "$(brew --prefix)/share/zsh"

    Add Homebrew to your PATH:

    echo'eval $(/opt/homebrew/bin/brew shellenv)'>>~/.zshrc
    source~/.zshrc
  2. Install dependencies:

    brew install llvm libomp gcc cmake jemalloc
  3. Configure environment variables:

    echo'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include $CPPFLAGS"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/libomp/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/libomp/include $CPPFLAGS"'>>~/.zshrc
    echo'CC=/opt/homebrew/opt/gcc/bin/gcc-15'>>~/.zshrc
    echo'export CC'>>~/.zshrc
    echo'CXX=/opt/homebrew/opt/gcc/bin/g++-15'>>~/.zshrc
    echo'export CXX'>>~/.zshrc
    source~/.zshrc
  4. Build:

    ./build.sh

Linux

./build.sh

Windows (WSL)

sudo ./build_wsl_windows.sh

Build Options

# Disable CUDA support
./build.sh --cuda OFF
# Specify a custom nvcc compiler path
./build.sh --nvcc /usr/local/cuda-12/bin/nvcc
# Or pass it directly to cmakecd build && cmake .. -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc && cmake --build . -j
# Specify target CUDA architectures (default is "86;90")cd build && cmake .. -DCMAKE_CUDA_ARCHITECTURES="75;80"&& cmake --build . -j
# Build and run benchmarks
./build.sh --test all
# Build a single targetcd build
cmake --build . --target IntegratorFitPeaksGPUStream

Updating After git pull

Each time you pull the latest changes, rebuild the C binaries:

cd MIDAS/build
cmake --build .

Python Environment

conda env create -f environment.yml
conda activate midas_env

Or install the required packages manually:

pip install numpy scipy h5py parsl

Quick Start

  1. Calibrate the detector geometry → FF_Calibration
  2. Run FF-HEDM grain indexing and fitting → FF_Analysis
  3. Visualize results interactively → FF_Interactive_Plotting
  4. Match/stitch grains across load states or layers → FF_Match_Stack_Reconstructions
  5. Reconstruct NF-HEDM orientation maps → NF_Analysis
  6. Validate with forward simulation → Forward_Simulation

See the manuals README for the full step-by-step checklist.

Example: Run FF-HEDM on the included test dataset

conda activate midas_env
cd FF_HEDM/Example
python ../workflows/ff_MIDAS.py -paramFN ps_ff.txt

Example: Run FF-HEDM with GPU acceleration

python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -useGPU 1

Example: Resume a failed pipeline from its last checkpoint

# Auto-detect last completed stage and resume:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -resume /path/to/consolidated.h5
# Or restart from a specific stage:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -restartFrom refinement

Example: Reprocess old results (generate MergeMap.csv + consolidated HDF5)

python FF_HEDM/workflows/ff_MIDAS.py -reprocess 1 -resultFolder /path/to/results/

Example: Match grains across load states

python utils/match_grains.py match \
--state1 unloaded/Grains.csv \
--state2 loaded/Grains.csv \
--space-group 225 --mode combined --weights 2.0 50.0

Benchmark Testing

MIDAS includes automated benchmark tests that validate every pipeline using synthetic data and built-in reference comparisons. Each test also runs pre-flight checks (binary existence, staleness, package availability) and prints an environment fingerprint to make failures easy to diagnose.

Quick Start

# Build and run all benchmarks
./build.sh --test all
# Or run benchmarks individually:
./build.sh --test ff # FF-HEDM only
./build.sh --test nf # NF-HEDM only

Running Benchmarks Separately

conda activate midas_env
# FF-HEDM: Forward simulation → indexing → grain recovery (6-stage HDF5 comparison)
python tests/test_ff_hedm.py -nCPUs 4
# NF-HEDM: Forward simulation → reconstruction → orientation comparison (>80% < 0.25°)
python tests/test_nf_hedm.py -nCPUs 8
# Calibration + Integration: CeO2 ring fitting + peak strain residual
python tests/test_calibration_integration.py -nCPUs 4
# Phase ID: CeO2 detected, Au absent, lattice constant within 500 ppm
python tests/test_phase_id.py -nCPUs 4
# Tomography: Shepp-Logan phantom → FBP reconstruction → Pearson correlation > 0.85
python tests/test_tomo.py -nCPUs 4

If a Test Fails

All tests support built-in diagnostic flags for troubleshooting:

# Generate a JSON diagnostic report with full environment and comparison details
python tests/test_ff_hedm.py -nCPUs 4 --diagnose
# Save the generated output file alongside the reference for manual comparison
python tests/test_ff_hedm.py -nCPUs 4 --save-on-fail

Send the generated diagnostic report to hsharma@anl.gov for assistance.

See tests/README.md for detailed documentation on what each test computes, how results are compared, and exact pass/fail criteria.


Citing MIDAS

If you use MIDAS in your research, please cite:

In review, citations coming soon.

FF-HEDM methodology:

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. I. Overlapping diffraction peaks and parameters of the experimental setup," J. Appl. Cryst.45, 693–704 (2012). DOI: 10.1107/S0021889812025563

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. II. Volume, centre-of-mass position, crystallographic orientation and strain state of grains," J. Appl. Cryst.45, 705–718 (2012). DOI: 10.1107/S0021889812025599


Acknowledgments

  • SGInfo library for HKL calculations
  • ODFPF package (Cornell) for misorientation functions

License

MIDAS is released under the UChicago Argonne open-source license.

Copyright © 2012, UChicago Argonne, LLC. All rights reserved.

This product includes software produced by UChicago Argonne, LLC under Contract No. DE-AC02-06CH11357 with the Department of Energy.

About

No description, website, or topics provided.

Resources

Contributing

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

MIDAS Logo

MIDAS — Microstructural Imaging using Diffraction Analysis Software

License

MIDAS is an open-source suite for reconstructing three-dimensional microstructures from High-Energy Diffraction Microscopy (HEDM) data. Developed at the Advanced Photon Source at Argonne National Laboratory, it supports the complete data-reduction pipeline — from raw detector frames to grain maps, strain tensors, spatially resolved orientation fields, and tomographic reconstructions.

Version: 11.0 Contact:Hemant Sharma (hsharma@anl.gov)


Key Capabilities

TechniqueWhat It ProducesDetector Distance
Far-Field HEDM (FF-HEDM)Grain centroids, average orientations, full elastic strain tensors≈ 1 m
Near-Field HEDM (NF-HEDM)Spatially resolved 3D orientation maps, grain morphology, grain boundary networks≈ 5–10 mm
Point-Focus HEDM (PF-HEDM)High-resolution grain orientations from focused beam≈ 1 m
Radial Integration (Caking)1D intensity vs. 2θ profiles for Rietveld refinement (GSAS-II)
Grain Matching & StitchingTrack grains across load states; combine multi-layer scans
Tomography (CT)Absorption-contrast cross-sections via gridrec algorithm

Version 11 Highlights

  • GPU acceleration — CUDA-accelerated indexing (IndexerGPU), strain fitting (FitPosOrStrainsGPU), NF orientation fitting (FitOrientationGPU), scanning HEDM (IndexerScanningGPU, FitOrStrainsScanningGPU), radial integration (IntegratorFitPeaksGPUStream), and tomographic reconstruction (tomo_gpu). See GPU_Acceleration
  • Consolidated binary I/O — PF/scanning HEDM replaces ~30K+ per-voxel files with 3 consolidated binary files per scan via IndexerConsolidatedIO.h
  • CalibrantIntegratorOMP — new primary calibration executable (replaces archived CalibrantPanelShiftsOMP)
  • Switchable peak fitting — unified pseudo-Voigt (pV) and Thompson-Cox-Hastings (TCH) modes across calibration, integration, and auto-calibration
  • Physical corrections — parallax, solid-angle, and polarization corrections in DetectorMapper (matching pyFAI convention)
  • Q-spacing integration — radial bins equally spaced in Q (Å⁻¹) via QBinSize/QMin/QMax parameters
  • CBF file format — new ReadCBFFrame() reader for CBF detector data
  • Streaming median — histogram-based streaming median for NF image processing (~500 MB vs 11.5 GB)
  • Stripe artifact removal — Vo et al. (2018) algorithms for tomography ring/stripe correction
  • Shared integration library — extracted IntegrationCore, MapperCore, CalibrationCore, CalibPeakFit modules
  • Centralized MIDAS_ParamParser — unified parameter file parsing across all executables
  • Gradient-aware pixel splitting — sub-pixel radial resampling for improved integration accuracy

Recent GUI Update (May 2026)

  • FF viewer caking overlay workflow — added load/save/edit support for cake_parameters*.csv, per-detector caking metadata, and composite-sector overlay drawing.
  • Plot/Clear + keyboard toggle — caking overlay can now be toggled directly from the GUI and with the C shortcut.
  • Multi-detector caking controls — HYDRA mode now includes per-GE cake rows and a dedicated cake parameter editor panel.
  • Path precedence hardening — explicit user selections (first file, dark file, HDF5 data/dark dataset paths) are preserved and no longer overwritten by later parameter-file loads.
  • Dark subtraction fallback — when no separate dark file is configured, dark data can be read from the current HDF5 data file path.
  • Overlay readability improvements — lab-frame axes were restyled for clearer on-image visibility.

Version 10 Highlights

  • Consolidated HDF5 output — all FF-HEDM results (grains, spots, strains, peak provenance) in a single .h5 file
  • Pipeline restart--resume and --restart-from flags on all workflows (FF, PF, NF, dual-dataset, multi-resolution) allow resuming from any completed stage using the HDF5 checkpoint
  • Version & provenance tracking — every C binary and Python workflow embeds MIDAS v11.0 (<git-hash>) into output files, HDF5 attributes, and Zarr metadata for full reproducibility
  • Pseudo-Voigt peak fitting — two-stage decomposed fitting (Lorentzian + Gaussian) with mu-weighted effective widths
  • Grain matching & stitching — Python-native optimal (Hungarian) matching across load states with affine deformation support
  • Reprocess mode — regenerate MergeMap.csv and consolidated HDF5 on old datasets (-reprocess 1)
  • Dynamic detector sizes — auto-detected from data, no hardcoded dimensions
  • Zarr-ZIP data format — compressed, portable, self-contained analysis archives
  • Forward simulation engine — compressed output with OpenMP parallelism
  • Multi-resolution NF-HEDM — iterative reconstruction at increasing grid resolution
  • Interactive GUI — browser-based visualization of NF calibration, microstructure, and FF results
  • Multi-stage auto-calibration — geometry-first calibration strategy with panel auto-detection from masks

Repository Layout

MIDAS/
├── FF_HEDM/ # Far-field HEDM (calibration, indexing, fitting, integration)
│ ├── src/ # C source code (peak search, fitting, merging, indexing, grains)
│ ├── workflows/ # Python workflow drivers (ff_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ └── Example/ # Example dataset for testing
├── NF_HEDM/ # Near-field HEDM reconstruction
│ ├── src/ # C source code (forward model, grid reconstruction)
│ ├── workflows/ # Python workflow drivers (nf_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ ├── v7/ # Workflow templates
│ ├── seedOrientations/ # Orientation seed files (downloaded by build)
│ └── Example/ # Example dataset for testing
├── DT/ # Diffraction tomography (peak-fit integrator)
├── TOMO/ # Tomographic reconstruction (gridrec CT engine)
├── utils/ # Python utilities
│ ├── AutoCalibrateZarr.py # FF-HEDM auto-calibration
│ ├── match_grains.py # Grain matching and layer stitching
│ ├── calcMiso.py # Crystallographic misorientation calculations
│ ├── gsas_ii_refine.py # GSAS-II integration
│ └── ...
├── gui/ # Interactive visualization GUI
├── manuals/ # Comprehensive documentation (see below)
├── cmake/ # CMake build configuration and dependency management
├── build.sh # Build script (Linux / macOS)
├── build_wsl_windows.sh # Build script (Windows via WSL)
├── environment.yml # Conda environment specification
├── CMakeLists.txt # Top-level CMake configuration
└── LICENSE # UChicago Argonne open-source license

Documentation

Full manuals are in the manuals/ directory. Start with the manuals README for an overview of all HEDM techniques, coordinate systems, and a getting-started checklist.

ManualTopic
GPU_AccelerationGPU-accelerated computation (CUDA)
FF_CalibrationFF-HEDM geometry calibration
FF_AnalysisFF-HEDM grain indexing and fitting
FF_Match_Stack_ReconstructionsGrain matching across load states and layer stitching
FF_Radial_IntegrationRadial integration / caking
FF_Interactive_PlottingInteractive FF-HEDM visualization
FF_VisualizationFF-HEDM result visualization
FF_Dual_DatasetsDual-dataset FF-HEDM analysis
PF_AnalysisPoint-Focus HEDM analysis
NF_CalibrationNF-HEDM detector calibration
NF_AnalysisNF-HEDM reconstruction workflow
NF_MultiResolution_AnalysisMulti-resolution NF-HEDM
NF_GUINF-HEDM interactive GUI
Forward_SimulationForward simulation for validation
GSAS-II_IntegrationImporting MIDAS output into GSAS-II
Tomography_ReconstructionAbsorption-contrast CT reconstruction
FF_BenchmarkFF-HEDM benchmark testing
NF_BenchmarkNF-HEDM benchmark testing

Installation

Python packages via pip (no source build)

The Python pipeline — calibration, integration, indexing, refinement, grain processing — installs from PyPI and does not need the source build below:

pip install "midas-suite[all]"

midas-index and midas-fit-grain bundle C/OpenMP executables (midas_indexer, midas_fitgrain) and are published as sdist, so pip compiles them during install. CMake and ninja come along automatically; you need a C compiler and OpenMP (macOS: brew install libomp gcc; Linux: gcc; Windows: Visual Studio Build Tools). If either is missing the install still succeeds and silently leaves you on the much slower Python-only path — so check:

importmidas_index.backend_casb; print(b.available()) # True = c-omp indexer presentimportmidas_fit_grain.backend_casf; print(f.available()) # True = c-omp refiner present

See packages/midas_suite/README.md for the full breakdown of what pip does and does not give you.

Prerequisites

PlatformRequirements
macOSHomebrew, LLVM, libomp, GCC, CMake, jemalloc
LinuxGCC ≥ 9, CMake ≥ 3.16
WindowsWSL with Ubuntu

MIDAS automatically downloads and builds these C/C++ dependencies during compilation: NLOPT, LIBTIFF, FFTW, HDF5, BLOSC, BLOSC-2, ZLIB, LIBZIP.

Clone

git clone https://github.com/marinerhemant/MIDAS.git
cd MIDAS

macOS

  1. Install Homebrew (if not already installed):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Without sudo access, install to your home directory:

    mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/main | tar xz --strip-components 1 -C homebrew
    eval"$(homebrew/bin/brew shellenv)"
    brew update --force --quiet
    chmod -R go-w "$(brew --prefix)/share/zsh"

    Add Homebrew to your PATH:

    echo'eval $(/opt/homebrew/bin/brew shellenv)'>>~/.zshrc
    source~/.zshrc
  2. Install dependencies:

    brew install llvm libomp gcc cmake jemalloc
  3. Configure environment variables:

    echo'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include $CPPFLAGS"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/libomp/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/libomp/include $CPPFLAGS"'>>~/.zshrc
    echo'CC=/opt/homebrew/opt/gcc/bin/gcc-15'>>~/.zshrc
    echo'export CC'>>~/.zshrc
    echo'CXX=/opt/homebrew/opt/gcc/bin/g++-15'>>~/.zshrc
    echo'export CXX'>>~/.zshrc
    source~/.zshrc
  4. Build:

    ./build.sh

Linux

./build.sh

Windows (WSL)

sudo ./build_wsl_windows.sh

Build Options

# Disable CUDA support
./build.sh --cuda OFF
# Specify a custom nvcc compiler path
./build.sh --nvcc /usr/local/cuda-12/bin/nvcc
# Or pass it directly to cmakecd build && cmake .. -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc && cmake --build . -j
# Specify target CUDA architectures (default is "86;90")cd build && cmake .. -DCMAKE_CUDA_ARCHITECTURES="75;80"&& cmake --build . -j
# Build and run benchmarks
./build.sh --test all
# Build a single targetcd build
cmake --build . --target IntegratorFitPeaksGPUStream

Updating After git pull

Each time you pull the latest changes, rebuild the C binaries:

cd MIDAS/build
cmake --build .

Python Environment

conda env create -f environment.yml
conda activate midas_env

Or install the required packages manually:

pip install numpy scipy h5py parsl

Quick Start

  1. Calibrate the detector geometry → FF_Calibration
  2. Run FF-HEDM grain indexing and fitting → FF_Analysis
  3. Visualize results interactively → FF_Interactive_Plotting
  4. Match/stitch grains across load states or layers → FF_Match_Stack_Reconstructions
  5. Reconstruct NF-HEDM orientation maps → NF_Analysis
  6. Validate with forward simulation → Forward_Simulation

See the manuals README for the full step-by-step checklist.

Example: Run FF-HEDM on the included test dataset

conda activate midas_env
cd FF_HEDM/Example
python ../workflows/ff_MIDAS.py -paramFN ps_ff.txt

Example: Run FF-HEDM with GPU acceleration

python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -useGPU 1

Example: Resume a failed pipeline from its last checkpoint

# Auto-detect last completed stage and resume:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -resume /path/to/consolidated.h5
# Or restart from a specific stage:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -restartFrom refinement

Example: Reprocess old results (generate MergeMap.csv + consolidated HDF5)

python FF_HEDM/workflows/ff_MIDAS.py -reprocess 1 -resultFolder /path/to/results/

Example: Match grains across load states

python utils/match_grains.py match \
--state1 unloaded/Grains.csv \
--state2 loaded/Grains.csv \
--space-group 225 --mode combined --weights 2.0 50.0

Benchmark Testing

MIDAS includes automated benchmark tests that validate every pipeline using synthetic data and built-in reference comparisons. Each test also runs pre-flight checks (binary existence, staleness, package availability) and prints an environment fingerprint to make failures easy to diagnose.

Quick Start

# Build and run all benchmarks
./build.sh --test all
# Or run benchmarks individually:
./build.sh --test ff # FF-HEDM only
./build.sh --test nf # NF-HEDM only

Running Benchmarks Separately

conda activate midas_env
# FF-HEDM: Forward simulation → indexing → grain recovery (6-stage HDF5 comparison)
python tests/test_ff_hedm.py -nCPUs 4
# NF-HEDM: Forward simulation → reconstruction → orientation comparison (>80% < 0.25°)
python tests/test_nf_hedm.py -nCPUs 8
# Calibration + Integration: CeO2 ring fitting + peak strain residual
python tests/test_calibration_integration.py -nCPUs 4
# Phase ID: CeO2 detected, Au absent, lattice constant within 500 ppm
python tests/test_phase_id.py -nCPUs 4
# Tomography: Shepp-Logan phantom → FBP reconstruction → Pearson correlation > 0.85
python tests/test_tomo.py -nCPUs 4

If a Test Fails

All tests support built-in diagnostic flags for troubleshooting:

# Generate a JSON diagnostic report with full environment and comparison details
python tests/test_ff_hedm.py -nCPUs 4 --diagnose
# Save the generated output file alongside the reference for manual comparison
python tests/test_ff_hedm.py -nCPUs 4 --save-on-fail

Send the generated diagnostic report to hsharma@anl.gov for assistance.

See tests/README.md for detailed documentation on what each test computes, how results are compared, and exact pass/fail criteria.


Citing MIDAS

If you use MIDAS in your research, please cite:

In review, citations coming soon.

FF-HEDM methodology:

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. I. Overlapping diffraction peaks and parameters of the experimental setup," J. Appl. Cryst.45, 693–704 (2012). DOI: 10.1107/S0021889812025563

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. II. Volume, centre-of-mass position, crystallographic orientation and strain state of grains," J. Appl. Cryst.45, 705–718 (2012). DOI: 10.1107/S0021889812025599


Acknowledgments

  • SGInfo library for HKL calculations
  • ODFPF package (Cornell) for misorientation functions

License

MIDAS is released under the UChicago Argonne open-source license.

Copyright © 2012, UChicago Argonne, LLC. All rights reserved.

This product includes software produced by UChicago Argonne, LLC under Contract No. DE-AC02-06CH11357 with the Department of Energy.

About

No description, website, or topics provided.

Resources

Contributing

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

MIDAS Logo

MIDAS — Microstructural Imaging using Diffraction Analysis Software

License

MIDAS is an open-source suite for reconstructing three-dimensional microstructures from High-Energy Diffraction Microscopy (HEDM) data. Developed at the Advanced Photon Source at Argonne National Laboratory, it supports the complete data-reduction pipeline — from raw detector frames to grain maps, strain tensors, spatially resolved orientation fields, and tomographic reconstructions.

Version: 11.0 Contact:Hemant Sharma (hsharma@anl.gov)


Key Capabilities

TechniqueWhat It ProducesDetector Distance
Far-Field HEDM (FF-HEDM)Grain centroids, average orientations, full elastic strain tensors≈ 1 m
Near-Field HEDM (NF-HEDM)Spatially resolved 3D orientation maps, grain morphology, grain boundary networks≈ 5–10 mm
Point-Focus HEDM (PF-HEDM)High-resolution grain orientations from focused beam≈ 1 m
Radial Integration (Caking)1D intensity vs. 2θ profiles for Rietveld refinement (GSAS-II)
Grain Matching & StitchingTrack grains across load states; combine multi-layer scans
Tomography (CT)Absorption-contrast cross-sections via gridrec algorithm

Version 11 Highlights

  • GPU acceleration — CUDA-accelerated indexing (IndexerGPU), strain fitting (FitPosOrStrainsGPU), NF orientation fitting (FitOrientationGPU), scanning HEDM (IndexerScanningGPU, FitOrStrainsScanningGPU), radial integration (IntegratorFitPeaksGPUStream), and tomographic reconstruction (tomo_gpu). See GPU_Acceleration
  • Consolidated binary I/O — PF/scanning HEDM replaces ~30K+ per-voxel files with 3 consolidated binary files per scan via IndexerConsolidatedIO.h
  • CalibrantIntegratorOMP — new primary calibration executable (replaces archived CalibrantPanelShiftsOMP)
  • Switchable peak fitting — unified pseudo-Voigt (pV) and Thompson-Cox-Hastings (TCH) modes across calibration, integration, and auto-calibration
  • Physical corrections — parallax, solid-angle, and polarization corrections in DetectorMapper (matching pyFAI convention)
  • Q-spacing integration — radial bins equally spaced in Q (Å⁻¹) via QBinSize/QMin/QMax parameters
  • CBF file format — new ReadCBFFrame() reader for CBF detector data
  • Streaming median — histogram-based streaming median for NF image processing (~500 MB vs 11.5 GB)
  • Stripe artifact removal — Vo et al. (2018) algorithms for tomography ring/stripe correction
  • Shared integration library — extracted IntegrationCore, MapperCore, CalibrationCore, CalibPeakFit modules
  • Centralized MIDAS_ParamParser — unified parameter file parsing across all executables
  • Gradient-aware pixel splitting — sub-pixel radial resampling for improved integration accuracy

Recent GUI Update (May 2026)

  • FF viewer caking overlay workflow — added load/save/edit support for cake_parameters*.csv, per-detector caking metadata, and composite-sector overlay drawing.
  • Plot/Clear + keyboard toggle — caking overlay can now be toggled directly from the GUI and with the C shortcut.
  • Multi-detector caking controls — HYDRA mode now includes per-GE cake rows and a dedicated cake parameter editor panel.
  • Path precedence hardening — explicit user selections (first file, dark file, HDF5 data/dark dataset paths) are preserved and no longer overwritten by later parameter-file loads.
  • Dark subtraction fallback — when no separate dark file is configured, dark data can be read from the current HDF5 data file path.
  • Overlay readability improvements — lab-frame axes were restyled for clearer on-image visibility.

Version 10 Highlights

  • Consolidated HDF5 output — all FF-HEDM results (grains, spots, strains, peak provenance) in a single .h5 file
  • Pipeline restart--resume and --restart-from flags on all workflows (FF, PF, NF, dual-dataset, multi-resolution) allow resuming from any completed stage using the HDF5 checkpoint
  • Version & provenance tracking — every C binary and Python workflow embeds MIDAS v11.0 (<git-hash>) into output files, HDF5 attributes, and Zarr metadata for full reproducibility
  • Pseudo-Voigt peak fitting — two-stage decomposed fitting (Lorentzian + Gaussian) with mu-weighted effective widths
  • Grain matching & stitching — Python-native optimal (Hungarian) matching across load states with affine deformation support
  • Reprocess mode — regenerate MergeMap.csv and consolidated HDF5 on old datasets (-reprocess 1)
  • Dynamic detector sizes — auto-detected from data, no hardcoded dimensions
  • Zarr-ZIP data format — compressed, portable, self-contained analysis archives
  • Forward simulation engine — compressed output with OpenMP parallelism
  • Multi-resolution NF-HEDM — iterative reconstruction at increasing grid resolution
  • Interactive GUI — browser-based visualization of NF calibration, microstructure, and FF results
  • Multi-stage auto-calibration — geometry-first calibration strategy with panel auto-detection from masks

Repository Layout

MIDAS/
├── FF_HEDM/ # Far-field HEDM (calibration, indexing, fitting, integration)
│ ├── src/ # C source code (peak search, fitting, merging, indexing, grains)
│ ├── workflows/ # Python workflow drivers (ff_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ └── Example/ # Example dataset for testing
├── NF_HEDM/ # Near-field HEDM reconstruction
│ ├── src/ # C source code (forward model, grid reconstruction)
│ ├── workflows/ # Python workflow drivers (nf_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ ├── v7/ # Workflow templates
│ ├── seedOrientations/ # Orientation seed files (downloaded by build)
│ └── Example/ # Example dataset for testing
├── DT/ # Diffraction tomography (peak-fit integrator)
├── TOMO/ # Tomographic reconstruction (gridrec CT engine)
├── utils/ # Python utilities
│ ├── AutoCalibrateZarr.py # FF-HEDM auto-calibration
│ ├── match_grains.py # Grain matching and layer stitching
│ ├── calcMiso.py # Crystallographic misorientation calculations
│ ├── gsas_ii_refine.py # GSAS-II integration
│ └── ...
├── gui/ # Interactive visualization GUI
├── manuals/ # Comprehensive documentation (see below)
├── cmake/ # CMake build configuration and dependency management
├── build.sh # Build script (Linux / macOS)
├── build_wsl_windows.sh # Build script (Windows via WSL)
├── environment.yml # Conda environment specification
├── CMakeLists.txt # Top-level CMake configuration
└── LICENSE # UChicago Argonne open-source license

Documentation

Full manuals are in the manuals/ directory. Start with the manuals README for an overview of all HEDM techniques, coordinate systems, and a getting-started checklist.

ManualTopic
GPU_AccelerationGPU-accelerated computation (CUDA)
FF_CalibrationFF-HEDM geometry calibration
FF_AnalysisFF-HEDM grain indexing and fitting
FF_Match_Stack_ReconstructionsGrain matching across load states and layer stitching
FF_Radial_IntegrationRadial integration / caking
FF_Interactive_PlottingInteractive FF-HEDM visualization
FF_VisualizationFF-HEDM result visualization
FF_Dual_DatasetsDual-dataset FF-HEDM analysis
PF_AnalysisPoint-Focus HEDM analysis
NF_CalibrationNF-HEDM detector calibration
NF_AnalysisNF-HEDM reconstruction workflow
NF_MultiResolution_AnalysisMulti-resolution NF-HEDM
NF_GUINF-HEDM interactive GUI
Forward_SimulationForward simulation for validation
GSAS-II_IntegrationImporting MIDAS output into GSAS-II
Tomography_ReconstructionAbsorption-contrast CT reconstruction
FF_BenchmarkFF-HEDM benchmark testing
NF_BenchmarkNF-HEDM benchmark testing

Installation

Python packages via pip (no source build)

The Python pipeline — calibration, integration, indexing, refinement, grain processing — installs from PyPI and does not need the source build below:

pip install "midas-suite[all]"

midas-index and midas-fit-grain bundle C/OpenMP executables (midas_indexer, midas_fitgrain) and are published as sdist, so pip compiles them during install. CMake and ninja come along automatically; you need a C compiler and OpenMP (macOS: brew install libomp gcc; Linux: gcc; Windows: Visual Studio Build Tools). If either is missing the install still succeeds and silently leaves you on the much slower Python-only path — so check:

importmidas_index.backend_casb; print(b.available()) # True = c-omp indexer presentimportmidas_fit_grain.backend_casf; print(f.available()) # True = c-omp refiner present

See packages/midas_suite/README.md for the full breakdown of what pip does and does not give you.

Prerequisites

PlatformRequirements
macOSHomebrew, LLVM, libomp, GCC, CMake, jemalloc
LinuxGCC ≥ 9, CMake ≥ 3.16
WindowsWSL with Ubuntu

MIDAS automatically downloads and builds these C/C++ dependencies during compilation: NLOPT, LIBTIFF, FFTW, HDF5, BLOSC, BLOSC-2, ZLIB, LIBZIP.

Clone

git clone https://github.com/marinerhemant/MIDAS.git
cd MIDAS

macOS

  1. Install Homebrew (if not already installed):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Without sudo access, install to your home directory:

    mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/main | tar xz --strip-components 1 -C homebrew
    eval"$(homebrew/bin/brew shellenv)"
    brew update --force --quiet
    chmod -R go-w "$(brew --prefix)/share/zsh"

    Add Homebrew to your PATH:

    echo'eval $(/opt/homebrew/bin/brew shellenv)'>>~/.zshrc
    source~/.zshrc
  2. Install dependencies:

    brew install llvm libomp gcc cmake jemalloc
  3. Configure environment variables:

    echo'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include $CPPFLAGS"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/libomp/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/libomp/include $CPPFLAGS"'>>~/.zshrc
    echo'CC=/opt/homebrew/opt/gcc/bin/gcc-15'>>~/.zshrc
    echo'export CC'>>~/.zshrc
    echo'CXX=/opt/homebrew/opt/gcc/bin/g++-15'>>~/.zshrc
    echo'export CXX'>>~/.zshrc
    source~/.zshrc
  4. Build:

    ./build.sh

Linux

./build.sh

Windows (WSL)

sudo ./build_wsl_windows.sh

Build Options

# Disable CUDA support
./build.sh --cuda OFF
# Specify a custom nvcc compiler path
./build.sh --nvcc /usr/local/cuda-12/bin/nvcc
# Or pass it directly to cmakecd build && cmake .. -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc && cmake --build . -j
# Specify target CUDA architectures (default is "86;90")cd build && cmake .. -DCMAKE_CUDA_ARCHITECTURES="75;80"&& cmake --build . -j
# Build and run benchmarks
./build.sh --test all
# Build a single targetcd build
cmake --build . --target IntegratorFitPeaksGPUStream

Updating After git pull

Each time you pull the latest changes, rebuild the C binaries:

cd MIDAS/build
cmake --build .

Python Environment

conda env create -f environment.yml
conda activate midas_env

Or install the required packages manually:

pip install numpy scipy h5py parsl

Quick Start

  1. Calibrate the detector geometry → FF_Calibration
  2. Run FF-HEDM grain indexing and fitting → FF_Analysis
  3. Visualize results interactively → FF_Interactive_Plotting
  4. Match/stitch grains across load states or layers → FF_Match_Stack_Reconstructions
  5. Reconstruct NF-HEDM orientation maps → NF_Analysis
  6. Validate with forward simulation → Forward_Simulation

See the manuals README for the full step-by-step checklist.

Example: Run FF-HEDM on the included test dataset

conda activate midas_env
cd FF_HEDM/Example
python ../workflows/ff_MIDAS.py -paramFN ps_ff.txt

Example: Run FF-HEDM with GPU acceleration

python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -useGPU 1

Example: Resume a failed pipeline from its last checkpoint

# Auto-detect last completed stage and resume:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -resume /path/to/consolidated.h5
# Or restart from a specific stage:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -restartFrom refinement

Example: Reprocess old results (generate MergeMap.csv + consolidated HDF5)

python FF_HEDM/workflows/ff_MIDAS.py -reprocess 1 -resultFolder /path/to/results/

Example: Match grains across load states

python utils/match_grains.py match \
--state1 unloaded/Grains.csv \
--state2 loaded/Grains.csv \
--space-group 225 --mode combined --weights 2.0 50.0

Benchmark Testing

MIDAS includes automated benchmark tests that validate every pipeline using synthetic data and built-in reference comparisons. Each test also runs pre-flight checks (binary existence, staleness, package availability) and prints an environment fingerprint to make failures easy to diagnose.

Quick Start

# Build and run all benchmarks
./build.sh --test all
# Or run benchmarks individually:
./build.sh --test ff # FF-HEDM only
./build.sh --test nf # NF-HEDM only

Running Benchmarks Separately

conda activate midas_env
# FF-HEDM: Forward simulation → indexing → grain recovery (6-stage HDF5 comparison)
python tests/test_ff_hedm.py -nCPUs 4
# NF-HEDM: Forward simulation → reconstruction → orientation comparison (>80% < 0.25°)
python tests/test_nf_hedm.py -nCPUs 8
# Calibration + Integration: CeO2 ring fitting + peak strain residual
python tests/test_calibration_integration.py -nCPUs 4
# Phase ID: CeO2 detected, Au absent, lattice constant within 500 ppm
python tests/test_phase_id.py -nCPUs 4
# Tomography: Shepp-Logan phantom → FBP reconstruction → Pearson correlation > 0.85
python tests/test_tomo.py -nCPUs 4

If a Test Fails

All tests support built-in diagnostic flags for troubleshooting:

# Generate a JSON diagnostic report with full environment and comparison details
python tests/test_ff_hedm.py -nCPUs 4 --diagnose
# Save the generated output file alongside the reference for manual comparison
python tests/test_ff_hedm.py -nCPUs 4 --save-on-fail

Send the generated diagnostic report to hsharma@anl.gov for assistance.

See tests/README.md for detailed documentation on what each test computes, how results are compared, and exact pass/fail criteria.


Citing MIDAS

If you use MIDAS in your research, please cite:

In review, citations coming soon.

FF-HEDM methodology:

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. I. Overlapping diffraction peaks and parameters of the experimental setup," J. Appl. Cryst.45, 693–704 (2012). DOI: 10.1107/S0021889812025563

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. II. Volume, centre-of-mass position, crystallographic orientation and strain state of grains," J. Appl. Cryst.45, 705–718 (2012). DOI: 10.1107/S0021889812025599


Acknowledgments

  • SGInfo library for HKL calculations
  • ODFPF package (Cornell) for misorientation functions

License

MIDAS is released under the UChicago Argonne open-source license.

Copyright © 2012, UChicago Argonne, LLC. All rights reserved.

This product includes software produced by UChicago Argonne, LLC under Contract No. DE-AC02-06CH11357 with the Department of Energy.

About

No description, website, or topics provided.

Resources

Contributing

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

MIDAS Logo

MIDAS — Microstructural Imaging using Diffraction Analysis Software

License

MIDAS is an open-source suite for reconstructing three-dimensional microstructures from High-Energy Diffraction Microscopy (HEDM) data. Developed at the Advanced Photon Source at Argonne National Laboratory, it supports the complete data-reduction pipeline — from raw detector frames to grain maps, strain tensors, spatially resolved orientation fields, and tomographic reconstructions.

Version: 11.0 Contact:Hemant Sharma (hsharma@anl.gov)


Key Capabilities

TechniqueWhat It ProducesDetector Distance
Far-Field HEDM (FF-HEDM)Grain centroids, average orientations, full elastic strain tensors≈ 1 m
Near-Field HEDM (NF-HEDM)Spatially resolved 3D orientation maps, grain morphology, grain boundary networks≈ 5–10 mm
Point-Focus HEDM (PF-HEDM)High-resolution grain orientations from focused beam≈ 1 m
Radial Integration (Caking)1D intensity vs. 2θ profiles for Rietveld refinement (GSAS-II)
Grain Matching & StitchingTrack grains across load states; combine multi-layer scans
Tomography (CT)Absorption-contrast cross-sections via gridrec algorithm

Version 11 Highlights

  • GPU acceleration — CUDA-accelerated indexing (IndexerGPU), strain fitting (FitPosOrStrainsGPU), NF orientation fitting (FitOrientationGPU), scanning HEDM (IndexerScanningGPU, FitOrStrainsScanningGPU), radial integration (IntegratorFitPeaksGPUStream), and tomographic reconstruction (tomo_gpu). See GPU_Acceleration
  • Consolidated binary I/O — PF/scanning HEDM replaces ~30K+ per-voxel files with 3 consolidated binary files per scan via IndexerConsolidatedIO.h
  • CalibrantIntegratorOMP — new primary calibration executable (replaces archived CalibrantPanelShiftsOMP)
  • Switchable peak fitting — unified pseudo-Voigt (pV) and Thompson-Cox-Hastings (TCH) modes across calibration, integration, and auto-calibration
  • Physical corrections — parallax, solid-angle, and polarization corrections in DetectorMapper (matching pyFAI convention)
  • Q-spacing integration — radial bins equally spaced in Q (Å⁻¹) via QBinSize/QMin/QMax parameters
  • CBF file format — new ReadCBFFrame() reader for CBF detector data
  • Streaming median — histogram-based streaming median for NF image processing (~500 MB vs 11.5 GB)
  • Stripe artifact removal — Vo et al. (2018) algorithms for tomography ring/stripe correction
  • Shared integration library — extracted IntegrationCore, MapperCore, CalibrationCore, CalibPeakFit modules
  • Centralized MIDAS_ParamParser — unified parameter file parsing across all executables
  • Gradient-aware pixel splitting — sub-pixel radial resampling for improved integration accuracy

Recent GUI Update (May 2026)

  • FF viewer caking overlay workflow — added load/save/edit support for cake_parameters*.csv, per-detector caking metadata, and composite-sector overlay drawing.
  • Plot/Clear + keyboard toggle — caking overlay can now be toggled directly from the GUI and with the C shortcut.
  • Multi-detector caking controls — HYDRA mode now includes per-GE cake rows and a dedicated cake parameter editor panel.
  • Path precedence hardening — explicit user selections (first file, dark file, HDF5 data/dark dataset paths) are preserved and no longer overwritten by later parameter-file loads.
  • Dark subtraction fallback — when no separate dark file is configured, dark data can be read from the current HDF5 data file path.
  • Overlay readability improvements — lab-frame axes were restyled for clearer on-image visibility.

Version 10 Highlights

  • Consolidated HDF5 output — all FF-HEDM results (grains, spots, strains, peak provenance) in a single .h5 file
  • Pipeline restart--resume and --restart-from flags on all workflows (FF, PF, NF, dual-dataset, multi-resolution) allow resuming from any completed stage using the HDF5 checkpoint
  • Version & provenance tracking — every C binary and Python workflow embeds MIDAS v11.0 (<git-hash>) into output files, HDF5 attributes, and Zarr metadata for full reproducibility
  • Pseudo-Voigt peak fitting — two-stage decomposed fitting (Lorentzian + Gaussian) with mu-weighted effective widths
  • Grain matching & stitching — Python-native optimal (Hungarian) matching across load states with affine deformation support
  • Reprocess mode — regenerate MergeMap.csv and consolidated HDF5 on old datasets (-reprocess 1)
  • Dynamic detector sizes — auto-detected from data, no hardcoded dimensions
  • Zarr-ZIP data format — compressed, portable, self-contained analysis archives
  • Forward simulation engine — compressed output with OpenMP parallelism
  • Multi-resolution NF-HEDM — iterative reconstruction at increasing grid resolution
  • Interactive GUI — browser-based visualization of NF calibration, microstructure, and FF results
  • Multi-stage auto-calibration — geometry-first calibration strategy with panel auto-detection from masks

Repository Layout

MIDAS/
├── FF_HEDM/ # Far-field HEDM (calibration, indexing, fitting, integration)
│ ├── src/ # C source code (peak search, fitting, merging, indexing, grains)
│ ├── workflows/ # Python workflow drivers (ff_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ └── Example/ # Example dataset for testing
├── NF_HEDM/ # Near-field HEDM reconstruction
│ ├── src/ # C source code (forward model, grid reconstruction)
│ ├── workflows/ # Python workflow drivers (nf_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ ├── v7/ # Workflow templates
│ ├── seedOrientations/ # Orientation seed files (downloaded by build)
│ └── Example/ # Example dataset for testing
├── DT/ # Diffraction tomography (peak-fit integrator)
├── TOMO/ # Tomographic reconstruction (gridrec CT engine)
├── utils/ # Python utilities
│ ├── AutoCalibrateZarr.py # FF-HEDM auto-calibration
│ ├── match_grains.py # Grain matching and layer stitching
│ ├── calcMiso.py # Crystallographic misorientation calculations
│ ├── gsas_ii_refine.py # GSAS-II integration
│ └── ...
├── gui/ # Interactive visualization GUI
├── manuals/ # Comprehensive documentation (see below)
├── cmake/ # CMake build configuration and dependency management
├── build.sh # Build script (Linux / macOS)
├── build_wsl_windows.sh # Build script (Windows via WSL)
├── environment.yml # Conda environment specification
├── CMakeLists.txt # Top-level CMake configuration
└── LICENSE # UChicago Argonne open-source license

Documentation

Full manuals are in the manuals/ directory. Start with the manuals README for an overview of all HEDM techniques, coordinate systems, and a getting-started checklist.

ManualTopic
GPU_AccelerationGPU-accelerated computation (CUDA)
FF_CalibrationFF-HEDM geometry calibration
FF_AnalysisFF-HEDM grain indexing and fitting
FF_Match_Stack_ReconstructionsGrain matching across load states and layer stitching
FF_Radial_IntegrationRadial integration / caking
FF_Interactive_PlottingInteractive FF-HEDM visualization
FF_VisualizationFF-HEDM result visualization
FF_Dual_DatasetsDual-dataset FF-HEDM analysis
PF_AnalysisPoint-Focus HEDM analysis
NF_CalibrationNF-HEDM detector calibration
NF_AnalysisNF-HEDM reconstruction workflow
NF_MultiResolution_AnalysisMulti-resolution NF-HEDM
NF_GUINF-HEDM interactive GUI
Forward_SimulationForward simulation for validation
GSAS-II_IntegrationImporting MIDAS output into GSAS-II
Tomography_ReconstructionAbsorption-contrast CT reconstruction
FF_BenchmarkFF-HEDM benchmark testing
NF_BenchmarkNF-HEDM benchmark testing

Installation

Python packages via pip (no source build)

The Python pipeline — calibration, integration, indexing, refinement, grain processing — installs from PyPI and does not need the source build below:

pip install "midas-suite[all]"

midas-index and midas-fit-grain bundle C/OpenMP executables (midas_indexer, midas_fitgrain) and are published as sdist, so pip compiles them during install. CMake and ninja come along automatically; you need a C compiler and OpenMP (macOS: brew install libomp gcc; Linux: gcc; Windows: Visual Studio Build Tools). If either is missing the install still succeeds and silently leaves you on the much slower Python-only path — so check:

importmidas_index.backend_casb; print(b.available()) # True = c-omp indexer presentimportmidas_fit_grain.backend_casf; print(f.available()) # True = c-omp refiner present

See packages/midas_suite/README.md for the full breakdown of what pip does and does not give you.

Prerequisites

PlatformRequirements
macOSHomebrew, LLVM, libomp, GCC, CMake, jemalloc
LinuxGCC ≥ 9, CMake ≥ 3.16
WindowsWSL with Ubuntu

MIDAS automatically downloads and builds these C/C++ dependencies during compilation: NLOPT, LIBTIFF, FFTW, HDF5, BLOSC, BLOSC-2, ZLIB, LIBZIP.

Clone

git clone https://github.com/marinerhemant/MIDAS.git
cd MIDAS

macOS

  1. Install Homebrew (if not already installed):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Without sudo access, install to your home directory:

    mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/main | tar xz --strip-components 1 -C homebrew
    eval"$(homebrew/bin/brew shellenv)"
    brew update --force --quiet
    chmod -R go-w "$(brew --prefix)/share/zsh"

    Add Homebrew to your PATH:

    echo'eval $(/opt/homebrew/bin/brew shellenv)'>>~/.zshrc
    source~/.zshrc
  2. Install dependencies:

    brew install llvm libomp gcc cmake jemalloc
  3. Configure environment variables:

    echo'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include $CPPFLAGS"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/libomp/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/libomp/include $CPPFLAGS"'>>~/.zshrc
    echo'CC=/opt/homebrew/opt/gcc/bin/gcc-15'>>~/.zshrc
    echo'export CC'>>~/.zshrc
    echo'CXX=/opt/homebrew/opt/gcc/bin/g++-15'>>~/.zshrc
    echo'export CXX'>>~/.zshrc
    source~/.zshrc
  4. Build:

    ./build.sh

Linux

./build.sh

Windows (WSL)

sudo ./build_wsl_windows.sh

Build Options

# Disable CUDA support
./build.sh --cuda OFF
# Specify a custom nvcc compiler path
./build.sh --nvcc /usr/local/cuda-12/bin/nvcc
# Or pass it directly to cmakecd build && cmake .. -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc && cmake --build . -j
# Specify target CUDA architectures (default is "86;90")cd build && cmake .. -DCMAKE_CUDA_ARCHITECTURES="75;80"&& cmake --build . -j
# Build and run benchmarks
./build.sh --test all
# Build a single targetcd build
cmake --build . --target IntegratorFitPeaksGPUStream

Updating After git pull

Each time you pull the latest changes, rebuild the C binaries:

cd MIDAS/build
cmake --build .

Python Environment

conda env create -f environment.yml
conda activate midas_env

Or install the required packages manually:

pip install numpy scipy h5py parsl

Quick Start

  1. Calibrate the detector geometry → FF_Calibration
  2. Run FF-HEDM grain indexing and fitting → FF_Analysis
  3. Visualize results interactively → FF_Interactive_Plotting
  4. Match/stitch grains across load states or layers → FF_Match_Stack_Reconstructions
  5. Reconstruct NF-HEDM orientation maps → NF_Analysis
  6. Validate with forward simulation → Forward_Simulation

See the manuals README for the full step-by-step checklist.

Example: Run FF-HEDM on the included test dataset

conda activate midas_env
cd FF_HEDM/Example
python ../workflows/ff_MIDAS.py -paramFN ps_ff.txt

Example: Run FF-HEDM with GPU acceleration

python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -useGPU 1

Example: Resume a failed pipeline from its last checkpoint

# Auto-detect last completed stage and resume:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -resume /path/to/consolidated.h5
# Or restart from a specific stage:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -restartFrom refinement

Example: Reprocess old results (generate MergeMap.csv + consolidated HDF5)

python FF_HEDM/workflows/ff_MIDAS.py -reprocess 1 -resultFolder /path/to/results/

Example: Match grains across load states

python utils/match_grains.py match \
--state1 unloaded/Grains.csv \
--state2 loaded/Grains.csv \
--space-group 225 --mode combined --weights 2.0 50.0

Benchmark Testing

MIDAS includes automated benchmark tests that validate every pipeline using synthetic data and built-in reference comparisons. Each test also runs pre-flight checks (binary existence, staleness, package availability) and prints an environment fingerprint to make failures easy to diagnose.

Quick Start

# Build and run all benchmarks
./build.sh --test all
# Or run benchmarks individually:
./build.sh --test ff # FF-HEDM only
./build.sh --test nf # NF-HEDM only

Running Benchmarks Separately

conda activate midas_env
# FF-HEDM: Forward simulation → indexing → grain recovery (6-stage HDF5 comparison)
python tests/test_ff_hedm.py -nCPUs 4
# NF-HEDM: Forward simulation → reconstruction → orientation comparison (>80% < 0.25°)
python tests/test_nf_hedm.py -nCPUs 8
# Calibration + Integration: CeO2 ring fitting + peak strain residual
python tests/test_calibration_integration.py -nCPUs 4
# Phase ID: CeO2 detected, Au absent, lattice constant within 500 ppm
python tests/test_phase_id.py -nCPUs 4
# Tomography: Shepp-Logan phantom → FBP reconstruction → Pearson correlation > 0.85
python tests/test_tomo.py -nCPUs 4

If a Test Fails

All tests support built-in diagnostic flags for troubleshooting:

# Generate a JSON diagnostic report with full environment and comparison details
python tests/test_ff_hedm.py -nCPUs 4 --diagnose
# Save the generated output file alongside the reference for manual comparison
python tests/test_ff_hedm.py -nCPUs 4 --save-on-fail

Send the generated diagnostic report to hsharma@anl.gov for assistance.

See tests/README.md for detailed documentation on what each test computes, how results are compared, and exact pass/fail criteria.


Citing MIDAS

If you use MIDAS in your research, please cite:

In review, citations coming soon.

FF-HEDM methodology:

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. I. Overlapping diffraction peaks and parameters of the experimental setup," J. Appl. Cryst.45, 693–704 (2012). DOI: 10.1107/S0021889812025563

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. II. Volume, centre-of-mass position, crystallographic orientation and strain state of grains," J. Appl. Cryst.45, 705–718 (2012). DOI: 10.1107/S0021889812025599


Acknowledgments

  • SGInfo library for HKL calculations
  • ODFPF package (Cornell) for misorientation functions

License

MIDAS is released under the UChicago Argonne open-source license.

Copyright © 2012, UChicago Argonne, LLC. All rights reserved.

This product includes software produced by UChicago Argonne, LLC under Contract No. DE-AC02-06CH11357 with the Department of Energy.

About

No description, website, or topics provided.

Resources

Contributing

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

MIDAS Logo

MIDAS — Microstructural Imaging using Diffraction Analysis Software

License

MIDAS is an open-source suite for reconstructing three-dimensional microstructures from High-Energy Diffraction Microscopy (HEDM) data. Developed at the Advanced Photon Source at Argonne National Laboratory, it supports the complete data-reduction pipeline — from raw detector frames to grain maps, strain tensors, spatially resolved orientation fields, and tomographic reconstructions.

Version: 11.0 Contact:Hemant Sharma (hsharma@anl.gov)


Key Capabilities

TechniqueWhat It ProducesDetector Distance
Far-Field HEDM (FF-HEDM)Grain centroids, average orientations, full elastic strain tensors≈ 1 m
Near-Field HEDM (NF-HEDM)Spatially resolved 3D orientation maps, grain morphology, grain boundary networks≈ 5–10 mm
Point-Focus HEDM (PF-HEDM)High-resolution grain orientations from focused beam≈ 1 m
Radial Integration (Caking)1D intensity vs. 2θ profiles for Rietveld refinement (GSAS-II)
Grain Matching & StitchingTrack grains across load states; combine multi-layer scans
Tomography (CT)Absorption-contrast cross-sections via gridrec algorithm

Version 11 Highlights

  • GPU acceleration — CUDA-accelerated indexing (IndexerGPU), strain fitting (FitPosOrStrainsGPU), NF orientation fitting (FitOrientationGPU), scanning HEDM (IndexerScanningGPU, FitOrStrainsScanningGPU), radial integration (IntegratorFitPeaksGPUStream), and tomographic reconstruction (tomo_gpu). See GPU_Acceleration
  • Consolidated binary I/O — PF/scanning HEDM replaces ~30K+ per-voxel files with 3 consolidated binary files per scan via IndexerConsolidatedIO.h
  • CalibrantIntegratorOMP — new primary calibration executable (replaces archived CalibrantPanelShiftsOMP)
  • Switchable peak fitting — unified pseudo-Voigt (pV) and Thompson-Cox-Hastings (TCH) modes across calibration, integration, and auto-calibration
  • Physical corrections — parallax, solid-angle, and polarization corrections in DetectorMapper (matching pyFAI convention)
  • Q-spacing integration — radial bins equally spaced in Q (Å⁻¹) via QBinSize/QMin/QMax parameters
  • CBF file format — new ReadCBFFrame() reader for CBF detector data
  • Streaming median — histogram-based streaming median for NF image processing (~500 MB vs 11.5 GB)
  • Stripe artifact removal — Vo et al. (2018) algorithms for tomography ring/stripe correction
  • Shared integration library — extracted IntegrationCore, MapperCore, CalibrationCore, CalibPeakFit modules
  • Centralized MIDAS_ParamParser — unified parameter file parsing across all executables
  • Gradient-aware pixel splitting — sub-pixel radial resampling for improved integration accuracy

Recent GUI Update (May 2026)

  • FF viewer caking overlay workflow — added load/save/edit support for cake_parameters*.csv, per-detector caking metadata, and composite-sector overlay drawing.
  • Plot/Clear + keyboard toggle — caking overlay can now be toggled directly from the GUI and with the C shortcut.
  • Multi-detector caking controls — HYDRA mode now includes per-GE cake rows and a dedicated cake parameter editor panel.
  • Path precedence hardening — explicit user selections (first file, dark file, HDF5 data/dark dataset paths) are preserved and no longer overwritten by later parameter-file loads.
  • Dark subtraction fallback — when no separate dark file is configured, dark data can be read from the current HDF5 data file path.
  • Overlay readability improvements — lab-frame axes were restyled for clearer on-image visibility.

Version 10 Highlights

  • Consolidated HDF5 output — all FF-HEDM results (grains, spots, strains, peak provenance) in a single .h5 file
  • Pipeline restart--resume and --restart-from flags on all workflows (FF, PF, NF, dual-dataset, multi-resolution) allow resuming from any completed stage using the HDF5 checkpoint
  • Version & provenance tracking — every C binary and Python workflow embeds MIDAS v11.0 (<git-hash>) into output files, HDF5 attributes, and Zarr metadata for full reproducibility
  • Pseudo-Voigt peak fitting — two-stage decomposed fitting (Lorentzian + Gaussian) with mu-weighted effective widths
  • Grain matching & stitching — Python-native optimal (Hungarian) matching across load states with affine deformation support
  • Reprocess mode — regenerate MergeMap.csv and consolidated HDF5 on old datasets (-reprocess 1)
  • Dynamic detector sizes — auto-detected from data, no hardcoded dimensions
  • Zarr-ZIP data format — compressed, portable, self-contained analysis archives
  • Forward simulation engine — compressed output with OpenMP parallelism
  • Multi-resolution NF-HEDM — iterative reconstruction at increasing grid resolution
  • Interactive GUI — browser-based visualization of NF calibration, microstructure, and FF results
  • Multi-stage auto-calibration — geometry-first calibration strategy with panel auto-detection from masks

Repository Layout

MIDAS/
├── FF_HEDM/ # Far-field HEDM (calibration, indexing, fitting, integration)
│ ├── src/ # C source code (peak search, fitting, merging, indexing, grains)
│ ├── workflows/ # Python workflow drivers (ff_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ └── Example/ # Example dataset for testing
├── NF_HEDM/ # Near-field HEDM reconstruction
│ ├── src/ # C source code (forward model, grid reconstruction)
│ ├── workflows/ # Python workflow drivers (nf_MIDAS.py)
│ ├── bin/ # Compiled binaries (auto-generated by build)
│ ├── v7/ # Workflow templates
│ ├── seedOrientations/ # Orientation seed files (downloaded by build)
│ └── Example/ # Example dataset for testing
├── DT/ # Diffraction tomography (peak-fit integrator)
├── TOMO/ # Tomographic reconstruction (gridrec CT engine)
├── utils/ # Python utilities
│ ├── AutoCalibrateZarr.py # FF-HEDM auto-calibration
│ ├── match_grains.py # Grain matching and layer stitching
│ ├── calcMiso.py # Crystallographic misorientation calculations
│ ├── gsas_ii_refine.py # GSAS-II integration
│ └── ...
├── gui/ # Interactive visualization GUI
├── manuals/ # Comprehensive documentation (see below)
├── cmake/ # CMake build configuration and dependency management
├── build.sh # Build script (Linux / macOS)
├── build_wsl_windows.sh # Build script (Windows via WSL)
├── environment.yml # Conda environment specification
├── CMakeLists.txt # Top-level CMake configuration
└── LICENSE # UChicago Argonne open-source license

Documentation

Full manuals are in the manuals/ directory. Start with the manuals README for an overview of all HEDM techniques, coordinate systems, and a getting-started checklist.

ManualTopic
GPU_AccelerationGPU-accelerated computation (CUDA)
FF_CalibrationFF-HEDM geometry calibration
FF_AnalysisFF-HEDM grain indexing and fitting
FF_Match_Stack_ReconstructionsGrain matching across load states and layer stitching
FF_Radial_IntegrationRadial integration / caking
FF_Interactive_PlottingInteractive FF-HEDM visualization
FF_VisualizationFF-HEDM result visualization
FF_Dual_DatasetsDual-dataset FF-HEDM analysis
PF_AnalysisPoint-Focus HEDM analysis
NF_CalibrationNF-HEDM detector calibration
NF_AnalysisNF-HEDM reconstruction workflow
NF_MultiResolution_AnalysisMulti-resolution NF-HEDM
NF_GUINF-HEDM interactive GUI
Forward_SimulationForward simulation for validation
GSAS-II_IntegrationImporting MIDAS output into GSAS-II
Tomography_ReconstructionAbsorption-contrast CT reconstruction
FF_BenchmarkFF-HEDM benchmark testing
NF_BenchmarkNF-HEDM benchmark testing

Installation

Python packages via pip (no source build)

The Python pipeline — calibration, integration, indexing, refinement, grain processing — installs from PyPI and does not need the source build below:

pip install "midas-suite[all]"

midas-index and midas-fit-grain bundle C/OpenMP executables (midas_indexer, midas_fitgrain) and are published as sdist, so pip compiles them during install. CMake and ninja come along automatically; you need a C compiler and OpenMP (macOS: brew install libomp gcc; Linux: gcc; Windows: Visual Studio Build Tools). If either is missing the install still succeeds and silently leaves you on the much slower Python-only path — so check:

importmidas_index.backend_casb; print(b.available()) # True = c-omp indexer presentimportmidas_fit_grain.backend_casf; print(f.available()) # True = c-omp refiner present

See packages/midas_suite/README.md for the full breakdown of what pip does and does not give you.

Prerequisites

PlatformRequirements
macOSHomebrew, LLVM, libomp, GCC, CMake, jemalloc
LinuxGCC ≥ 9, CMake ≥ 3.16
WindowsWSL with Ubuntu

MIDAS automatically downloads and builds these C/C++ dependencies during compilation: NLOPT, LIBTIFF, FFTW, HDF5, BLOSC, BLOSC-2, ZLIB, LIBZIP.

Clone

git clone https://github.com/marinerhemant/MIDAS.git
cd MIDAS

macOS

  1. Install Homebrew (if not already installed):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Without sudo access, install to your home directory:

    mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/main | tar xz --strip-components 1 -C homebrew
    eval"$(homebrew/bin/brew shellenv)"
    brew update --force --quiet
    chmod -R go-w "$(brew --prefix)/share/zsh"

    Add Homebrew to your PATH:

    echo'eval $(/opt/homebrew/bin/brew shellenv)'>>~/.zshrc
    source~/.zshrc
  2. Install dependencies:

    brew install llvm libomp gcc cmake jemalloc
  3. Configure environment variables:

    echo'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include $CPPFLAGS"'>>~/.zshrc
    echo'export LDFLAGS="-L/opt/homebrew/opt/libomp/lib $LDFLAGS"'>>~/.zshrc
    echo'export CPPFLAGS="-I/opt/homebrew/opt/libomp/include $CPPFLAGS"'>>~/.zshrc
    echo'CC=/opt/homebrew/opt/gcc/bin/gcc-15'>>~/.zshrc
    echo'export CC'>>~/.zshrc
    echo'CXX=/opt/homebrew/opt/gcc/bin/g++-15'>>~/.zshrc
    echo'export CXX'>>~/.zshrc
    source~/.zshrc
  4. Build:

    ./build.sh

Linux

./build.sh

Windows (WSL)

sudo ./build_wsl_windows.sh

Build Options

# Disable CUDA support
./build.sh --cuda OFF
# Specify a custom nvcc compiler path
./build.sh --nvcc /usr/local/cuda-12/bin/nvcc
# Or pass it directly to cmakecd build && cmake .. -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc && cmake --build . -j
# Specify target CUDA architectures (default is "86;90")cd build && cmake .. -DCMAKE_CUDA_ARCHITECTURES="75;80"&& cmake --build . -j
# Build and run benchmarks
./build.sh --test all
# Build a single targetcd build
cmake --build . --target IntegratorFitPeaksGPUStream

Updating After git pull

Each time you pull the latest changes, rebuild the C binaries:

cd MIDAS/build
cmake --build .

Python Environment

conda env create -f environment.yml
conda activate midas_env

Or install the required packages manually:

pip install numpy scipy h5py parsl

Quick Start

  1. Calibrate the detector geometry → FF_Calibration
  2. Run FF-HEDM grain indexing and fitting → FF_Analysis
  3. Visualize results interactively → FF_Interactive_Plotting
  4. Match/stitch grains across load states or layers → FF_Match_Stack_Reconstructions
  5. Reconstruct NF-HEDM orientation maps → NF_Analysis
  6. Validate with forward simulation → Forward_Simulation

See the manuals README for the full step-by-step checklist.

Example: Run FF-HEDM on the included test dataset

conda activate midas_env
cd FF_HEDM/Example
python ../workflows/ff_MIDAS.py -paramFN ps_ff.txt

Example: Run FF-HEDM with GPU acceleration

python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -useGPU 1

Example: Resume a failed pipeline from its last checkpoint

# Auto-detect last completed stage and resume:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -resume /path/to/consolidated.h5
# Or restart from a specific stage:
python FF_HEDM/workflows/ff_MIDAS.py -paramFN ps_ff.txt -restartFrom refinement

Example: Reprocess old results (generate MergeMap.csv + consolidated HDF5)

python FF_HEDM/workflows/ff_MIDAS.py -reprocess 1 -resultFolder /path/to/results/

Example: Match grains across load states

python utils/match_grains.py match \
--state1 unloaded/Grains.csv \
--state2 loaded/Grains.csv \
--space-group 225 --mode combined --weights 2.0 50.0

Benchmark Testing

MIDAS includes automated benchmark tests that validate every pipeline using synthetic data and built-in reference comparisons. Each test also runs pre-flight checks (binary existence, staleness, package availability) and prints an environment fingerprint to make failures easy to diagnose.

Quick Start

# Build and run all benchmarks
./build.sh --test all
# Or run benchmarks individually:
./build.sh --test ff # FF-HEDM only
./build.sh --test nf # NF-HEDM only

Running Benchmarks Separately

conda activate midas_env
# FF-HEDM: Forward simulation → indexing → grain recovery (6-stage HDF5 comparison)
python tests/test_ff_hedm.py -nCPUs 4
# NF-HEDM: Forward simulation → reconstruction → orientation comparison (>80% < 0.25°)
python tests/test_nf_hedm.py -nCPUs 8
# Calibration + Integration: CeO2 ring fitting + peak strain residual
python tests/test_calibration_integration.py -nCPUs 4
# Phase ID: CeO2 detected, Au absent, lattice constant within 500 ppm
python tests/test_phase_id.py -nCPUs 4
# Tomography: Shepp-Logan phantom → FBP reconstruction → Pearson correlation > 0.85
python tests/test_tomo.py -nCPUs 4

If a Test Fails

All tests support built-in diagnostic flags for troubleshooting:

# Generate a JSON diagnostic report with full environment and comparison details
python tests/test_ff_hedm.py -nCPUs 4 --diagnose
# Save the generated output file alongside the reference for manual comparison
python tests/test_ff_hedm.py -nCPUs 4 --save-on-fail

Send the generated diagnostic report to hsharma@anl.gov for assistance.

See tests/README.md for detailed documentation on what each test computes, how results are compared, and exact pass/fail criteria.


Citing MIDAS

If you use MIDAS in your research, please cite:

In review, citations coming soon.

FF-HEDM methodology:

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. I. Overlapping diffraction peaks and parameters of the experimental setup," J. Appl. Cryst.45, 693–704 (2012). DOI: 10.1107/S0021889812025563

H. Sharma, R. M. Huizenga & S. E. Offerman, "A fast methodology to determine the characteristics of thousands of grains using three-dimensional X-ray diffraction. II. Volume, centre-of-mass position, crystallographic orientation and strain state of grains," J. Appl. Cryst.45, 705–718 (2012). DOI: 10.1107/S0021889812025599


Acknowledgments

  • SGInfo library for HKL calculations
  • ODFPF package (Cornell) for misorientation functions

License

MIDAS is released under the UChicago Argonne open-source license.

Copyright © 2012, UChicago Argonne, LLC. All rights reserved.

This product includes software produced by UChicago Argonne, LLC under Contract No. DE-AC02-06CH11357 with the Department of Energy.

About

No description, website, or topics provided.

Resources

Contributing

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages