def srw_end_bl_call(): el2 = [] opMask = setup_mask() el2.append(srwlib.SRWLOptD(1e-32)) el2.append(opMask) pp2 = [] pp2.append([0, 0, 1.0, 1, 0, xRatio, 1/xRatio, xRatio, 1/yRatio]) pp2.append([0, 0, 1.0, 0, 0, 1.0, 1.0, 1.0, 1.0])#mask pp2.append([0, 0, 1.0, 0, 0, 1.0, 1.0, 1.0, 1.0]) op2 = deepcopy(srwlib.SRWLOptC(el2, pp2)) int_ws2=propogation(op2) mesh_ws2 = deepcopy(wfr2.mesh) print('.....',mesh_ws2.xStart, mesh_ws2.ny , '......') up.uti_plot2d1d( int_ws2, [mesh_ws2.xStart, mesh_ws2.xFin, mesh_ws2.nx], [mesh_ws2.yStart, mesh_ws2.yFin, mesh_ws2.ny], 0, 0, ['Horizontal Position', 'Vertical Position', ' After Propagation'], ['m', 'm', 'ph/s/.1%bw/mm^2'], True) up.uti_plot_show()
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)
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()
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)
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)
def action_simulate(self): msg_list = [] def msg(m): msg_list.append(m + '... \n \n') self._view.set_result_text('simulation', ''.join(msg_list)) self.params['wavefront'] = self._view.get_wavefront_params() for k in 'wavefront', 'simulation_kind', 'polarization', 'intensity': self.params[k] = self._view.get_global_param(k) res = self.simulate(msg) msg('Plotting the results') for plot in res.plots: plot[0](*plot[1:]) msg('NOTE: Close all graph windows to proceed') uti_plot.uti_plot_show()
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)
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]) yC = [] Inte = [] arI1ymax = max(arI1y) for i in range(len(arI1y)): arI1y[i] = arI1y[i] / arI1ymax thx = 2.0 * (i - wfr.mesh.ny / 2.0) * wfr.mesh.yFin / wfr.mesh.ny yC.append(thx) xA = 3.1415 * Aperture * sin(thx) / lam