This repository contains a sophisticated Python framework for analyzing X-ray Diffraction (XRD) data to determine the lattice parameters of crystalline materials. It is specifically tailored for identifying and fitting K-alpha/K-beta doublets on a Bremsstrahlung background, a common scenario in XRD analysis.
The primary goal of this project is to automate the process of analyzing XRD data to determine the crystal structure of a sample. The core of the analysis involves:
- Peak Detection: Identifying the diffraction peaks in the raw XRD data.
- Peak Fitting: Fitting a physically-motivated model (a double Voigt profile on a Bremsstrahlung background) to the detected peaks to precisely locate the K-alpha and K-beta components.
- d-spacing Calculation: Using Bragg's Law to calculate the d-spacing for each fitted peak.
- Lattice Parameter Refinement: Using the calculated d-spacings to refine the crystal's lattice parameter 'a', providing a final, statistically robust result with an error estimate.
- Advanced Peak Fitting: Utilizes a
double_voigtmodel on a Bremsstrahlung background to accurately fit K-alpha/K-beta doublets. - Global Background Subtraction: Fits a single, global background to the entire spectrum for a more robust analysis.
- Interactive HTML Reports: Generates a self-contained HTML report with an interactive
plotlygraph and detailed summary tables. - Caching: Caches the results of expensive fitting operations to make subsequent runs significantly faster.
- Flexible Configuration: Supports configuration via both command-line arguments and a
.envfile.
- Python >=3.12
- uv (for installation)
-
Clone the repository:
git clone https://github.com/shoham-baris/XRay.git cd XRay -
Install dependencies:
uv pip install -r requirements.txt
-
Run the analysis:
python -m xray
This will run the analysis on the default
data/dummy.csvfile. You can specify a different input file using the--inputoption or by creating a.envfile. -
View the report: After the analysis is complete, you will find the interactive HTML report at
artifacts/index.html.
The project also includes an extension CLI for analyzing X-ray diffraction images.
Analyze a single image:
python -m xray.extension.cli analyze <path_to_image> --phys-w-mm 50.0 --phys-h-mm 50.0 --distance-l-mm 200.0Analyze a directory of images:
python -m xray.extension.cli analyze-dir <path_to_directory>This command processes all images in the directory in parallel and generates a combined report.
The project includes a CI/CD pipeline that automatically runs tests and builds the analysis report. You can view the status of the pipeline and the latest reports on the GitHub Actions page.
This project is licensed under the MIT License. See the LICENSE file for details.