Skip to content

shoham-b/XRay

Repository files navigation

X-Ray Diffraction Analysis for Crystal Lattices

CI codecov License: MIT

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.


1. Scientific Overview

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.

2. Features

  • Advanced Peak Fitting: Utilizes a double_voigt model 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 plotly graph 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 .env file.

3. Installation and Usage

Prerequisites

  • Python >=3.12
  • uv (for installation)

Steps

  1. Clone the repository:

    git clone https://github.com/shoham-baris/XRay.git
    cd XRay
  2. Install dependencies:

    uv pip install -r requirements.txt
  3. Run the analysis:

    python -m xray

    This will run the analysis on the default data/dummy.csv file. You can specify a different input file using the --input option or by creating a .env file.

  4. View the report: After the analysis is complete, you will find the interactive HTML report at artifacts/index.html.

Extension CLI

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.0

Analyze 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.


4. CI/CD

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.


5. License

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •