wpg.srwlib module

class wpg.srw.srwlib.SRWLDet(_xStart=0, _xFin=0, _nx=1, _yStart=0, _yFin=0, _ny=1, _dx=0, _dy=0, _spec_eff=1, _eStart=0, _eFin=0, _ord_interp=1)[source]

Bases: object

Detector of Radiation

Parameters:
  • _xStart – initial value of horizontal position [m] (/angle [rad])
  • _xFin – final value of horizontal position [m] (/angle [rad])
  • _nx – number of points vs horizontal position [m] (/angle [rad])
  • _yStart – initial value of vertical position [m] (/angle [rad])
  • _yFin – final value of vertical position [m] (/angle [rad])
  • _ny – number of points vs vertical position [m] (/angle [rad])
  • _dx – horizontal pixel size [m] (/angle [rad])
  • _dy – vertical pixel size [m] (/angle [rad])
  • _spec_eff – one number or array defining detector spectral efficiency (as function of photon energy, on the mesh given by _eStart, _eFin, _ne)
  • _eStart – initial value of photon energy [eV] (/time [s])
  • _eFin – final value of photon energy [eV] (/time [s])
  • _ne – number of points vs photon energy [eV] (/time [s])
  • _eff_e – treat spectral efficiency as for electric field if True
  • _ord_interp – interpolation order (i.e. order of polynomials to be used at 2D interpolation)
get_mesh()[source]
treat_int(_stk, _mesh=None, _ord_interp=0)[source]

Treat Intensity of Input Radiation :param _stk: Stokes data structure or a simple Intensity array to be treated by detector :param _mesh: mesh structure (if it is defined, _stk should be treated as Intensity array of type f) :param _ord_interp: Interpolation order to be used (overrides self.ord_interp)

class wpg.srw.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

(Coherent) Gaussian (Radiation) Beam

Parameters:
  • _x – average horizontal coordinate of waist [m]
  • _y – average vertical coordinate 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.srw.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.srw.srwlib.SRWLMagFld[source]

Bases: object

Magnetic Field (base class)

class wpg.srw.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.srw.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.srw.srwlib.SRWLMagFldC(_arMagFld=None, _arXc=None, _arYc=None, _arZc=None, _arVx=None, _arVy=None, _arVz=None, _arAng=None)[source]

Bases: wpg.srw.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.srw.srwlib.SRWLMagFldH(_n=1, _h_or_v='v', _B=0, _ph=0, _s=1, _a=1)[source]

Bases: wpg.srw.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.srw.srwlib.SRWLMagFldM(_G=0, _m=2, _n_or_s='n', _Leff=0, _Ledge=0, _R=0)[source]

Bases: wpg.srw.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.srw.srwlib.SRWLMagFldS(_B=0, _Leff=0)[source]

Bases: wpg.srw.srwlib.SRWLMagFld

Magnetic Field: Solenoid

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

Bases: wpg.srw.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

K_2_B(K)[source]

Convert K (deflection parameter) to B (magnetic field amplitude)

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.srw.srwlib.SRWLOpt[source]

Bases: object

Optical Element (base class)

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

Bases: wpg.srw.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.srw.srwlib.SRWLOptAng(_ang_x=0, _ang_y=0)[source]

Bases: wpg.srw.srwlib.SRWLOpt

Optical Element: Angle

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

Bases: wpg.srw.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]
append_drift(_len)[source]

Appends drift space to the end of the Container :param _len: length [m]

class wpg.srw.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, _uc=1)[source]

Bases: wpg.srw.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)
  • _uc – crystal use case: 1- Bragg Reflection, 2- Bragg Transmission (Laue cases to be added)
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, saggital, 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.srw.srwlib.SRWLOptD(_L=0, _treat=0)[source]

Bases: wpg.srw.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.srw.srwlib.SRWLOptG(_mirSub, _m=1, _grDen=100, _grDen1=0, _grDen2=0, _grDen3=0, _grDen4=0, _grAng=0)[source]

Bases: wpg.srw.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.srw.srwlib.SRWLOptL(_Fx=1e+23, _Fy=1e+23, _x=0, _y=0)[source]

Bases: wpg.srw.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.srw.srwlib.SRWLOptMir[source]

Bases: wpg.srw.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.srw.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.srw.srwlib.SRWLOptMir

Optical Element: Mirror: Elliptical NOTE: in the Local frame of the Mirror tangential direction is X, saggital Y, mirror normal is along Z

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.srw.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.srw.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.srw.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.srw.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.srw.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.srw.srwlib.SRWLOptMir

Optical Element: Mirror: Toroid NOTE: in the Local frame of the Mirror tangential direction is X, saggital Y, mirror normal is along Z

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.srw.srwlib.SRWLOptShift(_shift_x=0, _shift_y=0)[source]

Bases: wpg.srw.srwlib.SRWLOpt

Optical Element: Shirt

Parameters:
  • _shift_x – horizontal shift [m]
  • _shift_y – vertical shift [m]
class wpg.srw.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, _alloc_base=[0])[source]

Bases: wpg.srw.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, _alloc_base=[0])[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.srw.srwlib.SRWLOptWG(_L=1, _Dx=0.01, _Dy=0.01, _x=0, _y=0)[source]

Bases: wpg.srw.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.srw.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.srw.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.srw.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.srw.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.srw.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.srw.srwlib.SRWLPtSrc(_x=0, _y=0, _z=0, _flux=1, _unitFlux=1, _polar=1)[source]

Bases: object

Point Source (emitting coherent spherical wave)

Parameters:
  • _x – horizontal position [m]
  • _y – vertical position [m]
  • _z – longitudinal position [m]
  • _flux – spectral flux value
  • _unitFlux – spectral flux units: 1- ph/s/.1%bw, 2- W/eV
  • _polar – polarization 1- lin. hor., 2- lin. vert., 3- lin. 45 deg., 4- lin.135 deg., 5- circ. right, 6- circ. left, 7- radial
class wpg.srw.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)
copy()[source]
get_dep_type()[source]
set_from_other(_mesh)[source]
class wpg.srw.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_deg_coh(_rel_zer_tol=0.0001, _rot=True)[source]

Calculates / “extracts” Degree of Coherence from the Mutual Intensity (first Stokes component, s0) :param _rel_zer_tol: relative zero tolerance to use at normalizing (dividing) by the intensity :param _rot: rotate or not the degree of coherence data :return: 1D array with (C-aligned) resulting degree of coherence data

to_deg_coh_slow(_rel_zer_tol=0.0001, _rot=True)[source]

Calculates / “extracts” Degree of Coherence from the Mutual Intensity (first Stokes component, s0) :param _rel_zer_tol: relative zero tolerance to use at normalizing (dividing) by the intensity :param _rot: rotate or not the degree of coherence data :param _n_stokes_comp: number of Stokes components to treat (1 to 4) :return: 1D array with (C-aligned) resulting degree of coherence data

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.srw.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, _n_stokes_comp=4)[source]

Calculate Stokes parameters from Electric Field

copy_comp(_stokes)[source]

Copy compenents of Electric Field to Stokes structure

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.srw.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, _ang_rot_ex=0, _ang_rot_ey=0)[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 :param _nx: number of points vs horizontal position to represent the transmission element :param _ny: number of points vs vertical position to represent the transmission element :param _ang_rot_ex: angle [rad] of CRL rotation about horizontal axis :param _ang_rot_ey: angle [rad] of CRL rotation about vertical axis :param _ang_rot_ez: angle [rad] of CRL rotation about longitudinal axis :return: transmission (SRWLOptT) type optical element which simulates CRL

wpg.srw.srwlib.srwl_opt_setup_bumps(_ampl, _sx, _sy, _n, _delta, _atten_len, _rx, _ry, _xc=0, _yc=0, _nx=1001, _ny=1001, _n_sig=4, _ampl_min=None, _sx_min=None, _sy_min=None, _seed=None)[source]

Setup Transmission type Optical Element which simulates a set of Gaussian-shape “Bumps” randomly placed in transverse plane :param _ampl: amplitude of bumps [m] or list of min. and max. amplitudes :param _sx: horizontal FWHM size of bumps [m] or list of min. and max. horizontal sizes :param _sy: vertical FWHM size of bumps [m] or list of min. and max. vertical sizes :param _n: number of bumps or list of numbers of bumps of different types :param _delta: refractive index decrement of bump material or list of refractive index decrements of bump materials :param _atten_len: attenuation length of bump material [m] or list of attenuation lengths of bump materials :param _rx: horizontal coordiate range over which bumps are distributed [m] :param _ry: vertical coordiate range over which bumps are distributed [m] :param _xc: horizontal coordinate of center [m] of the interval / range over bumps are applied [m] :param _yc: vertical coordinate of center [m] of the interval / range over bumps are applied [m] :param _nx: number of points vs horizontal position to represent the transmission element :param _ny: number of points vs vertical position to represent the transmission element :param _n_sig: number of sigmas of each Gaussian to take into acount on each side of center position (i.e. only these x, y values will be used: -_n_sig*sigX < x < _n_sig*sigX, -_n_sig*sigY < y < _n_sig*sigY) :param _ampl_min: minimal amplitude of bumps [m]; if it defined, _ampl is treated as maximal amplitude, and the bump amplitude is evenly and randomly distributed between the two values :param _sx_min: minimal horizontal FWHM size of bumps [m]; if it defined, _sx is treated as maximal horizonatl size, and the bump horizontal size is evenly and randomly distributed between the two values :param _sy_min: minimal vertical FWHM size of bumps [m]; if it defined, _sy is treated as maximal vertical size, and the bump vertical size is evenly and randomly distributed between the two values :param _seed: integer number to be used to seed random placing of bumps (in None, the seeding will be made from current time) :return: transmission (SRWLOptT) type optical element which simulates a set of Gaussian-shape “Bumps” randomly placed in transverse plane

wpg.srw.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 external 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.srw.srwlib.srwl_opt_setup_gen_transm(_func_path, _delta, _atten_len, _rx, _ry, _xc=0, _yc=0, _ext_tr=0, _fx=0, _fy=0, _e_start=0, _e_fin=0, _nx=1001, _ny=1001)[source]

Setup Transmission type Optical Element similar to one simulating CRL, but with arbitrary optical path in material over hor. and vert. positions, defined by external function _func_path(x, y) :param _func_path: user-defined function of 2 variables specifying path in material over hor. and vert. positions (x, y) :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 _rx: horizontal aperture (range) size [m] :param _ry: vertical aperture (range) size [m] :param _xc: horizontal coordinate of center [m] :param _yc: vertical coordinate of center [m] :param _ext_tr: transmission outside the grid/mesh is zero (0), or it is same as on boundary (1) :param _fx: horizontal focal length [m]; if it is not set, a numerical estimate will be made (around _xc, _yc) :param _fy: vertical focal length [m]; if it is not set, a numerical estimate will be made (around _xc, _yc) :param _e_start: initial photon energy :param _e_fin: final photon energy :param _nx: number of points vs horizontal position to represent the transmission element :param _ny: number of points vs vertical position to represent the transmission element :return: transmission (SRWLOptT) type optical element which simulates CRL

wpg.srw.srwlib.srwl_opt_setup_mask(_delta, _atten_len, _thick, _hx, _hy, _pitch_x, _pitch_y, _mask_Nx, _mask_Ny, _grid_nx, _grid_ny, _grid_sh, _grid_dx, _grid_dy=0, _grid_angle=0, _mask_x0=0, _mask_y0=0)[source]

Setup Transmission type Optical Element which simulates a mask array for at-wavelength metrology.

Parameters:
  • _delta – refractive index decrement (can be one number of array vs photon energy)
  • _atten_len – attenuation length [m] (can be one number of array vs photon energy)
  • _thick – thickness of mask [m]
  • _hx – sampling interval in x-direction [m]
  • _hy – sampling interval in y-direction [m]
  • _pitch_x – grid pitch in x-direction [m]
  • _pitch_y – grid pitch in y-direction [m]
  • _mask_Nx – number of pixels in x-direction [1]
  • _mask_Ny – number of pixels in y-direction [1]
  • _grid_nx – number of grids in x-direction
  • _grid_ny – number of grids in y-direction
  • _grid_sh – grid shape (0: Circular grids case. 1: Rectangular grids case. 2: 2-D phase grating)
  • _grid_dx – grid dimension in x-direction, width for rectangular or elliptical grids [m]
  • _grid_dy – grid dimension in y-direction, height for rectangular or elliptical grids [m]
  • _grid_angle – tilt angle of the grid [rad]
  • _mask_x0 – horizontal coordinate of the mask [m]
  • _mask_y0 – vertical coordinate of the mask [m]
Returns:

transmission (SRWLOptT) type optical element which simulates the PMA

wpg.srw.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 is not 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.srw.srwlib.srwl_opt_setup_surf_height_1d_old(_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 is not 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.srw.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 is None and _ar_height_prof_y is 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.srw.srwlib.srwl_uti_array_alloc(_type, _n, _list_base=[0])[source]
wpg.srw.srwlib.srwl_uti_math_seq_halton(i, base=2)[source]
wpg.srw.srwlib.srwl_uti_num_round(_x, _ndig=8)[source]
wpg.srw.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.srw.srwlib.srwl_uti_proc_is_master()[source]

Check if process is Master (in parallel processing sense)

wpg.srw.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.srw.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.srw.srwlib.srwl_uti_read_intens_ascii(_file_path, _num_type='f')[source]
wpg.srw.srwlib.srwl_uti_read_mag_fld_3d(_fpath, _scom='#')[source]
wpg.srw.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, _cmplx=0)[source]
wpg.srw.srwlib.srwl_uti_save_stat_wfr_emit_prop_multi_e(particle_number=0, total_num_of_particles=0, filename='srwl_stat_wfr_emit_prop_multi_e', cores=None, particles_per_iteration=None)[source]

The function to save .log and .json status files to monitor parallel MPI jobs progress.

Parameters:
  • particle_number – current particle number.
  • total_num_of_particles – total number of particles.
  • filename – the name without extension used to save log/status files.
  • cores – number of cores used for parallel calculation.
  • particles_per_iteration – number of particles averaged per iteration (between mpi-receives).-
Returns:

None.

wpg.srw.srwlib.srwl_uti_save_stat_wfr_emit_prop_multi_e_init(rank, num_of_proc, num_part_per_proc, num_sent_per_proc, num_part_avg_proc)[source]

Initialize parameters for the SRW status files and generate the files. :param rank: rank of the process. :param num_of_proc: total number of processes. :param num_part_per_proc: number of electrons treated by each worker process. :param num_sent_per_proc: number of sending acts made by each worker process. :param num_part_avg_proc: number of macro-electrons to be used in calculation by each worker.

wpg.srw.srwlib.srwl_uti_save_text(_text, _file_path, mode='w', newline='\n')[source]
wpg.srw.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.srw.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, _wr=0.0, _wre=0.0, _det=None, _me_approx=0, _file_bkp=False)[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) or Coherent Gaussian beam (SRWLGsnBm type) or Point Source (SRWLPtSrc 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) or both (2, to implement !!!) :param _char: radiation characteristic to calculate:

0- Total Intensity, i.e. Flux per Unit Surface Area (s0); 1- Four Stokes components of Flux per Unit Surface Area; 2- Mutual Intensity Cut vs X; 3- Mutual Intensity Cut vs Y; 4- Mutual Intensity Cuts and Degree of Coherence vs X & Y; 10- Flux 20- Electric Field (sum of fields from all macro-electrons, assuming CSR) 40- Total Intensity, i.e. Flux per Unit Surface Area (s0), Mutual Intensity Cuts and Degree of Coherence vs X & Y;
Parameters:
  • _x0 – horizontal center position for mutual intensity calculation
  • _y0 – vertical center position for mutual intensity calculation
  • _e_ph_integ – integration over photon energy is required (1) or not (0); if the integration is required, the limits are taken from _mesh
  • _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)
  • _tryToUseMPI – switch specifying whether MPI should be attempted to be used
  • _wr – initial wavefront radius [m] to assume at wavefront propagation (is taken into account if != 0)
  • _wre – initial wavefront radius error [m] to assume at wavefront propagation (is taken into account if != 0)
  • _det – detector object for post-processing of final intensity (instance of SRWLDet)
  • _me_approx – approximation to be used at multi-electron integration: 0- none (i.e. do standard M-C integration over 5D phase space volume of e-beam), 1- integrate numerically only over e-beam energy spread and use convolution to treat transverse emittance
  • _file_bkp – create or not backup files with resulting multi-electron radiation characteristics
wpg.srw.srwlib.srwl_wfr_fn(_fn_core, _type)[source]

Generate standard filenames for radiation characteristics from a given core name :param _fn_core: core filename :param _type: type of radiation characteristic:

0- Electric Field 1- Spectral Intensity, i.e. Spectral Flux per Unit Surface Area 2- Spectral Angular Intensity, i.e. Spectral Flux per Unit Solid Angle 3- Mutual Intensity (in real space, i.e. dependent on coordinates) 31- Mutual Intensity Cut vs X 32- Mutual Intensity Cut vs Y 4- Degree of Coherence 41- Degree of Coherence Cut vs X 42- Degree of Coherence Cut vs Y 5- Wigner Distribution / Brightness 51- Wigner Distribution / Brightness Cut vs X 52- Wigner Distribution / Brightness Cut vs Y
wpg.srw.srwlib.srwl_wfr_from_intens(_ar_int, _mesh, _part_beam, _Rx, _Ry, _xc=0, _yc=0)[source]

Setup Coherent Wavefront from Intensity (assuming spherical or asigmatic wave): note this is an error-prone procedure :param _ar_int: input intensity array :param _mesh: mesh vs photon energy, horizontal and vertical positions (SRWLRadMesh type) on which initial SR should be calculated :param _part_beam: Finite-Emittance beam (SRWLPartBeam type) :param _Rx: horizontal wavefront radius [m] :param _Ry: vertical wavefront radius [m] :param _xc: horizontal wavefront center position [m] :param _yc: vertical wavefront center position [m]

wpg.srw.srwlib.srwl_wfr_prop_drifts(_wfr, _dz, _nz, _pp, _do3d=False, _nx=-1, _ny=-1, _rx=0, _ry=0, _xc=0, _yc=0, _pol=6, _type=0, _ord_interp=1)[source]

Propagates wavefront over free space in a number of steps and generates intensity distributions vs (z,x) and (z,y) and possibly (z,x,y) :param _wfr: input/output wavefront :param _dz: longitudinal step size for the drifts :param _nz: number of drift steps to be made :param _pp: list of propagation parameters to be used for each drift step :param _do3d: generate intensity vs (z,x,y) in addition to the cuts (z,x) and (z,y) :param _nx: number of points vs horizontal position (is taken into account if >0) :param _ny: number of points vs vertical position (is taken into account if >0) :param _rx: number of points vs horizontal position (is taken into account if >0) :param _ry: number of points vs vertical position(is taken into account if >0) :param _xc: horizontal position for vertical cut of intensity :param _yc: vertical position for horizontal cut of intensity :param _pol: switch specifying polarization component to be extracted:

=0 -Linear Horizontal; =1 -Linear Vertical; =2 -Linear 45 degrees; =3 -Linear 135 degrees; =4 -Circular Right; =5 -Circular Left; =6 -Total
Parameters:
  • _type – switch specifying “type” of a characteristic to be extracted: =0 -“Single-Electron” Intensity; =1 -“Multi-Electron” Intensity; =2 -“Single-Electron” Flux; =3 -“Multi-Electron” Flux; =4 -“Single-Electron” Radiation Phase; =5 -Re(E): Real part of Single-Electron Electric Field; =6 -Im(E): Imaginary part of Single-Electron Electric Field; =7 -“Single-Electron” Intensity, integrated over Time or Photon Energy (i.e. Fluence)
  • _ord_interp – interpolation order for final intensity calc.

:return resulting intensity distributions