Beispiel #1
0
def test_3():
    fname = _remove('uti_plot-0.png')
    up.uti_plot_init(None)
    x_range = (-.5, +.5, 10)
    up.uti_plot1d(array.array('f', Line(*x_range)), x_range)
    up.uti_plot_show()
    assert not os.path.isfile(fname)
Beispiel #2
0
def read_data(SFileName="1DprofileSR.txt", TFileName="Trajectory.txt"):
#   Reading SPECTRUM
#    SFileName="Spectrum.txt"
    f=open(SFileName,"r",1000)
    e_p=[]
    I_rad=[]
    for line in f.readlines():
        words = line.split()
        e_p.append(words[0])
        I_rad.append(words[1])
    f.close()

#   Reading TRAJECTORY
#    TFileName="Trajectory.txt"
    f=open(TFileName,"r",10000)
    z_dist=[]
    x_trajectory=[]
    for line in f.readlines():
        words = line.split()
        z_dist.append(words[0])
        x_trajectory.append(words[1])
    f.close()

    uti_plot.uti_plot1d(x_trajectory, [1, 10000, 10000], 
    ['ct [um]', 'Horizontal Position [m]'])
    uti_plot.uti_plot_show()
Beispiel #3
0
def test_2():
    fname_format = 'tuti-{}.png'
    fname = _remove(fname_format.format(0))
    up.uti_plot_init('agg', fname_format)
    x_range = (-.5, +.5, 10)
    up.uti_plot1d(array.array('f', Line(*x_range)), x_range)
    up.uti_plot_show()
    assert os.path.isfile(fname)
Beispiel #4
0
def test_1():
    fname = _remove('uti_plot-0.png')
    json_name = _remove('uti_plot-0.json')
    if 'DISPLAY' in os.environ:
        del os.environ['DISPLAY']
    up.uti_plot_init('TkAgg', None)
    x_range = (-.5, +.5, 10)
    up.uti_plot1d(array.array('f', Line(*x_range)), x_range)
    up.uti_plot_show()
    assert os.path.isfile(fname)
    assert os.path.isfile(json_name)
Beispiel #5
0
    return BzVsY, [yMin, yMax, ny], IBzVsX, [xMin, xMax, nx]


#*********************************Entry point
if __name__ == "__main__":

    #Build the Geometry
    g = BuildGeometry()
    print('SCW Geometry Index:', g)

    #Display the Geometry in 3D Viewer
    rad.ObjDrwOpenGL(g)

    #Calculate Magnetic Field
    BzVsY, MeshY, IBzVsX, MeshX = CalcField(g)

    print('Field in Center:', BzVsY[0], 'T')
    print('Field Integral in Center:', IBzVsX[0], 'T.mm')

    #Plot the Results
    uti_plot.uti_plot1d(
        BzVsY, MeshY,
        ['Longitudinal Position [mm]', 'Bz [T]', 'Vertical Magnetic Field'])
    uti_plot.uti_plot1d(IBzVsX, MeshX, [
        'Horizontal Position [mm]', 'Integral of Bz [T.mm]',
        'Vertical Magnetic Field Integral'
    ])

    uti_plot.uti_plot_show(
    )  #show all graphs (and block further execution, if any)
Beispiel #6
0
def test_1():
    x_range = (-.5, +.5, 2)
    up.uti_plot1d(array.array('f', [.5, +.5]), x_range)
Intens = 0  ## 0=Single-e I/1=Multi-e I/2=Single-e F/3=Multi-e F/4=Single-e RadPhase/5=Re single-e Efield/6=Im single-e Efield
DependArg = 3  ## 0 - vs e, 1 - vs x, 2 - vs y, 3- vs x&y, 4-vs x&e, 5-vs y&e, 6-vs x&y&e
plotNum = 1000
plotMeshx = [plotNum * wfr.mesh.xStart, plotNum * wfr.mesh.xFin, wfr.mesh.nx]
plotMeshy = [plotNum * wfr.mesh.yStart, plotNum * wfr.mesh.yFin, wfr.mesh.ny]

print(' 10. Plotting initial and output wavefront')
arIin = array('f', [0] * wfrIn.mesh.nx * wfrIn.mesh.ny)
srwl.CalcIntFromElecField(arIin, wfrIn, 0, 0, 3, wfr.mesh.eStart, 0, 0)
plotMeshInX = [1000 * wfrIn.mesh.xStart, 1000 * wfrIn.mesh.xFin, wfrIn.mesh.nx]
plotMeshInY = [1000 * wfrIn.mesh.yStart, 1000 * wfrIn.mesh.yFin, wfrIn.mesh.ny]
uti_plot.uti_plot2d(arIin, plotMeshInX, plotMeshInY,
                    ['Horizontal Position [mm]', 'Vertical Position [mm]', 'Intensity Before Propagation [a.u.]'])
arIinY = array('f', [0] * wfrIn.mesh.ny)
srwl.CalcIntFromElecField(arIinY, wfrIn, 0, 0, 2, wfrIn.mesh.eStart, 0, 0)  # extracts intensity
uti_plot.uti_plot1d(arIinY, plotMeshInY, ['Vertical Position [mm]', 'Intensity [a.u.]',
                                          'Intensity Before Propagation\n(cut vs vertical position at x = 0)'])

arIout = array('f', [0] * wfr.mesh.nx * wfr.mesh.ny)  # "flat" array to take 2D intensity data
arII = arIout
arIE = array('f', [0] * wfr.mesh.nx * wfr.mesh.ny)
srwl.CalcIntFromElecField(arII, wfr, Polar, Intens, DependArg, wfr.mesh.eStart, 0, 0)
uti_plot.uti_plot2d(arII, plotMeshx, plotMeshy,
                    ['Horizontal Position [mm]', 'Vertical Position [mm]', 'Intenisty, a.u.'])
uti_plot.uti_plot_show()

print(' 11. Extracting intensity for comparison with analytic calculation')
arI1y = array('f', [0] * wfr.mesh.ny)
srwl.CalcIntFromElecField(arI1y, wfr, Polar, Intens, 2, wfr.mesh.eStart, 0, 0)  # extracts intensity vs y
print('before:', [wfrIn.mesh.yStart, wfrIn.mesh.xFin, wfrIn.mesh.nx, wfrIn.mesh.ny])
print('after :', [wfr.mesh.yStart, wfr.mesh.xFin, wfr.mesh.nx, wfr.mesh.ny])
Beispiel #8
0
#Definitions and allocation for the Trajectory waveform
arPrecPar = [1] 
npTraj = 10001 # number of trajectory points along longitudinal axis
partTraj = srwlib.SRWLPrtTrj()
partTraj.partInitCond = part
partTraj.allocate(npTraj, True)
partTraj.ctStart = -L_total/2
partTraj.ctEnd = L_total/2 

print('6. Calculating Trajectory ...')
# Calculating Trajectory
partTraj = srwlib.srwl.CalcPartTraj(partTraj, magFldCnt, arPrecPar)
ctMesh = [partTraj.ctStart, partTraj.ctEnd, partTraj.np]

print('7. Plotting Trajectory ...')
uti_plot.uti_plot1d(partTraj.arX, ctMesh, ['ct [m]', 'Horizontal Position [m]'])
uti_plot.uti_plot1d(partTraj.arY, ctMesh, ['ct [m]', 'Vertical Position [m]'])
uti_plot.uti_plot1d(partTraj.arXp, ctMesh, ['ct [m]', 'Horizontal angle [rad]'])
uti_plot.uti_plot_show()

print('8. Switching to Synchrotron Radiation Calculations ...')

el1=0 # This FLAG defines type of calculation: 
#       Either filament beam calculation or for heat load calc

if el1==0:
    wfr2 = srwlib.SRWLWfr() #For intensity distribution at fixed photon energy
else:
    wfr2 = srwlib.SRWLStokes() 

print('9. Defining SR Wavefront ...')
RedA=3 # reduction factor for accuracies
FactorScan=1.1
ticPowerDen=[]
for i in range(4):
    RedF=np.round(RedF*FactorScan)
    stktP=stk(1,Nx/RedF,Ny/RedF,wfr2.mesh.zStart,wfr2.mesh.eStart,wfr2.mesh.eFin,AperXY)
    tic = time.clock()
    arPrecP[4]=arPrecP[4]/RedA
    srwl.CalcPowDenSR(stktP, elecBeam, 0, magFldCnt, arPrecP)
    toc = time.clock()
    ticPowerDen.append(toc - tic)
    print("# Time elapsed heat load calculations 1/Redc: %1.1f %1.3e" % (RedF, (toc - tic)))

#Power Spectrum and Density
#print(stktF.mesh.ne)
uti_plot.uti_plot1d(stktF.arS, [stktF.mesh.eStart, stktF.mesh.eFin, stktF.mesh.ne], ['Photon Energy [eV]', 'Flux [ph/s/.1%bw]', 'Flux through Finite Aperture'])
plotMeshX = [1000*stktP.mesh.xStart, 1000*stktP.mesh.xFin, stktP.mesh.nx]
plotMeshY = [1000*stktP.mesh.yStart, 1000*stktP.mesh.yFin, stktP.mesh.ny]
uti_plot.uti_plot2d(stktP.arS, plotMeshX, plotMeshY, ['Horizontal Position [mm]', 'Vertical Position [mm]', 'Power Density'])
uti_plot.uti_plot_show()

#-----------------------------------------------------------

print('5) Main calculation segment')
tic = time.clock()
arPrecF[2] = 1.0 #arPrecF[2]*RedF #longitudinal integration precision parameter
arPrecF[3] = 1.0 #arPrecF[2]*RedF #azimuthal integration precision parameter
srwl.CalcStokesUR(stkF, elecBeam, und, arPrecF)
toc = time.clock()
print("Time elapsed spectral calculations: %1.3e" % (toc - tic))