Beryllium Lens Calculations
This module contains multiple calculations to assist adjusting the Be Lenses to focus the beam.
Here is a quick example of how you would get started with this module.
>>> from pcdscalc import be_lens_calcs as be
Configure the defaults used for calculations:
>>> be.configure_defaults(distance=3.852, fwhm_unfocused=800e-6)
>>> be.DISTANCE
3.852
>>> be.FWHM_UNFOCUSED
0.0008
Note
The following defaults will be used if not configured with pcdscalc.be_lens_calcs.configure_defaults()
function:
# full width at half maximum unfocused
FWHM_UNFOCUSED = 500e-6
# Disk Thickness
DISK_THICKNESS = 1.0e-3
# Apex of the lens
APEX_DISTANCE = 30e-6
# Distance from the lenses to the sample
DISTANCE = 4.0
# Atomic symbol for element
MATERIAL = 'Be'
# Set of Be lenses with thicknesses:
LENS_RADII = [50e-6, 100e-6, 200e-6, 300e-6, 500e-6, 1000e-6, 1500e-6, 2000e-6, 3000e-6]
Configure the path to the lens_set file that will be used in multiple calculations:
>>> be.configure_lens_set_file('/path/for/current/be_lens_file')
Store sets in the be_lens_file:
>>> sets_list = [[3, 0.0001, 1, 0.0002],
[1, 0.0001, 1, 0.0003],
[2, 0.0001, 1, 0.0005]]
>>> set_lens_set_to_file(sets_list)
Get the first set that was stored in the be_lens_file:
>>> be.get_lens_set(1)
[3, 0.0001, 1, 0.0002]
Get the whole stack of lens sets from the be_lens_file:
>>> be.get_lens_set(None, get_all=True)
[[3, 0.0001, 1, 0.0002],
[1, 0.0001, 1, 0.0003, 1, 0.0005],
[2, 0.0001, 1, 0.0005]]
Note
The Be lens holders can take 3 different sets that could be set before experiments so that only the relevant beamline section is vented once. These sets can be stored in a file with the pcdscalc.be_lens_cals.set_lens_set_to_file()
function, and they can be accessed in other calculations with pcsdcalc.be_lens_cals.get_lens_set()
. The file containing the lens sets could be then saved to a specific experiment so users know which stack was used for the beamtime.
For more examples please look at each individual function’s Example section.
Module for Beryllium Lens Calculations.
- pcdscalc.be_lens_calcs.calc_beam_fwhm(energy, lens_set, distance=None, source_distance=None, prefocus_set=None, prefocus_distance=27, material=None, density=None, fwhm_unfocused=None, printsummary=True)[source]
Calculate beam Full Width at the Half Maximum.
Calculate beam parameters for certain lenses configuration and energy at a given distance. FWHM - Full Width at the Half Maximum Optionally some other parameters can be set.
- Parameters:
- energynumber
Beam Energy in KeV
- lens_setlist
[numer1, lensthick1, number2, lensthick2…]
- distancefloat
Distance from the lenses to the sample is 3.852 m at XPP. (in meters)
- source_distancefloat, optional
Distance from source to lenses. This is about 160 m at XPP. (in meters)
- prefocus_set: list, optional
[numer1, lensthick1, number2, lensthick2…]
- prefocus_distance: float
distance from prefocusing lenses to hutch lenses. 27 m for XCS.
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- densityfloat, optional
Material density in g/cm^3
- fwhm_unfocusedfloat, optional
This is about 400 microns at XPP. This is about 900 microns at MEC. Radial size of x-ray beam before focusing in meters.
- printsummarybool, optional
Prints summary of parameters/calculations if True.
- Returns:
- size_fwhmfloat
Beam Full Width at the Half Maximum in meters.
Examples
>>> calc_beam_fwhm(energy=9, lens_set=[2, 0.03, 4, 0.002], distance=4, material='Be', fwhm_unfocused=800e-6) 0.0008373516816325981
- pcdscalc.be_lens_calcs.calc_distance_for_size(size_fwhm, lens_set, energy, fwhm_unfocused=None)[source]
Calculate the distance for size.
- Parameters:
- size_fwhmfloat
Beam Full Width at the Half Maximum in meters.
- lens_setlist
[numer1, lensthick1, number2, lensthick2…]
- energynumber
Beam Energy in KeV
- fwhm_unfocusedfloat, optional
This is about 400 microns at XPP. Radial size of x-ray beam before focusing in meters.
- Returns:
- distancefloat
Distance in meters
Examples
>>> calc_distance_for_size(0.023, [2, 0.03, 4, 0.002], 8, 0.078) array([32.00383702, 58.77068253])
- pcdscalc.be_lens_calcs.calc_focal_length(energy, lens_set, material=None, density=None)[source]
Calculate the Focal Length for certain lenses configuration and energy.
- Parameters:
- energynumber
Beam Energy in KeV
- lens_setlist
[numer1, lensthick1, number2, lensthick2 …]
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- densityfloat, optional
Material density in g/cm^3
- Returns:
- focal_lengthfloat
Examples
>>> calc_focal_length(8, [1, 0.3, 2, 0.4], 'Be') 11256.040424758363
- pcdscalc.be_lens_calcs.calc_focal_length_for_single_lens(energy, radius, material=None, density=None)[source]
Calculate the Focal Length for a single lens.
- Parameters:
- energynumber
Beam Energy in in KeV
- radiusfloat
Radius of curvature (in meters)
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- densityfloat, optional
Material density in g/cm^3
- Returns:
- focal_lengthfloat
The focal length for a single lens
Examples
>>> calc_focal_length_for_single_lens(8, 0.03, 'Be') 2814.0101061895903
- pcdscalc.be_lens_calcs.calc_lens_aperture_radius(radius, disk_thickness=None, apex_distance=None)[source]
Calculate the lens aperture radius.
It is of importance to optimize which lens radius to use at a specific photon energy.
- Parameters:
- radiusfloat
- disk_thicknessfloat, optional
Disk Thickness in meters. Defaults to 1.0e-3.
- apex_distancefloat, optional
Apex Distance in meters. Defaults to 30e-6
- Returns:
- aperture_radiusfloat
Examples
>>> calc_lens_aperture_radius(radius=4.0, disk_thickness=1e-3, apex_distance=30e-6) 0.06228964600958975
- pcdscalc.be_lens_calcs.calc_lens_set(energy, size_fwhm, distance, n_max=25, max_each=5, lens_radii=None, fwhm_unfocused=None, eff_rad0=None)[source]
Calculate lens set.
- Parameters:
- energynumber
Beam Energy in KeV
- size_fwhmfloat
Beam Full Width at the Half Maximum. (in meters)
- distancefloat
Distance from the lenses to the sample. (in meters)
- n_maxint, optional
Number of lenses.
- max_eachint, optional
- lens_radiilist, optional
[numer1, lensthick1, number2, lensthick2…]
- fwhm_unfocusedfloat, optional
This is about 400 microns at XPP. Defaults to 500e-6. Radial size of x-ray beam before focusing in meters.
- eff_rad0float, optional
- Returns:
- lens_setstuple
Lens sets
Examples
>>> calc_lens_set(energy=7, size_fwhm=0.54, distance=3)
- pcdscalc.be_lens_calcs.calc_trans_for_single_lens(energy, radius, material=None, density=None, fwhm_unfocused=None, disk_thickness=None, apex_distance=None)[source]
Calculate the transmission for a single lens.
- Parameters:
- energynumber
Beam Energy in KeV
- radiusfloat
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- densityfloat, optional
Material density in g/cm^3
- fwhm_unfocusedfloat, optional
This is about 400 microns at XPP. Radial size of x-ray beam before focusing in meters.
- disk_thicknessfloat, optional
Disk Thickness in meters. Defaults to 1.0e-3.
- apex_distancefloat, optional
Apex Distance in meters. Defaults to 30e-6.
- Returns:
- transmissionfloat
Transmission for a single lens
Examples
>>> calc_trans_for_single_lens(energy=8, radius=0.03, material='Be', density=None, fwhm_unfocused=800e-6, disk_thickness=1.0e-3, apex_distance=30e-6) 0.9921954096643786
- pcdscalc.be_lens_calcs.calc_trans_lens_set(energy, lens_set, material=None, density=None, fwhm_unfocused=None, disk_thickness=None, apex_distance=None)[source]
Calculate the transmission of a lens set.
These would allow us to estimate the total transmission of the lenses.
- Parameters:
- energynumber
Beam Energy in KeV
- lens_setlist
[numer1, lensthick1, number2, lensthick2…]
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- densityfloat, optional
Material density in g/cm^3
- fwhm_unfocusedfloat, optional
This is about 400 microns at XPP. Default = 900e-6 Radial size of x-ray beam before focusing in meters.
- disk_thicknessfloat, optional
Disk Thickness in meters. Defaults to 1.0e-3.
- apex_distancefloat, optional
Apex Distance in meters. Defaults to 30e-6.
- Returns:
- transmissionfloat
Transmission for a set of lens
Examples
>>> calc_trans_lens_set(energy=8, lens_set=[1, 0.03, 4, 0.02], material='Be', density=None, fwhm_unfocused=400e-6) 0.955752311215339
- pcdscalc.be_lens_calcs.configure_defaults(fwhm_unfocused=None, disk_thickness=None, apex_distance=None, distance=None, material=None, lens_radii=None)[source]
Configure defaults.
- Parameters:
- fwhm_unfocusedfloat, optional
Full width at half maximum unfocused in meters.
- disk_thicknessfloat, optional
Disk thickness in meters.
- apex_distancefloat, optional
Apex Distance in meters.
- distancefloat, optional
Distance from the lenses to the sample in meters.
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- lens_radiilist
Set of Be lenses with thicknesses in meters.
Examples
>>> configure_defaults(distance=3.852)
- pcdscalc.be_lens_calcs.configure_lens_set_file(lens_file_path)[source]
Configure the path to the lens set file.
- Parameters:
- lens_file_pathstr
Path to the lens_set file.
- pcdscalc.be_lens_calcs.find_energy(lens_set, distance=None, material=None, density=None)[source]
Find the energy that would focus at a given distance.
- Parameters:
- lens_setlist
[numer1, lensthick1, number2, lensthick2…]
- distancefloat, optional
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- densityfloat, optional
Material density in g/cm^3
- Returns:
- energyfloat
Energy
Examples
>>> find_energy([2, 200e-6, 4, 500e-6], distance=4) 7.0100555419921875
- pcdscalc.be_lens_calcs.find_radius(energy, distance=None, material=None, density=None)[source]
Find the radius of curvature.
Find the radius of curvature of the lens that would focus the energy at the distance.
- Parameters:
- energynumber
Beam Energy
- distancefloat, optional
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- densityfloat, optional
Material density in g/cm^3
- Returns:
- radiusfloat
Radius of curvature in meters.
Examples
>>> find_radius(energy=8, distance=4.0, material='Be', density=None) 4.2643770090253954e-05
- pcdscalc.be_lens_calcs.find_z_pos(energy, lens_set, spot_size_fwhm, material=None, density=None, fwhm_unfocused=None)[source]
Find the Be Lens distances.
Find the two distances the Be lens needs to be at to get the spotsize in the chamber center.
- Parameters:
- energynumber
Beam Energy in KeV
- lens_setlist
[numer1, lensthick1, number2, lensthick2…]
- spot_size_fwhm
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- densityfloat, optional
Material density in g/cm^3
- fwhm_unfocusedfloat, optional
This is about 400 microns at XPP. Defaults to 500e-6 Radial size of x-ray beam before focusing in meters.
- Returns:
- z_positiontuple
(z1, z2)
Examples
>>> lens_set = [2, 200e-6, 4, 500e-6] >>> find_z_pos(energy=8, lens_set=lens_set, spot_size_fwhm=0.09, material='Be', density=None, fwhm_unfocused=800e-6) (-2339.797291538794, 2350.2195511913483)
- pcdscalc.be_lens_calcs.gaussian_fwhm_to_sigma(fwhm)[source]
Convert between FWHM and sigma of a Gaussian function.
sigma = FWHM / 2.35482004503
https://brainder.org/2011/08/20/gaussian-kernels-convert-fwhm-to-sigma/
- Parameters:
- fwhmfloat
Full Width at the Half Maximum.
- Returns:
- sigma
Examples
>>> gaussian_fwhm_to_sigma(0.023) 0.009767200703316157
- pcdscalc.be_lens_calcs.gaussian_sigma_to_fwhm(sigma)[source]
Convert between FWHM and sigma of a Gaussian function.
FWHM = 2.35482004503 * sigma
https://brainder.org/2011/08/20/gaussian-kernels-convert-fwhm-to-sigma/
- Parameters:
- sigmafloat
- Returns:
- FWHM - Full Width at the Half Maximum
Examples
>>> gaussian_sigma_to_fwhm(0.3) 0.7064460135089999
- pcdscalc.be_lens_calcs.get_att_len(energy, material=None, density=None)[source]
Get the attenuation length (in meter) of a material.
The X-ray beam intensity I(x) at depth x in a material is a function of the attenuation coefficient mu, and can be calculated by the Beer-Lambert law. The Absorption Length (or Attenuation Length) is defined as the distance into a material where the x-ray beam intensity has decreased to a value of 1/e (~ 40%) of the incident beam intensity (Io).
(1/e) = e^(-mu * x) ln(1/e) = ln(e^(-mu * x)) 1 = mu * x x = 1/mu
- Parameters:
- energynumber
Beam Energy given in KeV
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’
- densityfloat, optional
Material density in g/cm^3
- Returns:
- att_lenfloat
Attenuation length (in meters)
- Raises:
- ValueError
If an invalid symbol is provided for material.
Examples
>>> get_att_len(energy=8, material='Be') 0.004810113254120656
- pcdscalc.be_lens_calcs.get_delta(energy, material=None, density=None)[source]
Calculate delta for a given material at a given energy.
Anomalous components of the index of refraction for a material, using the tabulated scattering components from Chantler.
- Parameters:
- energynumber
x-ray energy in KeV
- materialstr, optional
Atomic symbol for element, defaults to ‘Be’.
- densityfloat, optional
Material density in g/cm^3
- Returns:
- deltafloat
Real part of index of refraction
- Raises:
- ValueError
If an invalid symbol is provided for material.
- ZeroDivisionError
When energy is 0.
Examples
>>> get_delta(energy=8, material='Au') 4.728879989419882e-05
- pcdscalc.be_lens_calcs.get_lens_set(set_number_top_to_bot, filename=None, get_all=False)[source]
Get the lens set from the file provided.
- Parameters:
- set_number_top_to_botint
The Be lens holders can take 3 different sets that we usually set before experiments, this is to specify what number set.
- filenamestr, optional
File path of the lens_set file.
- get_allbool
Indicates if it should return the entire stack of lens.
- Returns:
- lens_setlist
[numer1, lensthick1, number2, lensthick2 …]
- pcdscalc.be_lens_calcs.lens_transmission(radius, fwhm, energy, num=1, id_material='IF1', lens_thicknes=None)[source]
Find the CRL (Compound Refractive Lens) transmission.
- Parameters:
- radiusfloat
Effective radius of curvature in meters
- fwhmfloat
Incident beam size on the lens in meters
- numint
Number of lenses in the stack
- energynumber
Photon energy in KeV
- id_materialstr
Lens material, Defaults to IF1
- lens_thicknessfloat
Lens thickness in meters
- Returns:
- transfloat
Lens Transmission
- pcdscalc.be_lens_calcs.photon_to_wavelength(energy)[source]
Find the wavelength in micrometers.
Use photon energy in electronvolts. The equation is approximately: λ[µm] = 1.2398 / E[eV]. The photon energy at 1 μm wavelength, the wavelength of near infrared radiation, is approximately 1.2398 eV.
- Parameters:
- energynumber
Photon energy in electronvolts
- Returns:
- Wavelength in micrometers
Examples
>>> photon_to_wavelength(8) 0.154975
- pcdscalc.be_lens_calcs.plan_set(energy, z_offset, z_range, beam_size_unfocused, size_horizontal, size_vertical=None, exclude=None, max_tot_number_of_lenses=25, max_each=5, focus_before_sample=False)[source]
Macro to help plan for what lens set to use.
- Parameters:
- energynumber
Beam energy in KeV
- z_offsetfloat
Distance from sample to lens_z=0 in meters
- z_rangelist
Array or tuple of 2 values: minimum and maximum z pos in meters
- beam_size_unfocusedfloat
Radial size of x-ray beam before focusing in meters
- size_horizontalarray-like
- size_verticalNone, int or tuple of ints, optional
- excludelist
List with excluded sets of lenses
- max_tot_number_of_lensesint
Number of lenses.
- max_eachint
- focus_before_samplebool
Notes
When providing a large number to max_tot_number_of_lenses, it will take some time to run the calculations, for example: max_tot_number_of_lenses=25 will take ~ 2 min
Examples
>>> plan_set(energy=1, z_offset=-10, z_range=[1, 40], beam_size_unfocused=3, size_horizontal=9, size_vertical=None, exclude=[], max_tot_number_of_lenses=1, max_each=5, focus_before_sample=False)
N foc_len/m Min/um Max/um Trans/% Set 0 0.07 466994229.0 2112064677.4 0.0 1 x 50um 1 0.14 234997114.5 1057532338.7 0.0 1 x 100um 2 0.28 118998557.3 530266169.4 0.0 1 x 200um 3 0.43 80332371.5 354510779.6 0.0 1 x 300um 4 0.71 49399422.9 213906467.7 0.0 1 x 500um 5 1.42 26199711.5 108453233.9 0.0 1 x 1000um 6 2.13 18466474.3 73302155.9 0.0 1 x 1500um 7 2.84 14599855.7 55726616.9 0.0 1 x 2000um 8 4.27 10733237.2 38151078.0 0.0 1 x 3000um
Where: foc_len - is the focal length in um Min - Beam full width at half maximum for minimum z position Max - Beam full width at half maximum for maximum z position Trans - is the lens transmission in %.
- pcdscalc.be_lens_calcs.set_lens_set_to_file(list_of_sets, filename=None, make_backup=True)[source]
Write lens set to a file.
The Be lens holders can take 3 different sets that we usually set before few experiments so we only vent the relevant beamline section once. We then store these sets into a config file that we can call from some methods. Later, we save this config file to the specific experiment so users can make sure that they know which stack was used for there beamtime.
- Parameters:
- list_of_setslist
List of lists with lens sets.
- filenamestr, optional
Path to the filename to set the lens sets list to. This should be a .npy format file.
- make_backupbool, optional
To indicate if a backup file should be created or not. Defaults to True.
Examples
>>> list_of_sets = [[3, 0.0001, 1, 0.0002], [1, 0.0001, 1, 0.0003, 1, 0.0005], [2, 0.0001, 1, 0.0005]] >>> set_lens_set_to_file(list_of_sets, '../path/to/lens_set')