Skip to main content

X-Ray Scattering Tools

Tests

xrayscatteringtools is a Python library for gas-phase X-ray scattering data analysis. It provides tools for data I/O, visualization, detector calibration, masking, and theoretical modeling. It is designed to work alongside the CXI-Template repository for analyzing data from the Coherent X-ray Imaging (CXI) endstation at the Linac Coherent Light Source (LCLS).

Features

  • Data I/O — Read and write .xyz and .mol molecular geometry files, combine multi-run HDF5 experimental data, and manage YAML-based experiment configurations.
  • Visualization — Plot Jungfrau 4M detector images with proper tiled geometry.
  • Calibration — Geometry calibration, interactive pixel masking, per-material scattering corrections, and timetool arrival-time calibration.
  • Theoretical Modeling — Compute elastic and inelastic scattering patterns via the Independent Atom Model (IAM), load ab initio scattering data and optimized molecular geometries.
  • Azimuthal Integration — Momentum-transfer maps and azimuthal binning of detector images, either built-in or through pyFAI.
  • Utilities — Unit conversions (keV, Å, a.u., q, θ), molecular transformations, and element lookups.

Installation

Install from PyPI:

pip install xrayscatteringtools

Or install from source:

git clone https://github.com/Weber-Group/xrayscatteringtools.git
cd xrayscatteringtools
pip install .

For development (includes pytest, black, mypy, ruff):

pip install -e ".[dev]"

Requirements: Python ≥ 3.9


Modules Overview

xrayscatteringtools.io

Data input and output:

  • combineRuns — Combine data from multiple LCLS experimental runs (HDF5).
  • read_xyz / write_xyz — Read and write .xyz molecular geometry files.
  • read_mol — Parse .mol / .molden files.
  • get_leaves — Inspect the dataset tree of an HDF5 file.
  • get_data_paths — Resolve run-specific data paths from a YAML config.
  • get_config / get_config_for_runs — Load experiment configuration values.

xrayscatteringtools.plotting

Detector visualization:

  • plot_j4m — Plot a Jungfrau 4M image using the stored pixel geometry.
  • plot_jungfrau — Plot arbitrary Jungfrau panel data with custom coordinates.
  • compute_pixel_edges / edges_from_centers — Derive pixel-edge arrays for pcolormesh.

xrayscatteringtools.azimuthal

Azimuthal integration of detector images (all distances in microns, angles in degrees, energy in keV):

  • compute_q_map — Per-pixel momentum transfer for a given detector geometry.
  • azimuthalBinning — Bin an image into q (or r) and optional azimuthal sectors, with polarization and solid-angle corrections.
  • create_J4m_integrator — Build a pyFAI AzimuthalIntegrator from the real Jungfrau 4M pixel layout.
  • azimuthalBinning_pyfai — pyFAI-based alternative to azimuthalBinning that takes the same geometry parameters. Pass a pre-built integrator (ai=) to reuse it across many images.

xrayscatteringtools.utils

General-purpose utilities:

  • Unit conversions — keV2Angstroms, Angstroms2keV, au2invAngstroms, invAngstroms2au, q2theta, theta2q.
  • Molecular transforms — translate_molecule, rotate_molecule.
  • Element lookups — element_symbol_to_number, element_number_to_symbol.
  • Other — compress_ranges, expand_ranges, enable_underscore_cleanup, J4M (lazy-loaded Jungfrau 4M geometry).

xrayscatteringtools.calib

Calibration and correction tools:

  • geometry_calibration — Fit beam center and detector distance to a theory pattern, with an optional flat background (run_geometry_calibration, thompson_correction, geometry_correction).
  • masking — MaskMaker class for step-by-step pixel masking: dark, background, polygon, and per-q-ring sample masks. The detector's line and T masks are applied from the start, so known-bad pixels never enter the statistics.
  • scattering_corrections — Per-material correction factors (Si, Al, Be, Kapton HN, sample cell), attenuation lengths from xraylib, and J4M_efficiency.
  • timetool_calibration — fast_erf_fit for edge detection, apply_timetool_correction for per-shot arrival-time correction, and add_calibration_to_yaml for persisting calibration parameters.

xrayscatteringtools.theory

Theoretical scattering models:

  • iam — Independent Atom Model: isotropic and oriented elastic/inelastic scattering patterns (iam_elastic_pattern, iam_inelastic_pattern, iam_total_pattern, and their _oriented variants), iam_compton_spectrum, and iam_inelastic_pattern_from_formula (Compton intensity from a chemical formula alone, no coordinates needed).
  • geometries — Lazy-loaded optimized molecular geometries from bundled HDF5 data (accessed as module-level attributes, e.g. geometries.SF6__CCSD_T_DHK__aug_cc_pV5Z_DK).
  • patterns — Lazy-loaded ab initio scattering patterns from bundled HDF5 data (accessed as module-level attributes named molecule__method__basis_set, e.g. patterns.SF6__HF__aug_cc_pVDZ). Available: SF6 at the HF, MP2, and CCSD levels (aug-cc-pVDZ), HF (cc-pVTZ), and frozen-core CCSD (aug-cc-pVDZ/TZ); Ne at the CCSD+X2C level (aug-cc-pVDZ/TZ/QZ+DK); and norbornadiene (NBD) and quadricyclane (QC) at HF (cc-pVTZ) and frozen-core CCSD (aug-cc-pVDZ). Every pattern has the total I_q; many also carry I_q_elastic/I_q_inelastic, and the newer ones add the I_q_hartree/I_q_exchange/I_q_cumulant decomposition. Some patterns carry a notes attribute with details of the calculation.

Testing

The test suite uses pytest and covers all modules (580+ tests):

pip install -e ".[dev]"
python -m pytest tests/

Tests run automatically via GitHub Actions on every push and pull request to main.


Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your changes.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Acknowledgments

This library was created by David J. Romano by compiling and standardizing code from previous data analysis pipelines. Maintained by the Weber Research Group and developed by collaborators to facilitate X-ray scattering research.

Metadata

Release files for xrayscatteringtools 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xrayscatteringtools 1.3.0
File Size Uploaded Provenance Actions
xrayscatteringtools-1.3.0.tar.gz 514.7 kB Without provenance Details for xrayscatteringtools-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xrayscatteringtools 1.3.0
File Interpreter ABI Platform Actions
xrayscatteringtools-1.3.0-py3-none-any.whl Python 3 none any Details for xrayscatteringtools-1.3.0-py3-none-any.whl

Total release size: 1.0 MB

Release files / xrayscatteringtools-1.3.0.tar.gz

Download URL xrayscatteringtools-1.3.0.tar.gz
Size 514.7 kB
Tags Source
SHA-256 checksum
How to use checksums
eb7a84ed8bd84cc1387ddc287f973124c1fd497987b25ba74e42e3dd3d97ca6e
BLAKE2b-256 checksum
How to use checksums
33422d3d36423c23fb17eb551cc291e24b9c8b2532db4d08f2cfa2b36cab10ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.0

Release files / xrayscatteringtools-1.3.0-py3-none-any.whl

Download URL xrayscatteringtools-1.3.0-py3-none-any.whl
Size 508.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
038a104ff3e08c099667a07f45a2a579581c84400535e33919bde3e4a84297a2
BLAKE2b-256 checksum
How to use checksums
63a85c04d80de391143328cb6633233ccd7732e4bdc28ac9cb09d3e381c08de0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.0

Security for xrayscatteringtools 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page