A differentiable modeling package for automating X-ray fluorescence (XRF) analysis
Project description
MapsTorch
MapsTorch is a differentiable modeling package for automating X-ray fluorescence (XRF) analysis. It combines the physics-based MAPS model with PyTorch's automatic differentiation framework.
Key features:
- Automated parameter optimization for XRF spectrum fitting
- Automatic element detection and decision support
- GPU acceleration support for spectrum volume fitting
- Integration with existing XRF-Maps workflows
See extended abstract from M&M 2024.
Get Started
Latest development version:
pip install git+https://github.com/xyin-anl/MapsTorch.git
Latest release version:
pip install mapstorch
Optional: For GPU acceleration of spectra volume fitting, install PyTorch with CUDA support following https://pytorch.org/get-started/locally/
Prepare Data
MapsTorch works with HDF5 files produced by XRFMaps. The HDF5 file must contain:
- Spectra volume data in
MAPS/mca_arrgroup - Integrated spectra array in
MAPS/int_specgroup
An example dataset is provided in the assets folder. We recommend using H5Web to view HDF5 files.
For numpy array data, use the create_dataset function in mapstorch.io:
def create_dataset(
spec_vol,
energy_dim,
output_path,
fit_elems=None,
dtype=np.float32,
compression="gzip",
compression_opts=4,
):
"""Create an HDF5 file compatible with read_dataset function.
Args:
spec_vol: 3D numpy array or path to .npy file containing spectral volume
energy_dim: Which dimension (0,1,2) contains the energy channels
output_path: Path where to save the HDF5 file
fit_elems: Optional list of element names
dtype: numpy dtype for data storage (e.g. np.float32, np.float16). Default: np.float32
compression: Compression filter to use. Options: 'gzip', 'lzf', None. Default: 'gzip'
compression_opts: Compression settings. For 'gzip', this is the compression level (0-9). Default: 4
"""
Interactive Apps
We provide marimo notebooks in the apps folder that can be run as web apps (download the notebooks and run them in a Python environment with mapstorch installed):
Guess elements:
marimo run guess_elements.py
Optimize parameters:
marimo run optimize_parameters.py
Example Scripts
The scripts folder contains example scripts like fit_spec.py for fitting integrated spectra. Usage:
python fit_spec.py DATASET.h5 -e 12.0
For all options:
python scripts/fit_spec.py -h
Contact
- Bug reports and feature requests: Open GitHub Issues
- Contributions: Fork repository, create branch, submit pull request
- XRF analysis help: Contact xyin@anl.gov or aglowacki@anl.gov
Acknowledgement
This research used resources of the Advanced Photon Source, an U.S. Department of Energy (DOE) Office of Science User Facility operated for the DOE Office of Science by Argonne National Laboratory under Contract No. DE-AC02-06CH11357. The authors acknowledge funding support from Argonne LDRD 2023-0049.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mapstorch-0.0.1.tar.gz.
File metadata
- Download URL: mapstorch-0.0.1.tar.gz
- Upload date:
- Size: 376.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c59a11658713b099a1a08ec722217a1ba1364b2fe4e808a9a2be90465919cdb
|
|
| MD5 |
b1a3e4e380a4e19f90a9b892fcd2173f
|
|
| BLAKE2b-256 |
80c0a54a28103a28a31d108c14c15598a4909dc396f1e152c565242fafacf986
|
File details
Details for the file mapstorch-0.0.1-py3-none-any.whl.
File metadata
- Download URL: mapstorch-0.0.1-py3-none-any.whl
- Upload date:
- Size: 381.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32e362fb877bf055096f9bdf3a73c7c6dfa4fb185076f9fbf3ff6a09ac3f434c
|
|
| MD5 |
9387d4dd3fafee209bab461ec837d76b
|
|
| BLAKE2b-256 |
e551aedb1ccd3973cd0d760696795eb62ac61e4458714f0ac29c2c1ca6ecbf12
|