Skip to main content

Gaussian fitting for grazing incidence diffraction data

Project description

pygidFIT: Gaussian fitting for grazing incidence diffraction (GID) data

A Python package for fitting Gaussian functions to GID (Grazing-Incidence Wide-Angle X-ray and Neutron Scattering) data. pygidFIT is part of the comprehensive machine learning pipeline for automated analysis of GID data. The focus is on multiparallel execution for real-time sequential processing at the synchrotron and neutron facilities.

pygidFIT

Installation

Install using pip

pip install pygidfit

Install from source

First, clone the repository:

git clone git@github.com:mlgid-project/pygidFIT.git

Then, to install all required modules, navigate to the cloned directory and execute:

git clone git@github.com:mlgid-project/pygidFIT.git
cd pygidFIT
pip install -e .

Usage

Images from pygid NeXus file

from pygidfit import ProcessDataFromFile

filename = './example/BA2PbI4.h5'
analysis = ProcessDataFromFile(
    filename,                           # NeXus file with converted images and detected boxes (after pygid and mlgidDETECT)
    entry='entry_0000',                 # Entry to process (if None, processes all entries)
    frame_num=0,                        # Image frame to process (if None, processes all frames)
    crit_angle=2,                       # Critical angle to shift the sample horizon (in degrees)
    clustering_distance_rings=10,       # Distance for ring clustering (in pixels)
    clustering_distance_peaks=10,       # Distance for segments clustering (in pixels)
    clustering_extend=2,                # Number of pixels to extend the cluster size
    use_pool=False,                     # Whether to use peak pool from the previous image 
    debug=False,                        # Whether to plot fitting result and parameters)
    theta_fixed=True,                   # Whether to fix Gaussian tilt angle to 0° (azimuthal direction) during fitting. Default is True
)

Fit single image

from pygidfit import fit_data

img_container_fit = fit_data(
    polar_img=polar_img,              # 2D polar-transformed scattering image. Axis 0: polar angle (0–90°). Axis 1: radial coordinate |q| (Å⁻¹)
    radius=radius,                    # 1D array of radial centers of peak boxes (Å⁻¹)
    radius_width=radius_width,        # 1D array of radial widths of peak boxes (Å⁻¹)
    angle=angle,                      # 1D array of angular centers of peak boxes (degrees)
    angle_width=angle_width,          # 1D array of angular widths of peak boxes (degrees)
    wavelength=1e-10,                 # X-ray wavelength in meters. Used for missing-wedge calculation
    q_xy_max=3.5,                     # Upper cutoff for q_xy (Å⁻¹) used in peak classification
    q_z_max=3.5,                      # Upper cutoff for q_z (Å⁻¹) used in peak classification
    clustering_distance_peaks=10,     # Distance for ring clustering (in pixels)
    clustering_distance_rings=10,     # Distance for segments clustering (in pixels)
    clustering_extend=2,              # Number of pixels to extend the cluster size
    debug=False,                      # Whether to plot fitting result and parameters)
    peaks_pool=None,                  # List of pygidfit.Boxes or None (if don't use pool) 
    theta_fixed=True,                 # Whether to fix Gaussian tilt angle to 0° (azimuthal direction) during fitting. Default is True
)

This package is included in the mlgidBASE package and can be used as part of the mlgid pipeline.

Overview

pygidFIT is part of the machine learning pipeline for automated analysis of GID data. It is designed to analyze scattering data by fitting Gaussian profiles to peaks in both 1D and 2D data. It refines the peak positions revealed by the deep learning-based peak detection by automated conventional fitting during the postprocessing stage.

Key Features

  • Peak clustering: Groups spatially close peaks to improve fitting stability

  • Parameter reuse: Caches fit parameters from previous frames to accelerate time-series analysis

  • Parallel execution: Supports multiprocessing for efficient processing of large datasets

  • HDF5 compatibility: Operates directly on HDF5 files generated by pygid.DataSaver

Authors

License

MIT License

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

pygidfit-0.1.1.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

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

pygidfit-0.1.1-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file pygidfit-0.1.1.tar.gz.

File metadata

  • Download URL: pygidfit-0.1.1.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pygidfit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 55aa32ce781ba3815740dce704c1e8008c3730e23272299a2acbb852872f7ac8
MD5 56db7ed697b5c52e4fb2308e5f0f5e7d
BLAKE2b-256 c67413f2151187a296cb83e1384a9e5ff7b63f81e69d38720273a432e13846c5

See more details on using hashes here.

File details

Details for the file pygidfit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pygidfit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pygidfit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 20c99749c47eea0720721eb3aee3381aaaa39d9a7c4a37291ed9eb56067c07bb
MD5 1486b996b7b1c3f8fec3dadf35f45640
BLAKE2b-256 b66524171b34cf3fae154be4b664bd85435542883d309823fe0d343f28f7c3c6

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