Skip to main content

A library for gas phase analysis at the CXI endstation

Project description

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.
  • Utilities — Unit conversions (keV, Å, a.u., q, θ), momentum-transfer maps, azimuthal binning, 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.utils

General-purpose utilities:

  • Unit conversionskeV2Angstroms, Angstroms2keV, au2invAngstroms, invAngstroms2au, q2theta, theta2q.
  • Detector geometrycompute_q_map, azimuthalBinning.
  • Molecular transformstranslate_molecule, rotate_molecule.
  • Element lookupselement_symbol_to_number, element_number_to_symbol.
  • Othercompress_ranges, enable_underscore_cleanup, J4M (lazy-loaded Jungfrau 4M geometry).

xrayscatteringtools.calib

Calibration and correction tools:

  • geometry_calibration — Fit beam center and detector distance via azimuthally-averaged scattering patterns (run_geometry_calibration, thompson_correction, geometry_correction).
  • maskingMaskMaker class for step-by-step pixel masking: dark, background, polygon, and per-q-ring sample masks.
  • scattering_corrections — Per-material correction factors (Si, Al, Be, Kapton HN, sample cell), attenuation-length lookups, and J4M_efficiency.
  • timetool_calibrationfast_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), plus iam_compton_spectrum.
  • geometries — Lazy-loaded optimized molecular geometries from bundled HDF5 data (accessed as module-level attributes, e.g. geometries.SF6).
  • patterns — Lazy-loaded ab initio scattering patterns from bundled HDF5 data (accessed as module-level attributes, e.g. patterns.SF6__HF__aug_cc_pVDZ).

Testing

The test suite uses pytest and covers all modules (360+ 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.

Project details


Download files

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

Source Distribution

xrayscatteringtools-1.0.0.tar.gz (386.8 kB view details)

Uploaded Source

Built Distribution

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

xrayscatteringtools-1.0.0-py3-none-any.whl (369.7 kB view details)

Uploaded Python 3

File details

Details for the file xrayscatteringtools-1.0.0.tar.gz.

File metadata

  • Download URL: xrayscatteringtools-1.0.0.tar.gz
  • Upload date:
  • Size: 386.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for xrayscatteringtools-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3184cf345d3a7541c78a256283ff0ce3f1a8d027f5541b4fad0a6f975f00a8cf
MD5 362e022e31d199f0000d8a7f842b6cb3
BLAKE2b-256 a5c4639bf337464b75e20b093b6f17071ccde352a6f8d7ff948003d4a35afbb9

See more details on using hashes here.

File details

Details for the file xrayscatteringtools-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for xrayscatteringtools-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c5a34eebe3d8505320599c816aff301870b5a9fdca77ba50ffe5d8b6d996afe
MD5 25d016fabdb41c73baadc9b3700ae5b5
BLAKE2b-256 3c03dacda90a48f75d17b69c11c4c438875cf08c5b13e26d204de5529622cf07

See more details on using hashes here.

Supported by

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