shadow4.physical_models.prerefl package
Submodules
shadow4.physical_models.prerefl.prerefl module
python version of the mirror reflectivity code and refractive index calculations in shadow.
- class shadow4.physical_models.prerefl.prerefl.PreRefl[source]
Bases:
object- get_attenuation_coefficient(energy1)[source]
Returns the attenuation coefficient.
- Parameters:
energy1 (float or numpy array) – The photon energy or array of energies in eV.
- Returns:
The attenuation coefficient in cm^-1.
- Return type:
float or numpy array
- classmethod get_attenuation_coefficient_external_dabax(photon_energy_ev=10000.0, material='SiC', density=3.217, dabax=None)[source]
Standalone method to return the attenuation coefficient.
- Parameters:
photon_energy_ev (float or numpy array) – The photon energy or array of energies in eV.
material (str, optional) – The symbol/formula of the material.
density (float, optional) – The material density in g/cm3.
dabax (None or instance of DabaxXraylib) – A pointer to the dabax library. Use None for default.
- Returns:
The array with attenuation coefficient in cm^-1.
- Return type:
float or numpy array
- classmethod get_attenuation_coefficient_external_xraylib(photon_energy_ev=10000.0, material='SiC', density=3.217)[source]
- get_refraction_index(energy1)[source]
Returns the complex refraction index.
- Parameters:
energy1 (float or numpy array) – The photon energy or array of energies in eV.
- Returns:
The complex refraction index.
- Return type:
complex or numpy array
- classmethod get_refraction_index_external_dabax(photon_energy_ev=10000.0, material='SiC', density=3.217, dabax=None)[source]
Standalone method to return the complex refraction index using DABAX.
- Parameters:
photon_energy_ev (float or numpy array) – The photon energy or array of energies in eV.
material (str, optional) – The symbol/formula of the material.
density (float, optional) – The material density in g/cm3.
dabax (None or DabaxXraylib, optional) – The pointer to the DabaxXraylib instance (default: None, it uses DabaxXraylib()).
- Returns:
The array with complex refraction index.
- Return type:
float or numpy array
- classmethod get_refraction_index_external_xraylib(photon_energy_ev=10000.0, material='SiC', density=3.217)[source]
Standalone method to return the complex refraction index using xraylib.
- Parameters:
photon_energy_ev (float or numpy array) – The photon energy or array of energies in eV.
material (str, optional) – The symbol/formula of the material.
density (float, optional) – The material density in g/cm3.
- Returns:
The array with complex refraction index.
- Return type:
float or numpy array
- classmethod get_refraction_index_real_external_dabax(photon_energy_ev=10000.0, material='SiC', density=3.217, dabax=None)[source]
Standalone method to return the complex refraction index using DABAX.
- Parameters:
photon_energy_ev (float or numpy array) – The photon energy or array of energies in eV.
material (str, optional) – The symbol/formula of the material.
density (float, oprional) – The material density in g/cm3.
dabax (None or DabaxXraylib, optional) – The pointer to the DabaxXraylib instance (default: None, it uses DabaxXraylib()).
- Returns:
The array with the real part of the refraction index.
- Return type:
float or numpy array
- classmethod get_refraction_index_real_external_xraylib(photon_energy_ev=10000.0, material='SiC', density=3.217)[source]
Standalone method to return the real part of the refraction index using xraylib.
- Parameters:
photon_energy_ev (float or numpy array) – The photon energy or array of energies in eV.
material (str, optional) – The symbol/formula of the material.
density (float, optional) – The material density in g/cm3.
- Returns:
The array with the real part of refraction index.
- Return type:
float or numpy array
- classmethod prerefl(interactive=True, SYMBOL='SiC', DENSITY=3.217, FILE='prerefl.dat', E_MIN=100.0, E_MAX=20000.0, E_STEP=100.0, materials_library=None)[source]
Creates an instance of PreRefl with parameters initialized from the keyword parameters and the prerefl preprocessor file. It uses xraylib for accessing the optical constants.
- Parameters:
interactive (bool, optional) – Set True for running interactively in the terminal and answer the questions (like in shadow2).
SYMBOL (str, optional) – The material symbol/formula.
DENSITY (float, optional) – The density of the material in g/cm3.
FILE (str, optional) – The file name (output) for the prerefl preprocessor file.
E_MIN (float, optional) – The minimum photon energy in eV (for creating the tabulated refraction index).
E_MAX (float, optional) – The maximum photon energy in eV (for creating the tabulated refraction index).
E_STEP (float optional) – The photon energy step in eV.
- Return type:
instance of PreRefl
- classmethod prerefl_cxro(input_file='https://henke.lbl.gov/tmp/xray8378.dat', output_file='prerefl.dat', E_MIN=None, E_MAX=None, NPOINTS=1000)[source]
Creates an instance of PreRefl with parameters initialized from the keyword parameters and a file with energy, alpha and beta created by the CXRO web site https://henke.lbl.gov/optical_constants/getdb2.html
When running the cxro site, request a “text file” and copy the link below “If your file does not appear, click here.”
- Parameters:
input_file (str, optional) – The URL from where the data is downloaded.
output_file (str, optional) – The file name (output) for the prerefl preprocessor file.
E_MIN (float, optional) – The minimum photon energy in eV (for creating the tabulated refraction index).
E_MAX (float, optional) – The maximum photon energy in eV (for creating the tabulated refraction index).
NPOINTS (int optional) – The number of points for the photon energy array.
- Return type:
instance of PreRefl
- classmethod prerefl_refractiveindexinfo(shelf='main', book='SiO2', page='Franta', output_file='prerefl.dat', WAVELENGTH_MIN=1e-07, WAVELENGTH_MAX=5e-07, NPOINTS=1000, density=2.2, use_absorption=1, invert_refraction_index=0)[source]
Creates an instance of PreRefl with parameters initialized from the keyword parameters and data from https://refractiveindex.info/ .
- Parameters:
output_file (str, optional) – The file name (output) for the prerefl preprocessor file.
WAVELENGTH_MIN (float, optional) – The minimum value for the wavelength in m.
WAVELENGTH_MAX (float, optional) – The maximum value for the wavelength in m.
NPOINTS (int, optional) – The number of points.
density (float, optional) – The density in g/cm^3.
use_absorption (int, optional) – Set to zero for using zero absorption (zero imaginary part of refraction index).
invert_refraction_index (int, optional) – Set to 1 to invert the refraction index (to be used for example, for total internal reflection)
- Return type:
instance of PreRefl
References
- read_preprocessor_file(filename)[source]
Reads a preprocessor (prerefl) file. The same as in shadow3.
- Parameters:
filename (str) – The name of the filename.
- reflectivity_amplitudes_fresnel(photon_energy_ev=10000.0, grazing_angle_mrad=3.0, roughness_rms_A=0.0, method=0)[source]
Calculates the reflectivity (amplitude) of an interface using Fresnel formulas.
- Parameters:
photon_energy_ev (float or numpy array) – The photon energy in eV.
grazing_angle_mrad (float or numpy array) – The grazing incident angle in mrad.
roughness_rms_A (float or numpy array) – The rouughness RMS in Angstroms,
method (int, optional) – 0=Born&Wolf, 1=Parratt, 2=shadow3 (avoid using 0 or 1, experimental!!)
- Returns:
(rs, rp, runp) the s-polarized, p-pol and unpolarized reflectivities
- Return type:
tuple
- classmethod reflectivity_amplitudes_fresnel_external(photon_energy_ev=10000.0, refraction_index_1=1.0, refraction_index_2=1.0, grazing_angle_mrad=3.0, roughness_rms_A=0.0, method=0)[source]
- Standalone method to calculate the complex Fresnel reflectivity amplitudes
(r_s, r_p) of a single interface using different formulations.
This routine supports three different implementations that correspond to different physical approximations and historical usages.
Exact solution of Maxwell boundary conditions at a planar interface.
- Uses Snell’s law:
n1 sin(theta1) = n2 sin(theta2)
Fresnel amplitudes:
- r_s = (n1 cos(theta1) - n2 cos(theta2)) /
(n1 cos(theta1) + n2 cos(theta2))
- r_p = (n2 cos(theta1) - n1 cos(theta2)) /
(n2 cos(theta1) + n1 cos(theta2))
- Characteristics:
Fully complex
Correct magnitude and phase
Correct Brewster angle behavior
Correct total internal reflection (TIR)
Correct total external reflection (X-rays)
Correct sigma–pi phase difference
- Valid for:
Visible optics
Infrared
X-rays
Polarization studies
Phase-sensitive problems
Interference simulations
Recommended when phase or polarization matters.
Based on the grazing-angle X-ray approximation:
n = 1 - delta + i beta f = sqrt(phi^2 - 2 delta - 2 i beta) r = (f1 - f2) / (f1 + f2)
where phi is the grazing angle (rad).
This corresponds to the small-angle X-ray limit of the s-polarized Fresnel coefficient.
- IMPORTANT:
In the present implementation, r_p is set equal to r_s. Therefore polarization effects are not properly described.
- Characteristics:
Valid for grazing-incidence X-rays
Assumes delta, beta << 1
Assumes small angles (mrad)
Good for reflectivity curves
Suitable for multilayer recursion (Parratt method)
- Limitations:
No Brewster angle
No proper p-polarization behavior
Not valid for visible optics
Not valid for moderate angles
Not suitable for polarization phase studies
Derived from grazing-incidence X-ray reflectivity formulas.
Computes reflectivity (intensity) first:
R = |r|^2
Then reconstructs amplitude as:
r ≈ sqrt(R)
This approach was historically sufficient for ray tracing, where only intensities were required.
- Characteristics:
Good reflectivity magnitude for X-ray mirrors
Designed for ray-tracing simulations
Phase is not physically correct
Sigma–pi phase difference not reliable
- Limitations:
Phase information lost
Not suitable for interference
Not suitable for polarization studies
Not valid for visible optics
Use method=0 (Born & Wolf) whenever phase or polarization matters.
Use method=1 for grazing-incidence X-ray reflectivity curves.
Use method=2 only for intensity-based ray-tracing applications.
- photon_energy_evfloat or numpy array
Photon energy in eV (used only for Debye-Waller factor).
- grazing_angle_mradfloat or numpy array
Grazing incident angle in mrad (angle from surface).
- roughness_rms_Afloat
Surface roughness RMS in Angstrom.
- methodint
0 = Born & Wolf [1]_ (full Fresnel, recommended) 1 = Parratt grazing approximation [2]_ (X-rays) 2 = Shadow3 reflectivity approximation [3] (intensity-based)
- refraction_index_1complex
Refractive index of medium 1 (incident medium).
- refraction_index_2complex
Refractive index of medium 2 (transmitted medium).
- tuple
(r_s, r_p) complex amplitude reflectivities including optional Debye-Waller roughness factor.
[1] Born and Wolf “Principles of Optics” 6th edition, pag 40, eqs 21.
[2] Parratt LG (1954) Surface studies of solids by total reflection of X-rays. Phys Rev 95(2):359–369.
[3] Equations implemented in Shadow3.
- classmethod reflectivity_amplitudes_fresnel_external_dabax(photon_energy_ev=10000.0, coating_material='SiC', coating_density=3.217, grazing_angle_mrad=3.0, roughness_rms_A=0.0, method=0, dabax=None)[source]
Standalone method to calculate the reflectivity (amplitude) of an interface using Fresnel formulas using dabax.
- Parameters:
photon_energy_ev (float or numpy array) – The photon energy in eV.
grazing_angle_mrad (float or numpy array) – The grazing incident angle in mrad.
roughness_rms_A (float or numpy array) – The rouughness RMS in Angstroms,
method (int, optional) – 0=Born&Wolf, 1=Parratt, 2=shadow3 (avoid using 0 or 1, experimental!!)
dabax (None or instance of DabaxXraylib) – A pointer to the dabax library. Use None for default.
coating_material (int, optional) – The symbol/formula of the coating material.
coating_density (int, optional) – The density in g/cm3 of the coating material.
- Returns:
(rs, rp, runp) the s-polarized, p-pol and unpolarized reflectivities
- Return type:
tuple
- classmethod reflectivity_amplitudes_fresnel_external_xraylib(photon_energy_ev=10000.0, coating_material='SiC', coating_density=3.217, grazing_angle_mrad=3.0, roughness_rms_A=0.0, method=0)[source]
Standalone method to calculate the reflectivity (amplitude) of an interface using Fresnel formulas using xraylib.
- Parameters:
photon_energy_ev (float or numpy array) – The photon energy in eV.
grazing_angle_mrad (float or numpy array) – The grazing incident angle in mrad.
roughness_rms_A (float or numpy array) – The rouughness RMS in Angstroms,
method (int, optional) – 0=Born&Wolf, 1=Parratt, 2=shadow3 (avoid using 0 or 1, experimental!!)
coating_material (int, optional) – The symbol/formula of the coating material.
coating_density (int, optional) – The density in g/cm3 of the coating material.
- Returns:
(rs, rp, runp) the s-polarized, p-pol and unpolarized reflectivities
- Return type:
tuple
- reflectivity_fresnel(photon_energy_ev=10000.0, grazing_angle_mrad=3.0, roughness_rms_A=0.0, method=2)[source]
Calculates the reflectivity (intensity) of an interface using Fresnel formulas.
- Parameters:
photon_energy_ev (float or numpy array) – The photon energy in eV.
grazing_angle_mrad (float or numpy array) – The grazing incident angle in mrad.
roughness_rms_A (float or numpy array) – The rouughness RMS in Angstroms,
method (int, optional) – 0=Born&Wolf, 1=Parratt, 2=shadow3 (avoid using 0 or 1, experimental!!)
- Returns:
(rs, rp, runp) the s-polarized, p-pol and unpolarized reflectivities
- Return type:
tuple