wpg.srwlib module

class wpg.srwlib.SRWLGsnBm(_x=0, _y=0, _z=0, _xp=0, _yp=0, _avgPhotEn=1, _pulseEn=1, _repRate=1, _polar=1, _sigX=1e-05, _sigY=1e-05, _sigT=1e-15, _mx=0, _my=0)[source]

Bases: object

Gaussian Beam

Parameters:
  • _x – average horizontal coordinates of waist [m]
  • _y – average vertical coordinates of waist [m]
  • _z – average longitudinal coordinate of waist [m]
  • _xp – average horizontal angle at waist [rad]
  • _yp – average verical angle at waist [rad]
  • _avgPhotEn – average photon energy [eV]
  • _pulseEn – energy per pulse [J]
  • _repRate – rep. rate [Hz]
  • _polar – polarization 1- lin. hor., 2- lin. vert., 3- lin. 45 deg., 4- lin.135 deg., 5- circ. right, 6- circ. left
  • _sigX – rms beam size vs horizontal position [m] at waist (for intensity)
  • _sigY – rms beam size vs vertical position [m] at waist (for intensity)
  • _sigT – rms pulse duration [s] (for intensity)
  • _mx – transverse Gauss-Hermite mode order in horizontal direction
  • _my – transverse Gauss-Hermite mode order in vertical direction
class wpg.srwlib.SRWLKickM(_arKickMx=None, _arKickMy=None, _order=2, _nx=0, _ny=0, _nz=0, _rx=0, _ry=0, _rz=0, _x=0, _y=0, _z=0)[source]

Bases: object

Kick Matrix (for fast trajectory calculation)

Parameters:
  • _arKickMx – horizontal kick-matrix (tabulated on the same transverse grid vs x and y as vertical kick-matrix)
  • _arKickMy – vertical kick-matrix (tabulated on the same transverse grid vs x and y as horizontal kick-matrix)
  • _order – kick order: 1- first order (in this case kick matrix data is assumed to be in [T*m]), 2- second order (kick matrix data is assumed to be in [T^2*m^2])
  • _nx – numbers of points in kick matrices in horizontal direction
  • _ny – numbers of points in kick matrices in vertical direction
  • _nz – number of steps in longitudinal direction
  • _rx – range covered by kick matrices in horizontal direction [m]
  • _ry – range covered by kick matrices in vertical direction [m]
  • _rz – extension in longitudinal direction [m]
  • _x – horizontal coordinate of center point [m]
  • _y – vertical coordinate of center point [m]
  • _z – longitudinal coordinate of center point [m]
class wpg.srwlib.SRWLMagFld[source]

Bases: object

Magnetic Field (base class)

class wpg.srwlib.SRWLMagFld3D(_arBx=None, _arBy=None, _arBz=None, _nx=0, _ny=0, _nz=0, _rx=0, _ry=0, _rz=0, _nRep=1, _interp=1, _arX=None, _arY=None, _arZ=None)[source]

Bases: wpg.srwlib.SRWLMagFld

Magnetic Field: Arbitrary 3D

Parameters:
  • _arBx – horizontal magnetic field component array [T]
  • _arBy – vertical magnetic field component array [T]
  • _arBz – longitudinal magnetic field component array [T]
  • _nx – number of magnetic field data points in the horizontal direction
  • _ny – number of magnetic field data points in the vertical direction
  • _nz – number of magnetic field data points in the longitudinal direction
  • _rx – range of horizontal coordinate for which the field is defined [m]
  • _ry – range of vertical coordinate for which the field is defined [m]
  • _rz – range of longitudinal coordinate for which the field is defined [m]
  • _nRep – “number of periods”, i.e. number of times the field is “repeated” in the longitudinal direction
  • _interp – interpolation method to use (e.g. for trajectory calculation), 1- bi-linear (3D), 2- (bi-)quadratic (3D), 3- (bi-)cubic (3D)
  • _arX – optional array of horizontal transverse coordinate of an irregular 3D mesh (if this array is defined, rx will be ignored)
  • _arY – optional array of vertical transverse coordinate of an irregular 3D mesh (if this array is defined, ry will be ignored)
  • _arZ – optional array of longitudinal coordinate of an irregular 3D mesh (if this array is defined, rz will be ignored)
add_const(_bx=0, _by=0, _bz=0)[source]

Adds constant magnetic field to the entire tabulated field (to simulate e.g. background magnetic field effects) :param _bx: horizontal magnetic field component to add [T] :param _by: vertical magnetic field component to add [T] :param _bz: longitudinal magnetic field component to add [T]

save_ascii(_file_path, _xc=0, _yc=0, _zc=0)[source]

Auxiliary function to write tabulated Arbitrary 3D Magnetic Field data to ASCII file

class wpg.srwlib.SRWLMagFldC(_arMagFld=None, _arXc=None, _arYc=None, _arZc=None, _arVx=None, _arVy=None, _arVz=None, _arAng=None)[source]

Bases: wpg.srwlib.SRWLMagFld

Magnetic Field: Container

Parameters:
  • _arMagFld – magnetic field structures array
  • _arXc – horizontal center positions of magnetic field elements in arMagFld array [m]
  • _arYc – vertical center positions of magnetic field elements in arMagFld array [m]
  • _arZc – longitudinal center positions of magnetic field elements in arMagFld array [m]
  • _arVx – horizontal components of axis vectors of magnetic field elements in arMagFld array [rad]
  • _arVy – vertical components of axis vectors of magnetic field elements in arMagFld array [rad]
  • _arVz – longitudinal components of axis vectors of magnetic field elements in arMagFld array [rad]
  • _arAng – rotation angles of magnetic field elements about their axes [rad]
add(_mag, _xc=None, _yc=None, _zc=None, _vx=None, _vy=None, _vz=None, _ang=None)[source]

Adds magnetic element to container :param _mag: magnetic element (or array of elements) to be added :param _xc: horizontal center position (or array of center positions) of magnetic field element to be added [m] :param _yc: vertical center positions (or array of center positions) of magnetic field element to be added [m] :param _zc: longitudinal center positions (or array of center positions) of magnetic field element to be added [m] :param _vx: horizontal component of axis vectors of magnetic field element to be added [rad] :param _vy: vertical component of axis vectors of magnetic field element to be added [rad] :param _vz: longitudinal components of axis vector of magnetic field element to be added [rad] :param _ang: rotation angle about axis [rad]

allocate(_nElem)[source]
class wpg.srwlib.SRWLMagFldH(_n=1, _h_or_v='v', _B=0, _ph=0, _s=1, _a=1)[source]

Bases: wpg.srwlib.SRWLMagFld

Magnetic Field: Undulator Harmonic

Parameters:
  • _n – harmonic number
  • _h_or_v – magnetic field plane horzontal (‘h’) or vertical (‘v’)
  • _B – magnetic field amplitude [T]
  • _ph – initial phase [rad]
  • _s – symmetry vs longitudinal position 1 - symmetric (B ~ cos(2*Pi*n*z/per + ph)) , -1 - anti-symmetric (B ~ sin(2*Pi*n*z/per + ph))
  • _a – coefficient for transverse depenednce B*cosh(2*Pi*n*a*y/per)*cos(2*Pi*n*z/per + ph)
class wpg.srwlib.SRWLMagFldM(_G=0, _m=2, _n_or_s='n', _Leff=0, _Ledge=0, _R=0)[source]

Bases: wpg.srwlib.SRWLMagFld

Magnetic Field: Multipole Magnet

Parameters:
  • _G – field parameter [T] for dipole, [T/m] for quadrupole (negative means defocusing for x), [T/m^2] for sextupole, [T/m^3] for octupole
  • _m – multipole order 1 for dipole, 2 for quadrupoole, 3 for sextupole, 4 for octupole
  • _n_or_s – normal (‘n’) or skew (‘s’)
  • _Leff – effective length [m]
  • _Ledge – “soft” edge length for field variation from 10% to 90% [m]; G/(1 + ((z-zc)/d)^2)^2 fringe field dependence is assumed
  • _R – radius of curvature of central trajectory [m] (for simulating e.g. quadrupole component integrated to a bending magnet; effective if > 0)
class wpg.srwlib.SRWLMagFldS(_B=0, _Leff=0)[source]

Bases: wpg.srwlib.SRWLMagFld

Magnetic Field: Solenoid

Parameters:
  • _B – magnetic field [T]
  • _Leff – effective length [m]
class wpg.srwlib.SRWLMagFldU(_arHarm=None, _per=0, _nPer=0)[source]

Bases: wpg.srwlib.SRWLMagFld

Magnetic Field: Undulator

Parameters:
  • _arHarm – array of field harmonics
  • _per – period length [m]
  • _nPer – number of periods (will be rounded to integer)
E1_2_B(_e1, _en_elec=3.0)[source]

Estimate deflection parameter from :param _e1: fundamental photon energy [eV] :param _en_elec: electron energy [GeV] :return: magnetic field amplitude [T]

E1_2_K(_e1, _en_elec=3.0)[source]

Estimate deflection parameter from :param _e1: fundamental photon energy [eV] :param _en_elec: electron energy [GeV] :return: deflection parameter

allocate(_nHarm)[source]
get_E1(_en_elec=3.0, _unit='eV')[source]

Estimate fundamental photon energy :param _en_elec: electron energy [GeV] :return: fundamental photon energy [eV]

get_K()[source]

Estimate K (deflection parameter) value

set_sin(_per=0.02, _len=1, _bx=0, _by=0, _phx=0, _phy=0, _sx=1, _sy=1)[source]

Setup basic undulator with sinusoidal magnetic field :param _per: period length [m] :param _len: undulator length [m] :param _bx: horizontal magnetic field amplitude [m] :param _by: vertical magnetic field amplitude [m] :param _phx: initial phase of the horizontal magnetic field [rad] :param _phx: initial phase of the vertical magnetic field [rad] :param _sx: symmetry of the horizontal magnetic field vs longitudinal position 1 - symmetric (B ~ cos(2*Pi*n*z/per + ph)) , -1 - anti-symmetric (B ~ sin(2*Pi*n*z/per + ph)) :param _sy: symmetry of the vertical magnetic field vs longitudinal position

class wpg.srwlib.SRWLOpt[source]

Bases: object

Optical Element (base class)

class wpg.srwlib.SRWLOptA(_shape='r', _ap_or_ob='a', _Dx=0, _Dy=0, _x=0, _y=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Aperture / Obstacle

Parameters:
  • _shape – ‘r’ for rectangular, ‘c’ for circular
  • _ap_or_ob – ‘a’ for aperture, ‘o’ for obstacle
  • _Dx – horizontal transverse dimension [m]; in case of circular aperture, only Dx is used for diameter
  • _Dy – vertical transverse dimension [m]; in case of circular aperture, Dy is ignored
  • _x – horizontal transverse coordinate of center [m]
  • _y – vertical transverse coordinate of center [m]
class wpg.srwlib.SRWLOptAng(_ang_x=0, _ang_y=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Angle

Parameters:
  • _ang_x – horizontal angle [rad]
  • _ang_y – vertical angle [rad]
class wpg.srwlib.SRWLOptC(_arOpt=None, _arProp=None)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Container

Parameters:
  • _arOpt – optical element structures list (or array)
  • _arProp – list of lists of propagation parameters to be used for each individual optical element Each element _arProp[i] is a list in which elements mean: [0]: Auto-Resize (1) or not (0) Before propagation [1]: Auto-Resize (1) or not (0) After propagation [2]: Relative Precision for propagation with Auto-Resizing (1. is nominal) [3]: Allow (1) or not (0) for semi-analytical treatment of the quadratic (leading) phase terms at the propagation [4]: Do any Resizing on Fourier side, using FFT, (1) or not (0) [5]: Horizontal Range modification factor at Resizing (1. means no modification) [6]: Horizontal Resolution modification factor at Resizing (1. means no modification) [7]: Vertical Range modification factor at Resizing (1. means no modification) [8]: Vertical Resolution modification factor at Resizing (1. means no modification) [9]: Optional: Type of wavefront Shift before Resizing (vs which coordinates; to be implemented) [10]: Optional: New Horizontal wavefront Center position after Shift (to be implemented) [11]: Optional: New Vertical wavefront Center position after Shift (to be implemented) [12]: Optional: Orientation of the Output Optical Axis vector in the Incident Beam Frame: Horizontal Coordinate [13]: Optional: Orientation of the Output Optical Axis vector in the Incident Beam Frame: Vertical Coordinate [14]: Optional: Orientation of the Output Optical Axis vector in the Incident Beam Frame: Longitudinal Coordinate [15]: Optional: Orientation of the Horizontal Base vector of the Output Frame in the Incident Beam Frame: Horizontal Coordinate [16]: Optional: Orientation of the Horizontal Base vector of the Output Frame in the Incident Beam Frame: Vertical Coordinate
allocate(_nElem)[source]
class wpg.srwlib.SRWLOptCryst(_d_sp, _psi0r, _psi0i, _psi_hr, _psi_hi, _psi_hbr, _psi_hbi, _tc, _ang_as, _nvx=0, _nvy=0, _nvz=-1, _tvx=1, _tvy=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Ideal Crystal

Parameters:
  • _d_sp – (_d_space) crystal reflecting planes d-spacing (John’s dA) [A]
  • _psi0r – real part of 0-th Fourier component of crystal polarizability (John’s psi0c.real) (units?)
  • _psi0i – imaginary part of 0-th Fourier component of crystal polarizability (John’s psi0c.imag) (units?)
  • _psi_hr – (_psiHr) real part of H-th Fourier component of crystal polarizability (John’s psihc.real) (units?)
  • _psi_hi – (_psiHi) imaginary part of H-th Fourier component of crystal polarizability (John’s psihc.imag) (units?)
  • _psi_hbr – (_psiHBr:) real part of -H-th Fourier component of crystal polarizability (John’s psimhc.real) (units?)
  • _psi_hbi – (_psiHBi:) imaginary part of -H-th Fourier component of crystal polarizability (John’s psimhc.imag) (units?)
  • _tc – crystal thickness [m] (John’s thicum)
  • _ang_as – (_Tasym) asymmetry angle [rad] (John’s alphdg)
  • _nvx – horizontal coordinate of outward normal to crystal surface (John’s angles: thdg, chidg, phidg)
  • _nvy – vertical coordinate of outward normal to crystal surface (John’s angles: thdg, chidg, phidg)
  • _nvz – longitudinal coordinate of outward normal to crystal surface (John’s angles: thdg, chidg, phidg)
  • _tvx – horizontal coordinate of central tangential vector (John’s angles: thdg, chidg, phidg)
  • _tvy – vertical coordinate of central tangential vector (John’s angles: thdg, chidg, phidg)
find_orient(_en, _ang_dif_pl=0)[source]

Finds optimal crystal orientation in the input beam frame (i.e. surface normal and tangential vectors) and the orientation of the output beam frame (i.e. coordinates of the longitudinal and horizontal vectors in the input beam frame) :param _en: photon energy [eV] :param _ang_dif_pl: diffraction plane angle (0 corresponds to the vertical deflection; pi/2 to the horizontal deflection; any value in between is allowed) :return: list of two triplets of vectors:

out[0] is the list of 3 base vectors [tangential, saggitan, normal] defining the crystal orientation out[1] is the list of 3 base vectors [ex, ey, ez] defining orientation of the output beam frame the cartesian coordinates of all these vectors are given in the frame of the input beam
set_orient(_nvx=0, _nvy=0, _nvz=-1, _tvx=1, _tvy=0)[source]

Defines Crystal Orientation in the frame of the Incident Photon beam :param _nvx: horizontal coordinate of normal vector :param _nvy: vertical coordinate of normal vector :param _nvz: longitudinal coordinate of normal vector :param _tvx: horizontal coordinate of tangential vector :param _tvy: vertical coordinate of tangential vector

class wpg.srwlib.SRWLOptD(_L=0, _treat=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Drift Space

Parameters:
  • _L – Length [m]
  • _treat – switch specifying whether the absolute optical path should be taken into account in radiation phase (=1) or not (=0, default)
class wpg.srwlib.SRWLOptG(_mirSub, _m=1, _grDen=100, _grDen1=0, _grDen2=0, _grDen3=0, _grDen4=0, _grAng=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Grating

Parameters:
  • _mirSub – SRWLOptMir (or derived) type object defining substrate of the grating
  • _m – output (diffraction) order
  • _grDen – groove density [lines/mm] (coefficient a0 in the polynomial groove density: a0 + a1*y + a2*y^2 + a3*y^3 + a4*y^4)
  • _grDen1 – groove density polynomial coefficient a1 [lines/mm^2]
  • _grDen2 – groove density polynomial coefficient a2 [lines/mm^3]
  • _grDen3 – groove density polynomial coefficient a3 [lines/mm^4]
  • _grDen4 – groove density polynomial coefficient a4 [lines/mm^5]
  • _grAng – angle between the grove direction and the saggital direction of the substrate [rad] (by default, groves are made along saggital direction (_grAng=0))
class wpg.srwlib.SRWLOptL(_Fx=1e+23, _Fy=1e+23, _x=0, _y=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Thin Lens

Parameters:
  • _Fx – focal length in horizontal plane [m]
  • _Fy – focal length in vertical plane [m]
  • _x – horizontal coordinate of center [m]
  • _y – vertical coordinate of center [m]
class wpg.srwlib.SRWLOptMir[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Mirror (focusing)

set_all(_size_tang=1, _size_sag=1, _ap_shape='r', _sim_meth=2, _npt=100, _nps=100, _treat_in_out=1, _ext_in=0, _ext_out=0, _nvx=0, _nvy=0, _nvz=-1, _tvx=1, _tvy=0, _x=0, _y=0, _refl=1, _n_ph_en=1, _n_ang=1, _n_comp=1, _ph_en_start=1000.0, _ph_en_fin=1000.0, _ph_en_scale_type='lin', _ang_start=0, _ang_fin=0, _ang_scale_type='lin')[source]
Parameters:
  • _size_tang – size in tangential direction [m]
  • _size_sag – size in sagital direction [m]
  • _ap_shape – shape of aperture in local frame (‘r’ for rectangular, ‘e’ for elliptical)
  • _sim_meth – simulation method (1 for “thin” approximation, 2 for “thick” approximation)
  • _treat_in_out – switch specifying how to treat input and output wavefront before and after the main propagation through the optical element: 0- assume that the input wavefront is defined in the plane before the optical element, and the output wavefront is required in a plane just after the element; 1- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; 2- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; however, before the propagation though the optical element, the wavefront should be propagated through a drift back to a plane just before the optical element, then a special propagator will bring the wavefront to a plane at the optical element exit, and after that the wavefront will be propagated through a drift back to the element center;
  • _ext_in – optical element extent on the input side, i.e. distance between the input plane and the optical center (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _ext_out – optical element extent on the output side, i.e. distance between the optical center and the output plane (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _nvx – horizontal coordinate of central normal vector
  • _nvy – vertical coordinate of central normal vector
  • _nvz – longitudinal coordinate of central normal vector
  • _tvx – horizontal coordinate of central tangential vector
  • _tvy – vertical coordinate of central tangential vector
  • _x – horizontal position of mirror center [m]
  • _y – vertical position of mirror center [m]
  • _refl – reflectivity coefficient to set (can be one number or C-aligned flat complex array vs photon energy vs grazing angle vs component (sigma, pi))
  • _n_ph_en – number of photon energy values for which the reflectivity coefficient is specified
  • _n_ang – number of grazing angle values for which the reflectivity coefficient is specified
  • _n_comp – number of electric field components for which the reflectivity coefficient is specified (can be 1 or 2)
  • _ph_en_start – initial photon energy value for which the reflectivity coefficient is specified
  • _ph_en_fin – final photon energy value for which the reflectivity coefficient is specified
  • _ph_en_scale_type – photon energy sampling type (‘lin’ for linear, ‘log’ for logarithmic)
  • _ang_start – initial grazing angle value for which the reflectivity coefficient is specified
  • _ang_fin – final grazing angle value for which the reflectivity coefficient is specified
  • _ang_scale_type – angle sampling type (‘lin’ for linear, ‘log’ for logarithmic)
set_dim_sim_meth(_size_tang=1, _size_sag=1, _ap_shape='r', _sim_meth=2, _npt=500, _nps=500, _treat_in_out=1, _ext_in=0, _ext_out=0)[source]

Sets Mirror Dimensions, Aperture Shape and its simulation method :param _size_tang: size in tangential direction [m] :param _size_sag: size in sagital direction [m] :param _ap_shape: shape of aperture in local frame (‘r’ for rectangular, ‘e’ for elliptical) :param _sim_meth: simulation method (1 for “thin” approximation, 2 for “thick” approximation) :param _npt: number of mesh points to represent mirror in tangential direction (used for “thin” approximation) :param _nps: number of mesh points to represent mirror in sagital direction (used for “thin” approximation) :param _treat_in_out: switch specifying how to treat input and output wavefront before and after the main propagation through the optical element:

0- assume that the input wavefront is defined in the plane before the optical element, and the output wavefront is required in a plane just after the element; 1- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; 2- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; however, before the propagation though the optical element, the wavefront should be propagated through a drift back to a plane just before the optical element, then a special propagator will bring the wavefront to a plane at the optical element exit, and after this the wavefront will be propagated through a drift back to the element center;
Parameters:
  • _ext_in – optical element extent on the input side, i.e. distance between the input plane and the optical center (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _ext_out – optical element extent on the output side, i.e. distance between the optical center and the output plane (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
set_orient(_nvx=0, _nvy=0, _nvz=-1, _tvx=1, _tvy=0, _x=0, _y=0)[source]

Defines Mirror Orientation in the frame of the incident photon beam :param _nvx: horizontal coordinate of central normal vector :param _nvy: vertical coordinate of central normal vector :param _nvz: longitudinal coordinate of central normal vector :param _tvx: horizontal coordinate of central tangential vector :param _tvy: vertical coordinate of central tangential vector :param _x: horizontal position of mirror center [m] :param _y: vertical position of mirror center [m]

set_reflect(_refl=1, _n_ph_en=1, _n_ang=1, _n_comp=1, _ph_en_start=0, _ph_en_fin=0, _ph_en_scale_type='lin', _ang_start=0, _ang_fin=0, _ang_scale_type='lin')[source]

Sets Mirror Reflectivity :param _refl: reflectivity coefficient to set (can be one number or C-aligned flat array complex array vs photon energy vs grazing angle vs component (sigma, pi)) :param _n_ph_en: number of photon energy values for which the reflectivity coefficient is specified :param _n_ang: number of grazing angle values for which the reflectivity coefficient is specified :param _n_comp: number of electric field components for which the reflectivity coefficient is specified (can be 1 or 2) :param _ph_en_start: initial photon energy value for which the reflectivity coefficient is specified :param _ph_en_fin: final photon energy value for which the reflectivity coefficient is specified :param _ph_en_scale_type: photon energy sampling type (‘lin’ for linear, ‘log’ for logarithmic) :param _ang_start: initial grazing angle value for which the reflectivity coefficient is specified :param _ang_fin: final grazing angle value for which the reflectivity coefficient is specified :param _ang_scale_type: angle sampling type (‘lin’ for linear, ‘log’ for logarithmic)

class wpg.srwlib.SRWLOptMirEl(_p=1, _q=1, _ang_graz=0.001, _r_sag=1e+23, _size_tang=1, _size_sag=1, _ap_shape='r', _sim_meth=2, _npt=500, _nps=500, _treat_in_out=1, _ext_in=0, _ext_out=0, _nvx=0, _nvy=0, _nvz=-1, _tvx=1, _tvy=0, _x=0, _y=0, _refl=1, _n_ph_en=1, _n_ang=1, _n_comp=1, _ph_en_start=1000.0, _ph_en_fin=1000.0, _ph_en_scale_type='lin', _ang_start=0, _ang_fin=0, _ang_scale_type='lin')[source]

Bases: wpg.srwlib.SRWLOptMir

Optical Element: Mirror: Ellipsoid

Parameters:
  • _p – distance from first focus (“source”) to mirror center [m]
  • _q – distance from mirror center to second focus (“image”) [m]
  • _ang_graz – grazing angle at mirror center at perfect orientation [rad]
  • _r_sag – sagital radius of curvature at mirror center [m]
  • _size_tang – size in tangential direction [m]
  • _size_sag – size in sagital direction [m]
  • _ap_shape – shape of aperture in local frame (‘r’ for rectangular, ‘e’ for elliptical)
  • _sim_meth – simulation method (1 for “thin” approximation, 2 for “thick” approximation)
  • _npt – number of mesh points to represent mirror in tangential direction (used for “thin” approximation)
  • _nps – number of mesh points to represent mirror in sagital direction (used for “thin” approximation)
  • _treat_in_out – switch specifying how to treat input and output wavefront before and after the main propagation through the optical element: 0- assume that the input wavefront is defined in the plane before the optical element, and the output wavefront is required in a plane just after the element; 1- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; 2- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; however, before the propagation though the optical element, the wavefront should be propagated through a drift back to a plane just before the optical element, then a special propagator will bring the wavefront to a plane at the optical element exit, and after this the wavefront will be propagated through a drift back to the element center;
  • _ext_in – optical element extent on the input side, i.e. distance between the input plane and the optical center (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _ext_out – optical element extent on the output side, i.e. distance between the optical center and the output plane (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _nvx – horizontal coordinate of central normal vector
  • _nvy – vertical coordinate of central normal vector
  • _nvz – longitudinal coordinate of central normal vector
  • _tvx – horizontal coordinate of central tangential vector
  • _tvy – vertical coordinate of central tangential vector
  • _x – horizontal position of mirror center [m]
  • _y – vertical position of mirror center [m]
  • _refl – reflectivity coefficient to set (can be one number or C-aligned flat complex array vs photon energy vs grazing angle vs component (sigma, pi))
  • _n_ph_en – number of photon energy values for which the reflectivity coefficient is specified
  • _n_ang – number of grazing angle values for which the reflectivity coefficient is specified
  • _n_comp – number of electric field components for which the reflectivity coefficient is specified (can be 1 or 2)
  • _ph_en_start – initial photon energy value for which the reflectivity coefficient is specified
  • _ph_en_fin – final photon energy value for which the reflectivity coefficient is specified
  • _ph_en_scale_type – photon energy sampling type (‘lin’ for linear, ‘log’ for logarithmic)
  • _ang_start – initial grazing angle value for which the reflectivity coefficient is specified
  • _ang_fin – final grazing angle value for which the reflectivity coefficient is specified
  • _ang_scale_type – angle sampling type (‘lin’ for linear, ‘log’ for logarithmic)
class wpg.srwlib.SRWLOptMirPl(_size_tang=1, _size_sag=1, _ap_shape='r', _sim_meth=2, _npt=100, _nps=100, _treat_in_out=1, _ext_in=0, _ext_out=0, _nvx=0, _nvy=0, _nvz=-1, _tvx=1, _tvy=0, _x=0, _y=0, _refl=1, _n_ph_en=1, _n_ang=1, _n_comp=1, _ph_en_start=1000.0, _ph_en_fin=1000.0, _ph_en_scale_type='lin', _ang_start=0, _ang_fin=0, _ang_scale_type='lin')[source]

Bases: wpg.srwlib.SRWLOptMir

Optical Element: Mirror: Plane

Parameters:
  • _size_tang – size in tangential direction [m]
  • _size_sag – size in sagital direction [m]
  • _ap_shape – shape of aperture in local frame (‘r’ for rectangular, ‘e’ for elliptical)
  • _sim_meth – simulation method (1 for “thin” approximation, 2 for “thick” approximation)
  • _treat_in_out – switch specifying how to treat input and output wavefront before and after the main propagation through the optical element: 0- assume that the input wavefront is defined in the plane before the optical element, and the output wavefront is required in a plane just after the element; 1- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; 2- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; however, before the propagation though the optical element, the wavefront should be propagated through a drift back to a plane just before the optical element, then a special propagator will bring the wavefront to a plane at the optical element exit, and after that the wavefront will be propagated through a drift back to the element center;
  • _ext_in – optical element extent on the input side, i.e. distance between the input plane and the optical center (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _ext_out – optical element extent on the output side, i.e. distance between the optical center and the output plane (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _nvx – horizontal coordinate of central normal vector
  • _nvy – vertical coordinate of central normal vector
  • _nvz – longitudinal coordinate of central normal vector
  • _tvx – horizontal coordinate of central tangential vector
  • _tvy – vertical coordinate of central tangential vector
  • _x – horizontal position of mirror center [m]
  • _y – vertical position of mirror center [m]
  • _refl – reflectivity coefficient to set (can be one number or C-aligned flat complex array vs photon energy vs grazing angle vs component (sigma, pi))
  • _n_ph_en – number of photon energy values for which the reflectivity coefficient is specified
  • _n_ang – number of grazing angle values for which the reflectivity coefficient is specified
  • _n_comp – number of electric field components for which the reflectivity coefficient is specified (can be 1 or 2)
  • _ph_en_start – initial photon energy value for which the reflectivity coefficient is specified
  • _ph_en_fin – final photon energy value for which the reflectivity coefficient is specified
  • _ph_en_scale_type – photon energy sampling type (‘lin’ for linear, ‘log’ for logarithmic)
  • _ang_start – initial grazing angle value for which the reflectivity coefficient is specified
  • _ang_fin – final grazing angle value for which the reflectivity coefficient is specified
  • _ang_scale_type – angle sampling type (‘lin’ for linear, ‘log’ for logarithmic)
class wpg.srwlib.SRWLOptMirSph(_r=1.0, _size_tang=1, _size_sag=1, _ap_shape='r', _sim_meth=2, _npt=500, _nps=500, _treat_in_out=1, _ext_in=0, _ext_out=0, _nvx=0, _nvy=0, _nvz=-1, _tvx=1, _tvy=0, _x=0, _y=0, _refl=1, _n_ph_en=1, _n_ang=1, _n_comp=1, _ph_en_start=1000.0, _ph_en_fin=1000.0, _ph_en_scale_type='lin', _ang_start=0, _ang_fin=0, _ang_scale_type='lin')[source]

Bases: wpg.srwlib.SRWLOptMir

Optical Element: Mirror: Spherical

Parameters:
  • _r – radius of surface curvature [m]
  • _size_tang – size in tangential direction [m]
  • _size_sag – size in sagital direction [m]
  • _ap_shape – shape of aperture in local frame (‘r’ for rectangular, ‘e’ for elliptical)
  • _sim_meth – simulation method (1 for “thin” approximation, 2 for “thick” approximation)
  • _npt – number of mesh points to represent mirror in tangential direction (used for “thin” approximation)
  • _nps – number of mesh points to represent mirror in sagital direction (used for “thin” approximation)
  • _treat_in_out – switch specifying how to treat input and output wavefront before and after the main propagation through the optical element: 0- assume that the input wavefront is defined in the plane before the optical element, and the output wavefront is required in a plane just after the element; 1- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; 2- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; however, before the propagation though the optical element, the wavefront should be propagated through a drift back to a plane just before the optical element, then a special propagator will bring the wavefront to a plane at the optical element exit, and after this the wavefront will be propagated through a drift back to the element center;
  • _ext_in – optical element extent on the input side, i.e. distance between the input plane and the optical center (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _ext_out – optical element extent on the output side, i.e. distance between the optical center and the output plane (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _nvx – horizontal coordinate of central normal vector
  • _nvy – vertical coordinate of central normal vector
  • _nvz – longitudinal coordinate of central normal vector
  • _tvx – horizontal coordinate of central tangential vector
  • _tvy – vertical coordinate of central tangential vector
  • _x – horizontal position of mirror center [m]
  • _y – vertical position of mirror center [m]
  • _refl – reflectivity coefficient to set (can be one number or C-aligned flat complex array vs photon energy vs grazing angle vs component (sigma, pi))
  • _n_ph_en – number of photon energy values for which the reflectivity coefficient is specified
  • _n_ang – number of grazing angle values for which the reflectivity coefficient is specified
  • _n_comp – number of electric field components for which the reflectivity coefficient is specified (can be 1 or 2)
  • _ph_en_start – initial photon energy value for which the reflectivity coefficient is specified
  • _ph_en_fin – final photon energy value for which the reflectivity coefficient is specified
  • _ph_en_scale_type – photon energy sampling type (‘lin’ for linear, ‘log’ for logarithmic)
  • _ang_start – initial grazing angle value for which the reflectivity coefficient is specified
  • _ang_fin – final grazing angle value for which the reflectivity coefficient is specified
  • _ang_scale_type – angle sampling type (‘lin’ for linear, ‘log’ for logarithmic)
class wpg.srwlib.SRWLOptMirTor(_rt=1, _rs=1, _size_tang=1, _size_sag=1, _ap_shape='r', _sim_meth=2, _npt=500, _nps=500, _treat_in_out=1, _ext_in=0, _ext_out=0, _nvx=0, _nvy=0, _nvz=-1, _tvx=1, _tvy=0, _x=0, _y=0, _refl=1, _n_ph_en=1, _n_ang=1, _n_comp=1, _ph_en_start=1000.0, _ph_en_fin=1000.0, _ph_en_scale_type='lin', _ang_start=0, _ang_fin=0, _ang_scale_type='lin')[source]

Bases: wpg.srwlib.SRWLOptMir

Optical Element: Mirror: Toroid (to be developed)

Parameters:
  • _rt – tangential (major) radius [m]
  • _rs – sagittal (minor) radius [m]
  • _size_tang – size in tangential direction [m]
  • _size_sag – size in sagital direction [m]
  • _ap_shape – shape of aperture in local frame (‘r’ for rectangular, ‘e’ for elliptical)
  • _sim_meth – simulation method (1 for “thin” approximation, 2 for “thick” approximation)
  • _npt – number of mesh points to represent mirror in tangential direction (used for “thin” approximation)
  • _nps – number of mesh points to represent mirror in sagital direction (used for “thin” approximation)
  • _treat_in_out – switch specifying how to treat input and output wavefront before and after the main propagation through the optical element: 0- assume that the input wavefront is defined in the plane before the optical element, and the output wavefront is required in a plane just after the element; 1- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; 2- assume that the input wavefront is defined in the plane at the optical element center and the output wavefront is also required at the element center; however, before the propagation though the optical element, the wavefront should be propagated through a drift back to a plane just before the optical element, then a special propagator will bring the wavefront to a plane at the optical element exit, and after this the wavefront will be propagated through a drift back to the element center;
  • _ext_in – optical element extent on the input side, i.e. distance between the input plane and the optical center (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _ext_out – optical element extent on the output side, i.e. distance between the optical center and the output plane (positive, in [m]) to be used at wavefront propagation manipulations; if 0, this extent will be calculated internally from optical element parameters
  • _nvx – horizontal coordinate of central normal vector
  • _nvy – vertical coordinate of central normal vector
  • _nvz – longitudinal coordinate of central normal vector
  • _tvx – horizontal coordinate of central tangential vector
  • _tvy – vertical coordinate of central tangential vector
  • _x – horizontal position of mirror center [m]
  • _y – vertical position of mirror center [m]
  • _refl – reflectivity coefficient to set (can be one number or C-aligned flat complex array vs photon energy vs grazing angle vs component (sigma, pi))
  • _n_ph_en – number of photon energy values for which the reflectivity coefficient is specified
  • _n_ang – number of grazing angle values for which the reflectivity coefficient is specified
  • _n_comp – number of electric field components for which the reflectivity coefficient is specified (can be 1 or 2)
  • _ph_en_start – initial photon energy value for which the reflectivity coefficient is specified
  • _ph_en_fin – final photon energy value for which the reflectivity coefficient is specified
  • _ph_en_scale_type – photon energy sampling type (‘lin’ for linear, ‘log’ for logarithmic)
  • _ang_start – initial grazing angle value for which the reflectivity coefficient is specified
  • _ang_fin – final grazing angle value for which the reflectivity coefficient is specified
  • _ang_scale_type – angle sampling type (‘lin’ for linear, ‘log’ for logarithmic)
class wpg.srwlib.SRWLOptShift(_shift_x=0, _shift_y=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Shirt

Parameters:
  • _shift_x – horizontal shift [m]
  • _shift_y – vertical shift [m]
class wpg.srwlib.SRWLOptT(_nx=1, _ny=1, _rx=0.001, _ry=0.001, _arTr=None, _extTr=0, _Fx=1e+23, _Fy=1e+23, _x=0, _y=0, _ne=1, _eStart=0, _eFin=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Transmission (generic)

Parameters:
  • _nx – number of transmission data points in the horizontal direction
  • _ny – number of transmission data points in the vertical direction
  • _rx – range of the horizontal coordinate [m] for which the transmission is defined
  • _ry – range of the vertical coordinate [m] for which the transmission is defined
  • _arTr – complex C-aligned data array (of 2*ne*nx*ny length) storing amplitude transmission and optical path difference as function of transverse coordinates
  • _extTr – transmission outside the grid/mesh is zero (0), or it is same as on boundary (1)
  • _Fx – estimated focal length in the horizontal plane [m]
  • _Fy – estimated focal length in the vertical plane [m]
  • _x – horizontal transverse coordinate of center [m]
  • _y – vertical transverse coordinate of center [m]
  • _ne – number of transmission data points vs photon energy
  • _eStart – initial value of photon energy
  • _eFin – final value of photon energy
allocate(_ne, _nx, _ny)[source]
get_data(_typ, _dep=3, _e=0, _x=0, _y=0)[source]

Returns Transmission Data Characteristic :param _typ: type of transmission characteristic to extract: 1- amplitude transmission, 2- intensity transmission, 3- optical path difference :param _dep: type of dependence to extract: 0- vs photon energy, 1- vs horizontal position, 2- vs vertical position, 3- vs hor. & vert. positions :param _e: photon energy [eV] (to keep fixed) :param _x: horizontal position [m] (to keep fixed) :param _y: vertical position [m] (to keep fixed)

class wpg.srwlib.SRWLOptWG(_L=1, _Dx=0.01, _Dy=0.01, _x=0, _y=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Waveguide

Parameters:
  • _L – length [m]
  • _Dx – horizontal transverse dimension [m]
  • _Dy – vertical transverse dimension [m]
  • _x – horizontal transverse coordinate of center [m]
  • _y – vertical transverse coordinate of center [m]
class wpg.srwlib.SRWLOptZP(_nZones=100, _rn=0.0001, _thick=1e-05, _delta1=1e-06, _atLen1=0.1, _delta2=0, _atLen2=1e-06, _x=0, _y=0)[source]

Bases: wpg.srwlib.SRWLOpt

Optical Element: Thin Lens

Parameters:
  • _nZones – total number of zones
  • _rn – auter zone radius [m]
  • _thick – thickness [m]
  • _delta1 – refractuve index decrement of the “main” material
  • _atLen1 – attenuation length [m] of the “main” material
  • _delta2 – refractuve index decrement of the “complementary” material
  • _atLen2 – attenuation length [m] of the “complementary” material
  • _x – horizontal transverse coordinate of center [m]
  • _y – vertical transverse coordinates of center [m]
class wpg.srwlib.SRWLPartBeam(_Iavg=0, _nPart=0, _partStatMom1=None, _arStatMom2=None)[source]

Bases: object

Particle Beam

Parameters:
  • _Iavg – average current [A]
  • _nPart – number of electrons (in a bunch)
  • _partStatMom1 – particle type and 1st order statistical moments
  • _arStatMom2 – 2nd order statistical moments [0]: <(x-x0)^2> [1]: <(x-x0)*(xp-xp0)> [2]: <(xp-xp0)^2> [3]: <(y-y0)^2> [4]: <(y-y0)*(yp-yp0)> [5]: <(yp-yp0)^2> [6]: <(x-x0)*(y-y0)> [7]: <(xp-xp0)*(y-y0)> [8]: <(x-x0)*(yp-yp0)> [9]: <(xp-xp0)*(yp-yp0)> [10]: <(E-E0)^2>/E0^2 [11]: <(s-s0)^2> [12]: <(s-s0)*(E-E0)>/E0 [13]: <(x-x0)*(E-E0)>/E0 [14]: <(xp-xp0)*(E-E0)>/E0 [15]: <(y-y0)*(E-E0)>/E0 [16]: <(yp-yp0)*(E-E0)>/E0 [17]: <(x-x0)*(s-s0)> [18]: <(xp-xp0)*(s-s0)> [19]: <(y-y0)*(s-s0)> [20]: <(yp-yp0)*(s-s0)>
drift(_dist)[source]

Propagates particle beam statistical moments over a distance in free space :param _dist: distance the beam has to be propagated over [m]

from_RMS(_Iavg=0, _e=0, _sig_e=0, _sig_x=0, _sig_x_pr=0, _m_xx_pr=0, _sig_y=0, _sig_y_pr=0, _m_yy_pr=0)[source]

Sets up particle (electron) beam internal data from Twiss parameters :param _Iavg: average current [A] :param _e: energy [GeV] :param _sig_e: RMS energy spread :param _sig_x: horizontal RMS size [m] :param _sig_x_pr: horizontal RMS divergence [rad] :param _m_xx_pr: <(x-<x>)(x’-<x’>)> [m] :param _sig_y: vertical RMS size [m] :param _sig_y_pr: vertical RMS divergence [rad] :param _m_yy_pr: <(y-<y>)(y’-<y’>)> [m]

from_Twiss(_Iavg=0, _e=0, _sig_e=0, _emit_x=0, _beta_x=0, _alpha_x=0, _eta_x=0, _eta_x_pr=0, _emit_y=0, _beta_y=0, _alpha_y=0, _eta_y=0, _eta_y_pr=0)[source]

Sets up particle (electron) beam internal data from Twiss parameters :param _Iavg: average current [A] :param _e: energy [GeV] :param _sig_e: RMS energy spread :param _emit_x: horizontal emittance [m] :param _beta_x: horizontal beta-function [m] :param _alpha_x: horizontal alpha-function [rad] :param _eta_x: horizontal dispersion function [m] :param _eta_x_pr: horizontal dispersion function derivative [rad] :param _emit_y: vertical emittance [m] :param _beta_y: vertical beta-function [m] :param _alpha_y: vertical alpha-function [rad] :param _eta_y: vertical dispersion function [m] :param _eta_y_pr: vertical dispersion function derivative [rad]

class wpg.srwlib.SRWLParticle(_x=0, _y=0, _z=0, _xp=0, _yp=0, _gamma=1, _relE0=1, _nq=-1)[source]

Bases: object

Charged Particle

Parameters:
  • _x – instant coordinates [m]
  • _y – instant coordinates [m]
  • _z – instant coordinates [m]
  • _xp – instant transverse velocity component btx = vx/c (angles for relativistic particle)
  • _yp – instant transverse velocity component bty = vy/c (angles for relativistic particle)
  • _gamma – relative energy
  • _relE0 – rest mass (energy) in units of electron rest mass, e.g. 1 for electron, 1836.1526988 (=938.272013/0.510998902) for proton
  • _nq – charge of the particle related to absolute value of electron charge, -1 for electron, 1 for positron and for proton
drift(_dist)[source]

Propagates particle beam statistical moments over a distance in free space :param _dist: distance the beam has to be propagated over [m]

get_E(_unit='GeV')[source]
class wpg.srwlib.SRWLPrtTrj(_arX=None, _arXp=None, _arY=None, _arYp=None, _arZ=None, _arZp=None, _arBx=None, _arBy=None, _arBz=None, _np=0, _ctStart=0, _ctEnd=0, _partInitCond=None)[source]

Bases: object

Charged Particle Trajectory

Parameters:
  • _arX – array of horizontal position [m]
  • _arXp – array of horizontal relative velocity (trajectory angle) [rad]
  • _arY – array of vertical position [m]
  • _arYp – array of vertical relative velocity (trajectory angle) [rad]
  • _arZ – array of longitudinal positions [m]
  • _arZp – array of longitudinal relative velocity [rad]
  • _arBx – array of horizontal magnetic field component “seen” by particle [T]
  • _arBy – array of vertical magnetic field component “seen” by particle [T]
  • _arBz – array of longitudinal magnetic field component “seen” by particle [T]
  • _np – number of trajectory points
  • _ctStart – start value of independent variable (c*t) for which the trajectory should be (/is) calculated (is constant step enough?)
  • _ctEnd – end value of independent variable (c*t) for which the trajectory should be (/is) calculated (is constant step enough?)
  • _partInitCond – particle type and initial conditions for which the trajectory should be (/is) calculated
allocate(_np, _allB=False)[source]
save_ascii(_file_path)[source]

Auxiliary function to write tabulated Trajectory data to ASCII file

class wpg.srwlib.SRWLRadMesh(_eStart=0, _eFin=0, _ne=1, _xStart=0, _xFin=0, _nx=1, _yStart=0, _yFin=0, _ny=1, _zStart=0, _nvx=0, _nvy=0, _nvz=1, _hvx=1, _hvy=0, _hvz=0, _arSurf=None)[source]

Bases: object

Radiation Mesh (Sampling)

Parameters:
  • _eStart – initial value of photon energy (/time)
  • _eFin – final value of photon energy (/time)
  • _ne – number of points vs photon energy (/time)
  • _xStart – initial value of horizontal position (/angle)
  • _xFin – final value of horizontal position (/angle)
  • _nx – number of points vs horizontal position (/angle)
  • _yStart – initial value of vertical position (/angle)
  • _yFin – final value of vertical position (/angle)
  • _ny – number of points vs vertical position (/angle)
  • _zStart – longitudinal position
  • _nvx – horizontal lab-frame coordinate of inner normal to observation plane (/ surface in its center)
  • _nvy – vertical lab-frame coordinate of inner normal to observation plane (/ surface in its center)
  • _nvz – longitudinal lab-frame coordinate of inner normal to observation plane (/ surface in its center)
  • _hvx – horizontal lab-frame coordinate of the horizontal base vector of the observation plane (/ surface in its center)
  • _hvy – vertical lab-frame coordinate of the horizontal base vector of the observation plane (/ surface in its center)
  • _hvz – longitudinal lab-frame coordinate of the horizontal base vector of the observation plane (/ surface in its center)
  • _arSurf – array defining the observation surface (as function of 2 variables - x & y - on the mesh given by _xStart, _xFin, _nx, _yStart, _yFin, _ny; to be used in case this surface differs from plane)
set_from_other(_mesh)[source]
class wpg.srwlib.SRWLStokes(_arS=None, _typeStokes='f', _eStart=0, _eFin=0, _ne=0, _xStart=0, _xFin=0, _nx=0, _yStart=0, _yFin=0, _ny=0, _mutual=0)[source]

Bases: object

Radiation Stokes Parameters

Parameters:
  • _arS – flat C-aligned array of all Stokes components (outmost loop over Stokes parameter number); NOTE: only ‘f’ (float) is supported for the moment (Jan. 2012)
  • _typeStokes – numerical type: ‘f’ (float) or ‘d’ (double, not supported yet)
  • _eStart – initial value of photon energy (/time)
  • _eFin – final value of photon energy (/time)
  • _ne – numbers of points vs photon energy
  • _xStart – initial value of horizontal position
  • _xFin – final value of photon horizontal position
  • _nx – numbers of points vs horizontal position
  • _yStart – initial value of vertical position
  • _yFin – final value of vertical position
  • _ny – numbers of points vs vertical position
  • _mutual – mutual Stokes components (4*(_ne*_nx*_ny_)^2 values)
add_stokes(_st, _n_comp=4, _mult=1, _meth=0)[source]

Add Another Stokes structure :param _st: Stokes structure to be added :param _n_comp: number of components to treat :param _mult: multiplier :param _meth: method of adding the Stokes structure _st: 0- simple addition assuming _wfr to have same mesh as this wavefront 1- add using bilinear interpolation (taking into account meshes of the two wavefronts) 2- add using bi-quadratic interpolation (taking into account meshes of the two wavefronts) 3- add using bi-cubic interpolation (taking into account meshes of the two wavefronts)

allocate(_ne, _nx, _ny, _typeStokes='f', _mutual=0)[source]
avg_update_interp(_more_stokes, _iter, _ord, _n_stokes_comp=4, _mult=1.0)[source]

Update this Stokes data structure with new data, contained in the _more_stokes structure, calculated on a different 2D mesh, so that it would represent estimation of average of (_iter + 1) structures :param _more_stokes: Stokes data structure to “add” to the estimation of average :param _iter: number of Stokes structures already “added” previously :param _ord: order of 2D interpolation to use (1- bilinear, …, 3- bi-cubic) :param _n_stokes_comp: number of Stokes components to treat (1 to 4) :param _mult: optional multiplier of the _more_stokes

avg_update_interp_mutual(_more_stokes, _iter, _n_stokes_comp=4, _mult=1.0)[source]

Update this Stokes data structure with new data, contained in the _more_stokes structure, calculated on a different 2D mesh, so that it would represent estimation of average of (_iter + 1) structures :param _more_stokes: Stokes data structure to “add” to the estimation of average :param _iter: number of Stokes structures already “added” previously :param _n_stokes_comp: number of Stokes components to treat (1 to 4) :param _mult: optional multiplier of the _more_stokes

avg_update_same_mesh(_more_stokes, _iter, _n_stokes_comp=4, _mult=1.0)[source]

Update this Stokes data structure with new data, contained in the _more_stokes structure, calculated on the same mesh, so that this structure would represent estimation of average of (_iter + 1) structures :param _more_stokes: Stokes data structure to “add” to the estimation of average :param _iter: number of Stokes structures already “added” previously :param _n_stokes_comp: number of Stokes components to treat (1 to 4) :param _mult: optional multiplier of the _more_stokes

to_int(_pol=6)[source]

Calculates / “extracts” intensity at a given polarization from the Stokes components :param _pol: polarization component to extract:

0- Linear Horizontal; 1- Linear Vertical; 2- Linear 45 degrees; 3- Linear 135 degrees; 4- Circular Right; 5- Circular Left; 6- Total
Returns:1D array with (C-aligned) resulting intensity data
class wpg.srwlib.SRWLWfr(_arEx=None, _arEy=None, _typeE='f', _eStart=0, _eFin=0, _ne=0, _xStart=0, _xFin=0, _nx=0, _yStart=0, _yFin=0, _ny=0, _zStart=0, _partBeam=None)[source]

Bases: object

Radiation Wavefront (Electric Field)

Parameters:
  • _arEx – horizontal complex electric field component array; NOTE: only ‘f’ (float) is supported for the moment (Jan. 2011)
  • _arEy – vertical complex electric field component array
  • _typeE – electric field numerical type: ‘f’ (float) or ‘d’ (double)
  • _eStart – initial value of photon energy (/time)
  • _eFin – final value of photon energy (/time)
  • _ne – numbers of points vs photon energy
  • _xStart – initial value of horizontal positions
  • _xFin – final value of horizontal positions
  • _nx – numbers of points vs horizontal positions
  • _yStart – initial vertical positions
  • _yFin – final value of vertical positions
  • _ny – numbers of points vs vertical positions
  • _zStart – longitudinal position
  • _partBeam – particle beam source; strictly speaking, it should be just SRWLParticle; however, “multi-electron” information can appear useful for those cases when “multi-electron intensity” can be deduced from the “single-electron” one by convolution

Some additional parameters, that are not included in constructor arguments: Rx, Ry: instant wavefront radii dRx, dRy: error of wavefront radii xc, yc: transverse coordinates of wavefront instant “source center” avgPhotEn: average photon energy for time-domain simulations presCA: presentation/domain: 0- coordinates, 1- angles presFT: presentation/domain: 0- frequency (photon energy), 1- time unitElFld: electric field units: 0- arbitrary, 1- sqrt(Phot/s/0.1%bw/mm^2) arElecPropMatr: effective 1st order “propagation matrix” for electron beam parameters arMomX, arMomY: statistical moments (of Wigner distribution); to check the exact number of moments required arWfrAuxData: array of auxiliary wavefront data

addE(_wfr, _meth=0)[source]

Add Another Electric Field Wavefront :param _wfr: wavefront to be added :param _meth: method of adding the wavefront _wfr: 0- simple addition assuming _wfr to have same mesh as this wavefront 1- add using bilinear interpolation (taking into account meshes of the two wavefronts) 2- add using bi-quadratic interpolation (taking into account meshes of the two wavefronts) 3- add using bi-cubic interpolation (taking into account meshes of the two wavefronts)

allocate(_ne, _nx, _ny, _EXNeeded=1, _EYNeeded=1, _typeE='f', _backupNeeded=0)[source]

Allocate Electric Field data :param _ne: number of points vs photon energy / time :param _nx: number of points vs horizontal position / angle :param _ny: number of points vs vertical position / angle :param _EXNeeded: switch specifying whether Ex data is necessary or not (1 or 0) :param _EYNeeded: switch specifying whether Ey data is necessary or not (1 or 0) :param _typeE: numerical type of Electric Field data: float (single precision) or double (‘f’ or ‘d’); double is not yet supported :param _backupNeeded: switch specifying whether backup of Electric Field data (arExAux, arEyAux) should be created or not (1 or 0)

calc_stokes(_stokes)[source]

Calculate Stokes parameters from Electric Field

delE(_type=0, _treatEX=1, _treatEY=1)[source]

Delete Electric Field data :param _type: type of data to be deleted: 0- arEx, arEy, arExAux, arEyAux; 1- arEx, arEy only; 2- arExAux, arEyAux only :param _treatEX: switch specifying whether Ex data should be deleted or not (1 or 0) :param _treatEY: switch specifying whether Ey data should be deleted or not (1 or 0)

wpg.srwlib.srwl_opt_setup_CRL(_foc_plane, _delta, _atten_len, _shape, _apert_h, _apert_v, _r_min, _n, _wall_thick, _xc, _yc, _void_cen_rad=None, _e_start=0, _e_fin=0, _nx=1001, _ny=1001)[source]

Setup Transmission type Optical Element which simulates Compound Refractive Lens (CRL) :param _foc_plane: plane of focusing: 1- horizontal, 2- vertical, 3- both :param _delta: refractive index decrement (can be one number of array vs photon energy) :param _atten_len: attenuation length [m] (can be one number of array vs photon energy) :param _shape: 1- parabolic, 2- circular (spherical) :param _apert_h: horizontal aperture size [m] :param _apert_v: vertical aperture size [m] :param _r_min: radius (on tip of parabola for parabolic shape) [m] :param _n: number of lenses (/”holes”) :param _wall_thick: min. wall thickness between “holes” [m] :param _xc: horizontal coordinate of center [m] :param _yc: vertical coordinate of center [m] :param _void_cen_rad: flat array/list of void center coordinates and radii: [x1, y1, r1, x2, y2, r2,…] :param _e_start: initial photon energy :param _e_fin: final photon energy :return: transmission (SRWLOptT) type optical element which simulates CRL

wpg.srwlib.srwl_opt_setup_cyl_fiber(_foc_plane, _delta_ext, _delta_core, _atten_len_ext, _atten_len_core, _diam_ext, _diam_core, _xc, _yc)[source]

Setup Transmission type Optical Element which simulates Cylindrical Fiber :param _foc_plane: plane of focusing: 1- horizontal (i.e. fiber is parallel to vertical axis), 2- vertical (i.e. fiber is parallel to horizontal axis) :param _delta_ext: refractive index decrement of extenal layer :param _delta_core: refractive index decrement of core :param _atten_len_ext: attenuation length [m] of external layer :param _atten_len_core: attenuation length [m] of core :param _diam_ext: diameter [m] of external layer :param _diam_core: diameter [m] of core :param _xc: horizontal coordinate of center [m] :param _yc: vertical coordinate of center [m] :return: transmission (SRWLOptT) type optical element which simulates Cylindrical Fiber

wpg.srwlib.srwl_opt_setup_surf_height_1d(_height_prof_data, _dim, _ang, _ang_r=0, _amp_coef=1, _ar_arg_long=None, _nx=0, _ny=0, _size_x=0, _size_y=0, _xc=0, _yc=0)[source]

Setup Transmission type optical element with 1D (mirror or grating) surface Heght Profile data :param _height_prof_data: two- or one-column table containing, in case of two columns: longitudinal position in [m] (1st column) and the Height Profile in [m] (2nd column) data; in case of one column, it contains the Height Profile data :param _dim: orientation of the reflection (deflection) plane; can be ‘x’ or ‘y’ :param _ang: grazing angle (between input optical axis and mirror/grating plane) :param _ang_r: reflection angle (between output optical axis and mirror/grating plane) :param _amp_coef: height profile “amplification coefficient” :param _ar_arg_long: optional array of longitudinal position (along mirror/grating) in [m]; if _ar_arg_long != None, any longitudinal position contained in _height_prof_data is ignored :param _nx: optional number of points in horizontal dimension of the output transmission optical element :param _ny: optional number of points in vertical dimension of the output transmission optical element :param _size_x: optional horizontal transverse size of the output transmission optical element (if <=0: _height_prof_data, _dim, _ar_arg_long, _ar_arg_tr data is used) :param _size_y: optional vertical transverse size of the output transmission optical element (if <=0: _height_prof_data, _dim, _ar_arg_long, _ar_arg_tr data is used) :param _xc: optional horizontal center position of the output transmission optical element :param _yc: optional vertical center position of the output transmission optical element :return: transmission (SRWLOptT) type optical element which simulates the effect of surface height error

wpg.srwlib.srwl_opt_setup_surf_height_2d(_height_prof_data, _dim, _ang, _ang_r=0, _amp_coef=1, _ar_arg_long=None, _ar_arg_tr=None, _nx=0, _ny=0, _size_x=0, _size_y=0)[source]

Setup Transmission type optical element with 2D (mirror or grating) surface Heght Profile data :param _height_prof_data: a matrix (2D array) containing the Height Profile data in [m]; if _ar_height_prof_x==None and _ar_height_prof_y==None: the first column in _height_prof_data is assumed to be the “longitudinal” position [m] and first row the “transverse” position [m], and _height_prof_data[0][0] is not used; otherwise the “longitudinal” and “transverse” positions on the surface are assumed to be given by _ar_height_prof_x, _ar_height_prof_y :param _dim: orientation of the reflection (deflection) plane; can be ‘x’ or ‘y’ :param _ang: grazing angle (between input optical axis and mirror/grating plane) :param _ang_r: reflection angle (between output optical axis and mirror/grating plane) :param _amp_coef: height profile “amplification coefficient” :param _ar_arg_long: optional array of longitudinal position (along mirror/grating) in [m] :param _ar_arg_tr: optional array of transverse position on mirror/grating surface in [m] :param _nx: optional number of points in horizontal dimension of the output transmission optical element :param _ny: optional number of points in vertical dimension of the output transmission optical element :param _size_x: optional horizontal transverse size of the output transmission optical element (if <=0: _height_prof_data, _dim, _ar_arg_long, _ar_arg_tr data is used) :param _size_y: optional vertical transverse size of the output transmission optical element (if <=0: _height_prof_data, _dim, _ar_arg_long, _ar_arg_tr data is used) :return: transmission (SRWLOptT) type optical element which simulates the effect of surface height error

wpg.srwlib.srwl_uti_array_alloc(_type, _n)[source]
wpg.srwlib.srwl_uti_math_seq_halton(i, base=2)[source]
wpg.srwlib.srwl_uti_num_round(_x, _ndig=8)[source]
wpg.srwlib.srwl_uti_ph_en_conv(_x, _in_u='keV', _out_u='nm')[source]

Photon Energy <-> Wavelength conversion :param _x: value to be converted :param _in_u: input unit :param _out_u: output unit :return: value in the output units

wpg.srwlib.srwl_uti_proc_is_master()[source]

Check if process is Master (in parallel processing sense)

wpg.srwlib.srwl_uti_rand_fill_vol(_np, _x_min, _x_max, _nx, _ar_y_vs_x_min, _ar_y_vs_x_max, _y_min, _y_max, _ny, _ar_z_vs_xy_min, _ar_z_vs_xy_max)[source]

Generate coordinates of ponts randomly filling 3D volume limited by two arbitrary curves (defining base) and two surfaces :param _np: number of random points in rectangular parallelepiped to try :param _x_min: min. x coordinate :param _x_max: max. x coordinate :param _nx: number of points vs x coord. :param _ar_y_vs_x_min: min. y vs x array :param _ar_y_vs_x_max: max. y vs x array :param _y_min: min. y coordinate :param _y_max: max. y coordinate :param _ny: number of points vs y coord. :param _ar_z_vs_xy_min: min. z vs x and y flat 2D array :param _ar_z_vs_xy_max: max. z vs x and y flat 2D array :return: flat array of point coordinates: array(‘d’, [x1,y1,z1,x2,y2,z2,…])

wpg.srwlib.srwl_uti_read_data_cols(_file_path, _str_sep, _i_col_start=0, _i_col_end=-1, _n_line_skip=0)[source]

Auxiliary function to read-in data comumns from ASCII file (2D table) :param _file_path: full path (including file name) to the file :param _str_sep: column separation symbol(s) (string) :param _i_col_start: initial data column to read :param _i_col_end: final data column to read :param _n_line_skip: number of lines to skip in the beginning of the file :return: 2D list containing data columns read

wpg.srwlib.srwl_uti_read_intens_ascii(_file_path, _num_type='f')[source]
wpg.srwlib.srwl_uti_read_mag_fld_3d(_fpath, _scom='#')[source]
wpg.srwlib.srwl_uti_save_intens_ascii(_ar_intens, _mesh, _file_path, _n_stokes=1, _arLabels=['Photon Energy', 'Horizontal Position', 'Vertical Position', 'Intensity'], _arUnits=['eV', 'm', 'm', 'ph/s/.1%bw/mm^2'], _mutual=0)[source]
wpg.srwlib.srwl_uti_save_text(_text, _file_path)[source]
wpg.srwlib.srwl_uti_write_data_cols(_file_path, _cols, _str_sep, _str_head=None, _i_col_start=0, _i_col_end=-1)[source]

Auxiliary function to write tabulated data (columns, i.e 2D table) to ASCII file :param _file_path: full path (including file name) to the file to be (over-)written :param _cols: array of data columns to be saves to file :param _str_sep: column separation symbol(s) (string) :param _str_head: header (string) to write before data columns :param _i_col_start: initial data column to write :param _i_col_end: final data column to write

wpg.srwlib.srwl_wfr_emit_prop_multi_e(_e_beam, _mag, _mesh, _sr_meth, _sr_rel_prec, _n_part_tot, _n_part_avg_proc=1, _n_save_per=100, _file_path=None, _sr_samp_fact=-1, _opt_bl=None, _pres_ang=0, _char=0, _x0=0, _y0=0, _e_ph_integ=0, _rand_meth=1, _tryToUseMPI=True)[source]

Calculate Stokes Parameters of Emitted (and Propagated, if beamline is defined) Partially-Coherent SR :param _e_beam: Finite-Emittance e-beam (SRWLPartBeam type) :param _mag: Magnetic Field container (magFldCnt type) :param _mesh: mesh vs photon energy, horizontal and vertical positions (SRWLRadMesh type) on which initial SR should be calculated :param _sr_meth: SR Electric Field calculation method to be used (0- “manual”, 1- “auto-undulator”, 2- “auto-wiggler”) :param _sr_rel_prec: relative precision for SR Electric Field calculation (usually 0.01 is OK, the smaller the more accurate) :param _n_part_tot: total number of “macro-electrons” to be used in the calculation :param _n_part_avg_proc: number of “macro-electrons” to be used in calculation at each “slave” before sending Stokes data to “master” (effective if the calculation is run via MPI) :param _n_save_per: periodicity of saving intermediate average Stokes data to file by master process :param _file_path: path to file for saving intermediate average Stokes data by master process :param _sr_samp_fact: oversampling factor for calculating of initial wavefront for subsequent propagation (effective if >0) :param _opt_bl: optical beamline (container) to propagate the radiation through (SRWLOptC type) :param _pres_ang: switch specifying presentation of the resulting Stokes parameters: coordinate (0) or angular (1) :param _char: radiation characteristic to calculate: 0- Intensity (s0); 1- Four Stokes components; 2- Mutual Intensity Cut vs X; 3- Mutual Intensity Cut vs Y; 4- Mutual Intensity Cut vs X & Y; 10- Flux :param _x0: horizontal center position for mutual intensity calculation :param _y0: vertical center position for mutual intensity calculation :param _e_ph_integ: integration over photon energy is required (1) or not (0); if the integration is required, the limits are taken from _mesh :param _rand_meth: method for generation of pseudo-random numbers for e-beam phase-space integration:

1- standard pseudo-random number generator 2- Halton sequences 3- LPtau sequences (to be implemented)
Parameters:_tryToUseMPI – switch specifying whether MPI should be attempted to be used