# the number of coheret modes to propagate ncount = 30 #------------------------------------------------------------------------------ #--------------------------------------------------- # source sr0 = source(file_name = "B4_test.h5", name = "source", n_vector = ncount) #remap the coherent mode sr0.remap(0.5e-6, 0.5e-6) #--------------------------------------------------- # white beam slit wbs = screen(optics = sr0, n = ncount, location = 40) propagate_s(sr0, wbs) #--------------------------------------------------- # crl crl = ideal_lens(optics = wbs, n = ncount, location = 45, xfocus = 19.138, yfocus = 19.138) propagate_s(wbs, crl) crl.add_mask(xcoor = [-2.15e-4, 2.15e-4], ycoor = [-2.15e-4, 2.15e-4]) #--------------------------------------------------- # focus focus = screen(optics = crl, n = ncount, location = 78.3) propagate_s(crl, focus) # apply secondary source slit
#------------------------------------------------------------------------------ # beamline sr0 = source2( file_name = 'b4_srw2_12400.h5', name = 'source', n_vector = _ncount ) sr0.remap(0.5e-6, 0.5e-6) crl = ideal_lens( optics = sr0, n = _ncount, location = 40, xfocus = 16.91, yfocus = 16.91 ) focus = screen(optics = sr0, n = _ncount, location = 69.3) #------------------------------------------------------------------------------ # proapgation propagate_s(sr0, crl) propagate_s(crl, focus) #------------------------------------------------------------------------------ # plot focus center_x = 3.19 focus.xtick = focus.xtick - center_x*1e-6 focus.slit(xcoor = [-3e-5, 3e-5], ycoor = [-3e-5, 3e-5]) focus.cal_csd()
flux_ratio = list() islit = 7 sr0 = source2(file_name='b4_srw2_12400.h5', name='source', n_vector=_ncount) sr0.expand(xcoor=[-4e-4, 4e-4], ycoor=[-4e-4, 4e-4]) sr0.remap(0.5e-6, 0.5e-6) sr0.cal_i() crl = ideal_lens(optics=sr0, n=_ncount, location=40, xfocus=16.91, yfocus=16.91) ssa = screen(optics=sr0, n=_ncount, location=69.3) #-------------------------------------------------------------------------- # proapgation propagate_s(sr0, crl) propagate_s(crl, ssa) #------------------------------------------------ ix = np.sum(np.abs(ssa.cmode[0]), 0) iy = np.sum(np.abs(ssa.cmode[0]), 1) x_loc = np.argmin(np.abs(ix - np.max(ix))) y_loc = np.argmin(np.abs(iy - np.max(iy)))
akb = 0 offsetx = 0 offrotx = 0 # def beamline_saCDI(offsetx = 0, offrotx = 0, e = 0): #--------------------------------------------------- # source - 20m sr0 = source(file_name="B4.h5", name="source", n_vector=_ncount, offx=offsetx, rotx=offrotx) sc0 = screen(optics=sr0, n=_ncount, location=20) propagate_s(sr0, sc0) sc0.expand(xcoor=[-8e-4, 8e-4], ycoor=[-8e-4, 8e-4]) sc0.remap(1e-6, 1e-6) #--------------------------------------------------- # DCM slit dcm = screen(optics=sc0, n=_ncount, location=40) propagate_s(sc0, dcm) # add phase error dcm.slit(xcoor=[-3e-4, 3e-4], ycoor=[-3e-4, 3e-4]) dcm.expand(xcoor=[-8e-4, 8e-4], ycoor=[-8e-4, 8e-4]) dcm.add_mask(xcoor=[-3e-4, 3e-4], ycoor=[-3e-4, 3e-4])
def srw_cat_compare_propagators(): #-------------------------------------------------------------------------- # wavefront calculation part_beam = SRWLPartBeam() part_beam.Iavg = 0.2 part_beam.partStatMom1.x = 0.0 part_beam.partStatMom1.y = 0.0 part_beam.partStatMom1.z = -2.0795500000000002 part_beam.partStatMom1.xp = 0.0 part_beam.partStatMom1.yp = 0.0 part_beam.partStatMom1.gamma = 11741.70710144324 part_beam.arStatMom2[0] = 8.704890000000001e-11 part_beam.arStatMom2[1] = 0.0 part_beam.arStatMom2[2] = 1.1102224e-11 part_beam.arStatMom2[3] = 5.938969e-12 part_beam.arStatMom2[4] = 0.0 part_beam.arStatMom2[5] = 1.6281759999999997e-12 part_beam.arStatMom2[10] = 1.1236e-06 magnetic_fields = [] magnetic_fields.append( SRWLMagFldH(1, 'v', _B=0.47251184326559015, _ph=0.0, _s=-1, _a=1.0)) magnetic_structure = SRWLMagFldU(_arHarm=magnetic_fields, _per=0.0199, _nPer=201.0) magnetic_field_container = SRWLMagFldC(_arMagFld=[magnetic_structure], _arXc=array('d', [0.0]), _arYc=array('d', [0.0]), _arZc=array('d', [0.0])) mesh = SRWLRadMesh(_eStart=12400.003208235006, _eFin=12400.003208235006, _ne=1, _xStart=-0.0002, _xFin=0.0002, _nx=513, _yStart=-0.0002, _yFin=0.0002, _ny=513, _zStart=10.0) stk = SRWLStokes() stk.allocate(1, 513, 513) stk.mesh = mesh wfr = SRWLWfr() wfr.allocate(mesh.ne, mesh.nx, mesh.ny) wfr.mesh = mesh wfr.partBeam = part_beam initial_mesh = deepcopy(wfr.mesh) srwl.CalcElecFieldSR(wfr, 0, magnetic_field_container, [1, 0.01, 0.0, 0.0, 50000, 1, 0.0]) # example wfr mesh0 = deepcopy(wfr.mesh) wfr0 = np.reshape(np.array(wfr.arEx), (mesh0.nx, mesh0.ny, 2)) wfr0 = wfr0[:, :, 0] + 1j * wfr0[:, :, 1] # plot wfr arI = array('f', [0] * mesh0.nx * mesh0.ny) srwl.CalcIntFromElecField(arI, wfr, 6, 0, 3, mesh0.eStart, 0, 0) plotMesh0x = [1000 * mesh0.xStart, 1000 * mesh0.xFin, mesh0.nx] plotMesh0y = [1000 * mesh0.yStart, 1000 * mesh0.yFin, mesh0.ny] arI = np.reshape(np.array(arI), (mesh0.nx, mesh0.ny)) xtick = np.linspace(mesh0.xStart * 1e6, mesh0.xFin * 1e6, mesh0.nx) ytick = np.linspace(mesh0.yStart * 1e6, mesh0.yFin * 1e6, mesh0.ny) #-------------------------------------------------------------------------- # optical layout sr0 = source2(file_name='b4_srw2_12400.h5', name='source', n_vector=1) sr0.slit(xcoor=[-2e-4, 2e-4], ycoor=[-2e-4, 2e-4]) sr0.remap(0.77973e-6, 0.77973e-6) sr0.cmode[0] = np.abs(wfr0) * np.exp(-1j * np.angle(wfr0)) sr0.position = 10 ssa = screen(optics=sr0, n=1, location=10) propagate_s(sr0, ssa) # ssa.remap(0.5e-6, 0.5e-6) ssa.add_mask(xcoor=[-2.5e-5, 2.5e-5], ycoor=[-2.5e-5, 2.5e-5]) ssa.expand(xcoor=[-4e-4, 4e-4], ycoor=[-4e-4, 4e-4]) sc0 = screen(optics=ssa, n=1, location=20) sc1 = screen(optics=ssa, n=1, location=20) sc2 = screen(optics=ssa, n=1, location=20) #-------------------------------------------------------------------------- # compare propagators # Fresnel propagator propagate_s(ssa, sc0, t='fresnel') # Asm propagator propagate_s(ssa, sc1, t='asm') # CZT propagator propagate_czt(ssa, sc2) #-------------------------------------------------------------------------- return ssa, sc0, sc1, sc2