Source code for xraylabtool.calculators.derived_quantities

"""
Derived quantities calculator for X-ray optical properties.

This module contains functions for calculating derived X-ray properties such as
critical angles, attenuation lengths, and other useful quantities.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

from xraylabtool.backend import ops
from xraylabtool.constants import PI, RADIANS_TO_DEGREES

if TYPE_CHECKING:
    import numpy as np


[docs] def calculate_critical_angle(dispersion_delta: np.ndarray) -> np.ndarray: """ Calculate critical angle for total external reflection. Args: dispersion_delta: Dispersion coefficient δ Returns: Critical angle in degrees """ theta_c_rad = ops.sqrt(2.0 * dispersion_delta) return theta_c_rad * RADIANS_TO_DEGREES # type: ignore[no-any-return]
[docs] def calculate_attenuation_length( wavelength_angstrom: np.ndarray, absorption_beta: np.ndarray ) -> np.ndarray: """ Calculate X-ray attenuation length (1/e length). Args: wavelength_angstrom: X-ray wavelength in Angstroms absorption_beta: Absorption coefficient β Returns: Attenuation length in centimeters """ wavelength_m = wavelength_angstrom * 1e-10 # Convert to meters length_m = wavelength_m / (4 * PI * absorption_beta) return length_m * 100 # Convert to centimeters
[docs] def calculate_transmission( thickness_cm: float, attenuation_length_cm: np.ndarray ) -> np.ndarray: """ Calculate transmission through a material thickness. Args: thickness_cm: Material thickness in centimeters attenuation_length_cm: Attenuation length in centimeters Returns: Transmission coefficient (0-1) """ return ops.exp(-thickness_cm / attenuation_length_cm) # type: ignore[no-any-return]
[docs] def calculate_scattering_length_density( dispersion_delta: np.ndarray, absorption_beta: np.ndarray, wavelength_angstrom: np.ndarray, ) -> tuple[np.ndarray, np.ndarray]: """ Calculate real and imaginary scattering length densities. Args: dispersion_delta: Dispersion coefficient δ absorption_beta: Absorption coefficient β wavelength_angstrom: X-ray wavelength in Angstroms Returns: Tuple of (real_sld, imaginary_sld) in units of Å⁻² """ wavelength_ang = wavelength_angstrom real_sld = -dispersion_delta / (PI * wavelength_ang**2) * 1e20 # Convert to Å⁻² imaginary_sld = absorption_beta / (PI * wavelength_ang**2) * 1e20 # Convert to Å⁻² return real_sld, imaginary_sld