def getSimpleBl(): bl = Beamline() bl.append(Drift(10), propagation_parameters(1, 1, 1, 1, mode = 'quadratic')) return bl
def simpleProp(wfr): print(calculate_fwhm(wfr)) bl = Beamline() #bl.append(Aperture('c','a', 500e-06),propagation_parameters(1,1,1,1,mode = 'normal')) bl.append(Drift(100), propagation_parameters(1,1,1,1,mode = 'quadratic')) #bl.append(Drift(100), propagation_parameters(1,1,1,1,mode = 'quadratic')) bl.propagate(wfr) plotIntensity(wfr) print(calculate_fwhm(wfr))
val = nx//4 for i in range(N): wfr = construct_SA1_wavefront(nx,ny,4.96,0.25) pm = np.random.rand(nx,ny)*1e-2 print(pm[val,val]) srwlib.srwl.SetRepresElecField(wfr._srwl_wf, 'f') ps = phaseMask(pm, [ get_axis(wfr, axis = 'x').max()- get_axis(wfr, axis = 'x').min(), get_axis(wfr, axis = 'y').max()- get_axis(wfr, axis = 'y').min()], wav) ##speckle bl = Beamline() bl.append(sp, propagation_parameters(1,1,1,1)) bl.propagate(wfr) bl = Beamline() bl.append(ps, propagation_parameters(1,1,1,1)) bl.propagate(wfr) PH[:,:,i] = wfr.get_phase()[:,:,0] #% np.pi*2 ## PH = (PH + np.pi) % (2 * np.pi) - np.pi bl = Beamline() bl.append(Drift(0.10), propagation_parameters(1,1,1,1, mode = 'normal'))
wfr = construct_SA1_wavefront(nx, ny, 4.96, 0.25) wfr.store_hdf5("coherentSrc.h5") wav = (h * c) / (wfr.params.photonEnergy * e) pm = gaussian_filter(np.random.rand(5, 5) / 1000, sigma=20) plt.imshow(pm) sp = phaseMask(pm, [ get_axis(wfr, axis='x').max() - get_axis(wfr, axis='x').min(), get_axis(wfr, axis='y').max() - get_axis(wfr, axis='y').min() ], wav) ##speckle bl = Beamline() #bl.append(sp, propagation_parameters(1,1,1,1)) bl.append(Drift(1), propagation_parameters(1, 1, 1, 1, mode='normal')) bl.propagate(wfr) Ps = wfr.get_phase(slice_number=0) # Is = wfr.get_intensity(slice_number=0) ekev = wfr.params.photonEnergy z1 = 1 z2 = 1 pix_size = wfr.get_spatial_resolution()[0] delta = 1 beta = 1 bg_val = 1 scale = 1 #######################################
@author: twguest test to see if backpropagation works (it does) """ import sys sys.path.append("../") sys.path.append("/opt/WPG/") from model.tools import constructPulse from model.beamline.structure import propagation_parameters from felpy.model.beamline import Beamline from wpg.optical_elements import Drift from wpg.wpg_uti_wf import plot_intensity_map as plotIntensity if __name__ == "__main__": wfr = constructPulse(nz = 2) plotIntensity(wfr) bl = Beamline() bl.append(Drift(-10), propagation_parameters(1,1,1,1)) bl.propagate(wfr) plotIntensity(wfr)
def sliceFocus(wfr, ekev, focus='micron', nslices=500, axisName='x', outdir=None): spb = Instrument(overwrite_mirrors=False) spb.setupHOMs(ekev) spb.build_elements(focus=focus) spb.buildBeamline(focus=focus) el_n = len(spb.bl.propagation_options[0]['optical_elements']) - 1 slice_interval = copy( spb.bl.propagation_options[0]['optical_elements'][el_n].L / 1000) spb.bl.propagation_options[0]['optical_elements'][el_n].L *= 0.75 spb.bl.propagation_options[0]['propagation_parameters'][ el_n] = propagation_parameters(1 / 5, 5, 1 / 5, 5, mode='quadratic') bl = spb.get_beamline() bl.propagate(wfr) if axisName == 'x': data_focslice = np.zeros([nslices, np.shape(wfr.data.arrEhor)[0]]) elif axisName == 'y': data_focslice = np.zeros([nslices, np.shape(wfr.data.arrEhor)[1]]) fig = plt.figure() ax = fig.add_subplot(111) for n in range(nslices): print("Slice {}/{}".format(n + 1, nslices)) bl = Beamline() bl.append(SRWLOptD(slice_interval), propagation_parameters(1, 1, 1, 1, mode='normal')) bl.propagate(wfr) data_focslice[-n - 1, :] = wfr.get_profile_1d()[0] y = np.linspace( spb.bl.propagation_options[0]['optical_elements'][el_n].L, spb.bl.propagation_options[0]['optical_elements'][el_n].L + nslices * slice_interval, nslices) if axisName == 'x': extent = [ wfr.params.Mesh.xMin * 1e6, wfr.params.Mesh.xMax * 1e6, y.min(), y.max() ] elif axisName == 'y': extent = [ wfr.params.Mesh.yMin * 1e6, wfr.params.Mesh.yMax * 1e6, y.min(), y.max() ] ax.imshow(data_focslice, extent=extent, aspect='auto', norm=mpl.colors.LogNorm()) if focus == "micron": ax.set_title("Micron Focus Location") ax.set_ylabel("Longitudinal Distance from MKB (m)") if axisName == 'x': x = np.linspace(wfr.params.Mesh.xMin * 1e6, wfr.params.Mesh.xMax * 1e6, wfr.params.Mesh.nx) ax.set_xlabel("x ($\mu$m)") elif axisName == 'y': x = np.linspace(wfr.params.Mesh.yMin * 1e6, wfr.params.Mesh.yMax * 1e6, wfr.params.Mesh.ny) ax.set_xlabel("y ($\mu$m)") if focus == "nano": ax.set_title("Nano Focus Location") ax.set_ylabel("Longitudinal Distance from NKB (m)") if axisName == 'x': x = np.linspace(wfr.params.Mesh.xMin * 1e6, wfr.params.Mesh.xMax * 1e6, wfr.params.Mesh.nx) ax.set_xlabel("x ($\mu$m)") elif axisName == 'y': x = np.linspace(wfr.params.Mesh.yMin * 1e6, wfr.params.Mesh.yMax * 1e6, wfr.params.Mesh.ny) ax.set_xlabel("y ($\mu$m)") ax.plot(x, np.ones(x.shape) * spb.bl.params["df"]["distance"], 'r--') plt.legend(["Design Focal Plane"]) plt.show() estr = str(ekev).replace(".", "-") if outdir is not None: fig.savefig(outdir + "{}_focus_slice_{}_{}".format(focus, estr, axisName))