Anri is a Python package for the GPU-accelerated analysis of Diffraction Microstructure Imaging data, such as (Scanning) Three-Dimensional X-Ray Diffraction [(s)3DXRD].
The core concept of Anri is as follows:
(almost) all of Anri is implemented in JAX, a Python library for high-performance (e.g. GPU-accelerated) numerical computing.
The benefit is that Anri will work on any major x86 (and some ARM) CPUs and any recent CUDA-compatible GPU.
At the core of Anri is a high-performance forward model that goes from sample space (e.g. a grid of UBI matrices) to detector space (e.g. [slow, fast] coordinates). This can be used to investigate the performance of existing (s)3DXRD analysis packages such as ImageD11 by comparing forward-projected data to the raw data that you measured. Intensities are computed using the structure factors thanks to Dan's Diffraction and accumulate in detector pixels.
Great effort has been undertaken to ensure that JAX-native Anri functions are differentiable, using the powerful auto-diff capabilities of JAX. This has two obvious use-cases:
By expressing instrumental parameters such as incident beam divergence and energy spread as Gaussian distributions, Anri can use the per-peak Jacobians produced by JAX to propagate these parameters into detector space as a covariance matrix in output space, thereby rendering fairly realistic peak shapes that are not just simple detector point spread functions. Therefore, a spread in beam energy (for example) manifests as a radial distribution on the detector.
Anri will take advantage of the differentiable, intensity-aware forward model to perform iterative refinement of grain maps produced by ImageD11 (and perhaps other programs in the future) to yield refined maps of orientation gradients and strains.
Anri is in the early stages of development and is not yet ready to use for experimental analysis.
However, it can already be used today to perform interesting scientific analysis on simulated data.
See the Tutorials and Examples section of the Documentation for some examples of what Anri can do.
We currently target all stable releases of Python. Today this is 3.9 - 3.14 on Windows, ubuntu and OSX (ARM and x86).
git clone git@github.com:jadball/anri.git anri
cd anrimodule load mamba
mamba create --prefix=./.conda -c conda-forge python pip setuptools
mamba activate ./.condapython -m pip install --upgrade pip unidepThis gives you CUDA-enabled JAX.
unidep install .[dev,cuda12] -eComing soon!
Anri may (eventually) rely on packages from both conda and pip.
For ease of installation, it is recommended to use unidep which can install packages from both sources.
git clone git@github.com:jadball/anri.git anri
cd anriconda create -n <env-name>
conda activate <env-name>which pip # should yield something inside the environment <env-name>python -m pip install --upgrade pip unidepunidep install .[dev] -eThis GitHub repository is based on the python package template by @allenai: python-package-template.
Visual Studio Code is recommended for development.
anri uses ruff to lint and format, and ty for type-checking.
All Python functions and files (outside of anri/sandbox) must conform for the GitHub CI tests to pass.
With Visual Studio Code you have easy access to automatic lint-on-save and format-on-save via extensions.
Inside .vscode you have a settings.sample.json which, if you're happy with, you can rename to settings.json to apply my recommended per-project settings for this repository.
You also have extensions.json containing my recommended extensions (including ruff) which Visual Studio Code should prompt you to install automatically.
A paper describing and using Anri is under development. In the meantime, please cite this repository directly, updating the version number as required:
@software{anri2026github,
author = {James A. D. Ball},
title = {{Anri}: {GPU}-accelerated {D}iffraction {M}icrostructure {I}maging analysis},
url = {https://github.com/jadball/anri},
version = {0.1.0},
year = {2026},
}
If you use this codebase in your publication, feel free to open a Pull Request to add your work here!
- Ball, J. A. D., Andreasen, J. W., Angelis, S. D., Wright, J. P., & Detlefs, C. (2026, July 9). Multi-Beam 3DXRD. IOP Conference Series: Materials Science and Engineering. 46th Risø International Symposium on Materials Science: Characterization of evolving microstructures in metals, DTU Risø Campus, Roskilde, Denmark. Accepted for publication.
Anri is currently primarily developed by James A. D. Ball. Many sections of Anri are based on ImageD11 - I recommend you check it out!
We are grateful to Carsten Detlefs, Axel Henningsson, and Jon P. Wright for their invaluable advice during the development of Anri.