xraylarch: Synchrotron X-ray Data Analysis in Python

repository·master·Indexed 41 days ago

https://github.com/xraypy/xraylarch

A collection of modules and plugins for synchrotron X-ray data analysis. It provides tools for reading and processing X-ray Absorption Spectroscopy (XAS) data, including support for X-ray Data Interchange (XDI) files, Athena Project files, HDF5, NetCDF, and TIFF images. Features include utilities for pre-edge and background subtraction, Fast Fourier Transforms (FFT), parameter uncertainty estimation via confidence intervals, and integration with Epics Channel Access.

Tokens
89.2K
Snippets
261
Records
399
Agent score
51%

What's inside xraylarch

  1. Overview of the XRFMap Viewer application

    master

    The XRFMap Viewer is a GUI application within Larch designed for reading and displaying HDF5 files containing X-ray fluorescence (XRF) maps from synchrotron X-ray microprobes.

    It serves two primary functions:

    1. Displaying existing maps: Visualizing X-ray microprobe maps already stored in HDF5 format.
    2. Assembling maps: Creating HDF5 X-ray microprobe map files from raw data collected via APS beamline 13-ID-E or other microprobes using compatible Epics scanning software.

    The interface consists of a file browser on the left to select open map files and a tabbed window interface on the right for interacting with the selected data.

  2. Overview of the Larix Application

    master

    Larix is a graphical user interface (GUI) designed for the visualization and analysis of X-ray absorption spectroscopy (XAS) data, specifically XANES and EXAFS.

    Key features and characteristics:

    • Demeter Compatibility: It is patterned after the Demeter Package (Athena and Artemis), sharing similar concepts and presentation styles.
    • Reproducibility: While Larix provides an interactive GUI for data exploration, it records all analysis steps as Larch/Python commands. These commands can be saved and used for batch processing outside of the GUI.
    • Analysis Scope: Supports interactive data visualization, exploration, and analysis of XAS data.
  3. Overview of Fitting and Modeling in Larch

    master

    Larch provides robust tools for modeling data and performing complex fits of data to models. While Larch includes specialized fitting procedures for specific domains (such as EXAFS procedures like _xafs.autobk and _xafs.feffit), the core concepts and underlying algorithms are designed for modeling and fitting general spectra and data.

    Key workflows involve:

    1. Building models
    2. Setting up and performing fits
    3. Inspecting results
  4. Overview of Larch for X-ray Spectroscopy

    master

    Larch is an open-source Python library and suite of applications designed for processing and analyzing X-ray spectroscopy and imaging data.

    Supported Data Types:

    • X-ray Absorption Spectroscopy (XAS): Includes XANES (X-ray absorption near-edge spectroscopy) and EXAFS (extended X-ray absorption fine-structure spectroscopy).
    • X-ray Fluorescence (XRF): Spectra and image data from scanning X-ray microprobe beamlines.
    • X-ray Diffraction (XRD): Image data and 1-D patterns.

    Core Technologies: Larch is built on the scientific Python stack, including numpy, scipy, h5py, and matplotlib. It also utilizes a specialized macro language called the "Larch language" (based on asteval) for automation and batch processing.

  5. Available Larch Graphical User Interfaces

    master

    Larch provides several specialized GUIs for different X-ray spectroscopy, scattering, and imaging tasks. Many of these interfaces are interrelated and can launch one another to facilitate data interaction and processing.

    Key GUIs include:

    • Larix: A primary application for Larch.
    • Larch_XRF: For displaying and analyzing X-ray fluorescence (XRF) spectra.
    • Larch_XRD1D: For analyzing X-ray Diffraction (XRD) patterns, integrating XRD images into 1D patterns, and comparing patterns against CIF crystal structures.
    • GSE_Mapviewer: For visualization and analysis of XRF and XRD maps.
    • larch_gui (Basic Larch GUI): A simple command-line and data browser. It serves as the command-line buffer for other Larch GUIs and allows interaction with all raw data within the application.
  6. Common XAS Data Processing Tasks in Larix

    master

    Larix provides specialized dialogs to perform various corrections and manipulations on imported XAS data. These include:

    • Data Management: Copying, removing, renaming, or merging (summing) data groups.
    • Signal Cleaning: Deglitching spectra and smoothing noisy data.
    • Alignment & Calibration: Recalibrating or aligning spectra energy-wise.
    • Grid & Signal Transformation: Re-binning spectra onto a standard XAFS energy grid, de-convolving spectra, and correcting for over-absorption in fluorescence XANES spectra.
  7. Use the Larch XRD1D Viewer for pattern analysis

    master

    The Larch XRD1D application is designed for viewing and manipulating 1-dimensional XRD patterns (diffracted intensity as a function of scattering wavenumber $I(q)$ or angle $I(2\theta)$).

    Key capabilities include:

    • Reading and Comparison: Load and compare multiple XRD patterns simultaneously.
    • Background Management: Perform background fitting and subtraction from XRD patterns.
  8. Plotting and displaying data in Larch

    master

    Larch supports two primary types of data visualization:

    1. Line Plots (xy plots): Used to show traces of a set of functions $y(x)$.
    2. 2-dimensional image displays: Used to show a grayscale or false color map representing a 2-dimensional array of intensity.

    Larch's graphics are built using wxPython and the wxmplot library. This approach leverages matplotlib to provide publication-quality plots while offering interactive features like zooming, changing colors/labels, and easy saving/copying of images (via Ctrl-C or dropdown menus).

  9. Import and export data in Larix

    master

    Larix supports importing various XAS (X-ray Absorption Spectroscopy) data formats and exporting them into specific project or portable formats.

    Supported Import Formats

    • XDI data files: The standard data format for XAS.
    • Plain text (ASCII) files: Column-based data files common at beamlines.
    • Athena Project Files: Imports multiple data groups and associated processing parameters.
    • ESRF Spec/BLISS HDF5 files: Supports multiple scans (typically ordered by collection time).
    • Larch Session files (.larix): Portable files containing all data, processed arrays, journals, analysis results, and fit histories.

    Supported Export Formats

    • Athena Project files
    • CSV files
    • Larch Session files (.larix)
  10. Overview of the XAFS analysis workflow in Larch

    master

    Larch provides a comprehensive suite of tools for XAFS (X-ray Absorption Fine Structure) data processing, designed as an evolution of Ifeffit. The analysis workflow typically follows these eight steps:

    1. Reading raw data: Importing the initial experimental measurements.
    2. Data correction: Converting raw data to $\mu(E)$ (absorption coefficient vs energy).
    3. Pre-edge processing: Background removal and normalization.
    4. XANES interpretation: Analyzing the normalized $\mu(E)$ spectra.
    5. Post-edge processing: Background removal and conversion to $\chi(k)$ (EXAFS oscillations vs wavenumber).
    6. Fourier Transform: Converting $\chi(k)$ to $\chi(R)$ (radial distribution function).
    7. FEFF Path processing: Reading and processing FEFF paths from external files.
    8. XAFS Fitting: Fitting the $\chi(k)$ data to a sum of FEFF paths.

    All XAFS-specific functions are organized within the _xafs Group, which is included in the default search path for easy access.

  11. Understand Larch Variable Dynamics and Typing

    master

    Because Larch is based on Python, variables are created dynamically. They are not pre-defined with a specific data type, and a variable name can be reassigned to hold any type of data (e.g., changing a numeric variable to a string).

    While variables are dynamic, the values themselves have definite types, and type conversion is strictly defined. For example, you can add an integer to a real number to produce a real number, but you cannot perform operations between incompatible types like a string and a real number.

    larch> angle = asin(hc/(10000*2*d))*180/pi
    larch> print(angle)
    11.402879992850263
    larch> angle = 'now I am a string'