Constants Module¶
The constants module provides physical constants and conversion factors used throughout XRayLabTool.
Physical constants for X-ray calculations.
This module contains fundamental physical constants used throughout X-ray analysis calculations, translated from the Julia implementation with preserved numerical precision. All values are provided with explanatory docstrings describing their physical meaning and units.
The constants are defined with high precision to ensure accurate calculations in X-ray optical property computations.
- xraylabtool.constants.ANGSTROM_TO_METER: Final[float] = 1e-10¶
Conversion factor from Angstroms to meters.
Value: 10⁻¹⁰ Units: m/Å Usage: length_m = length_angstrom * ANGSTROM_TO_METER
- xraylabtool.constants.AVOGADRO: Final[float] = 6.02214199e+23¶
Avogadro’s number.
The number of constituent particles (atoms or molecules) per mole. Used in calculations relating molecular properties to bulk material properties.
Value: 6.02214199 × 10²³ mol⁻¹ Units: per mole (mol⁻¹) Reference: CODATA 2018 recommended values
Note: This value maintains compatibility with the Julia implementation. For the most current CODATA value, see: 6.02214076e23 mol⁻¹ (exact since 2019).
- xraylabtool.constants.CM_TO_METER: Final[float] = 0.01¶
Conversion factor from centimeters to meters.
Value: 0.01 Units: m/cm Usage: length_m = length_cm * CM_TO_METER
- xraylabtool.constants.DEGREES_TO_RADIANS: Final[float] = 0.017453292519943295¶
Conversion factor from degrees to radians.
Value: π/180 ≈ 0.017453292519943295 Units: rad/° Usage: angle_rad = angle_deg * DEGREES_TO_RADIANS
- xraylabtool.constants.ELEMENT_CHARGE: Final[float] = 1.60217646e-19¶
Elementary charge.
The electric charge of a single proton, equal in magnitude to the charge of an electron. Used in X-ray calculations for energy unit conversions between Joules and eV.
Value: 1.60217646 × 10⁻¹⁹ C Units: coulombs (C) Reference: CODATA 2018 recommended values
Note: This value maintains compatibility with the Julia implementation. For the most current CODATA value, see: 1.602176634e-19 C (exact since 2019).
- xraylabtool.constants.ENERGY_TO_WAVELENGTH_FACTOR: Final[float] = 1.2398417166827828e-09¶
Pre-computed factor for energy-to-wavelength conversion.
This constant combines fundamental constants to efficiently convert X-ray energies in keV to wavelengths in meters using: λ = ENERGY_TO_WAVELENGTH_FACTOR / E_keV
Mathematical derivation: λ = hc/E = (hc/e) / E_eV = (hc/e) / (1000 × E_keV)
- Value: (SPEED_OF_LIGHT × PLANCK / ELEMENT_CHARGE) / 1000.0
= (2.998 × 10⁸ × 6.626 × 10⁻³⁴ / 1.602 × 10⁻¹⁹) / 1000 ≈ 1.240 × 10⁻⁶ m⋅keV
Units: meter-keV (m⋅keV) Usage: wavelength_m = ENERGY_TO_WAVELENGTH_FACTOR / energy_keV
- xraylabtool.constants.EV_TO_KEV: Final[float] = 0.001¶
Conversion factor from eV to keV.
Value: 0.001 Units: keV/eV Usage: energy_keV = energy_eV * EV_TO_KEV
- xraylabtool.constants.KEV_TO_EV: Final[float] = 1000.0¶
Conversion factor from keV to eV.
Value: 1000 Units: eV/keV Usage: energy_eV = energy_keV * KEV_TO_EV
- xraylabtool.constants.METER_TO_ANGSTROM: Final[float] = 10000000000.0¶
Conversion factor from meters to Angstroms.
Value: 10¹⁰ Units: Å/m Usage: length_angstrom = length_m * METER_TO_ANGSTROM
- xraylabtool.constants.METER_TO_CM: Final[float] = 100.0¶
Conversion factor from meters to centimeters.
Value: 100 Units: cm/m Usage: length_cm = length_m * METER_TO_CM
- xraylabtool.constants.PI: Final[float] = 3.141592653589793¶
The mathematical constant π.
The ratio of a circle’s circumference to its diameter, appearing frequently in X-ray scattering calculations and Fourier transforms.
Value: 3.141592653589793… Units: dimensionless
- xraylabtool.constants.PLANCK: Final[float] = 6.626068e-34¶
Planck constant.
The quantum of action, relating the energy of a photon to its frequency. Essential for X-ray energy-wavelength conversions through E = hc/λ.
Value: 6.626068 × 10⁻³⁴ J⋅s Units: joule-seconds (J⋅s) Reference: CODATA 2018 recommended values
Note: This value maintains compatibility with the Julia implementation. For the most current CODATA value, see: 6.62607015e-34 J⋅s (exact since 2019).
- xraylabtool.constants.RADIANS_TO_DEGREES: Final[float] = 57.29577951308232¶
Conversion factor from radians to degrees.
Value: 180/π ≈ 57.29577951308232 Units: °/rad Usage: angle_deg = angle_rad * RADIANS_TO_DEGREES
- xraylabtool.constants.SCATTERING_FACTOR: Final[float] = 270086523204316.84¶
Pre-computed factor for X-ray scattering calculations.
This constant combines the Thomson scattering length with Avogadro’s number and unit conversion factors, optimized for calculating dispersion and absorption coefficients in X-ray optical property calculations.
Mathematical derivation: Factor = (rₑ × Nₐ × 10⁶) / (2π)
Where: - rₑ: Thomson scattering length (classical electron radius) - Nₐ: Avogadro’s number - 10⁶: Unit conversion factor (cm³/m³ to account for density units) - 2π: Geometric factor from X-ray scattering theory
- Value: THOMPSON × AVOGADRO × 10⁶ / (2π)
≈ 2.70 × 10¹⁴ m⁻¹⋅mol⁻¹
Units: per meter per mole (m⁻¹⋅mol⁻¹) Usage: Used in calculating δ = (λ²/2π) × rₑ × ρ × Nₐ × (Σf₁) / M
- xraylabtool.constants.SPEED_OF_LIGHT: Final[float] = 299792458.0¶
Speed of light in vacuum.
The speed of electromagnetic radiation in vacuum, a fundamental physical constant that appears in many X-ray calculations involving wavelength-energy conversions.
Value: 299,792,458 m/s (exact by definition) Units: meters per second (m/s) Reference: SI base unit definition
- xraylabtool.constants.SQRT_2: Final[float] = 1.4142135623730951¶
Square root of 2.
Mathematical constant that appears in geometric calculations and normalizations in X-ray crystallography.
Value: 1.4142135623730951… Units: dimensionless
- xraylabtool.constants.THOMPSON: Final[float] = 2.8179403227e-15¶
Thomson scattering length (classical electron radius).
The Thomson scattering length represents the classical radius of an electron, which is the length scale characterizing the scattering of electromagnetic radiation by a free electron in the classical limit.
Value: 2.8179403227 × 10⁻¹⁵ m Units: meters (m) Reference: CODATA 2018 recommended values
- xraylabtool.constants.TWO_PI: Final[float] = 6.283185307179586¶
Mathematical constant 2π.
Commonly appears in X-ray calculations involving angular frequencies, momentum transfer, and scattering theory.
Value: 6.283185307179586… Units: dimensionless
- xraylabtool.constants.attenuation_length_cm(wavelength_angstrom, absorption)[source]¶
Calculate X-ray attenuation length from wavelength and absorption coefficient.
- Parameters:
- Return type:
- Returns:
Attenuation length (1/e length) in centimeters
Example
>>> from xraylabtool.constants import attenuation_length_cm >>> length = attenuation_length_cm(1.24, 1e-7) >>> print(f"Attenuation length: {length:.2f} cm") Attenuation length: 0.01 cm
- xraylabtool.constants.critical_angle_degrees(dispersion)[source]¶
Calculate critical angle for total external reflection from dispersion coefficient.
- Parameters:
dispersion (
float|floating[Any] |ndarray[tuple[Any,...],dtype[double]]) – Dispersion coefficient δ (dimensionless)- Return type:
- Returns:
Critical angle in degrees
Example
>>> from xraylabtool.constants import critical_angle_degrees >>> theta_c = critical_angle_degrees(1e-6) >>> print(f"Critical angle: {theta_c:.4f}°") Critical angle: 0.0810°
- xraylabtool.constants.energy_to_wavelength_angstrom(energy_kev)[source]¶
Convert X-ray energy in keV to wavelength in Angstroms.
- Parameters:
energy_kev (
float|floating[Any] |ndarray[tuple[Any,...],dtype[double]]) – X-ray energy in keV- Return type:
- Returns:
Wavelength in Angstroms
Example
>>> from xraylabtool.constants import energy_to_wavelength_angstrom >>> wavelength = energy_to_wavelength_angstrom(10.0) # 10 keV >>> print(f"Wavelength: {wavelength:.4f} Å") Wavelength: 1.2398 Å
- xraylabtool.constants.validate_constants()[source]¶
Validate that all constants are properly defined and have reasonable values.
- Return type:
- Returns:
True if all constants pass validation
- Raises:
ValueError – If any constant fails validation
- xraylabtool.constants.wavelength_angstrom_to_energy(wavelength_angstrom)[source]¶
Convert X-ray wavelength in Angstroms to energy in keV.
- Parameters:
wavelength_angstrom (
float|floating[Any] |ndarray[tuple[Any,...],dtype[double]]) – X-ray wavelength in Angstroms- Return type:
- Returns:
Energy in keV
Example
>>> from xraylabtool.constants import wavelength_angstrom_to_energy >>> energy = wavelength_angstrom_to_energy(1.2398) # Cu Kα₁ >>> print(f"Energy: {energy:.4f} keV") Energy: 10.0003 keV
Usage Examples¶
Energy-Wavelength Conversion:
from xraylabtool.constants import HC_EV_ANGSTROM
def energy_to_wavelength(energy_ev):
return HC_EV_ANGSTROM / energy_ev
wavelength = energy_to_wavelength(8000) # 1.55 Å
Critical Angle Calculation:
from xraylabtool.constants import MRAD_TO_DEGREE
import numpy as np
def critical_angle_degrees(delta):
theta_mrad = 1000 * np.sqrt(2 * delta) # Convert to mrad
return theta_mrad * MRAD_TO_DEGREE
Unit Conversions:
from xraylabtool.constants import G_CM3_TO_KG_M3, ANGSTROM_TO_METER
# Convert density
density_si = 2.33 * G_CM3_TO_KG_M3 # g/cm³ to kg/m³
# Convert wavelength
wavelength_m = 1.55 * ANGSTROM_TO_METER # Å to m
Material Properties:
from xraylabtool.constants import COMMON_MATERIAL_DENSITIES, SILICON_DENSITY
# Get standard material densities
materials = ['Si', 'Al', 'Cu', 'Fe']
for material in materials:
if material in COMMON_MATERIAL_DENSITIES:
density = COMMON_MATERIAL_DENSITIES[material]
print(f"{material}: {density} g/cm³")
Energy Range Validation:
from xraylabtool.constants import MIN_ENERGY_EV, MAX_ENERGY_EV
def validate_energy(energy):
if energy < MIN_ENERGY_EV:
raise ValueError(f"Energy {energy} eV below minimum {MIN_ENERGY_EV} eV")
if energy > MAX_ENERGY_EV:
raise ValueError(f"Energy {energy} eV above maximum {MAX_ENERGY_EV} eV")
return True
Constants Reference Table¶
Constant |
Symbol |
Value |
Unit |
|---|---|---|---|
Planck constant |
h |
4.136e-15 |
eV·s |
Speed of light |
c |
2.998e8 |
m/s |
Classical electron radius |
r₀ |
2.818e-15 |
m |
Electron rest energy |
mₑc² |
510,999 |
eV |
hc product |
hc |
12,398.4 |
eV·Å |
Conversion |
Factor |
Usage |
|---|---|---|
Å → m |
1.0e-10 |
Length units |
eV → J |
1.602e-19 |
Energy units |
mrad → deg |
0.0573 |
Angular units |
g/cm³ → kg/m³ |
1000 |
Density units |
CODATA Standards¶
All physical constants are based on the 2018 CODATA internationally recommended values, ensuring compatibility with modern scientific standards and other physics software packages.