def propagate_wavefront(wavefront, beamline, output_file=None): """ Propagate wavefront and store it in output file. :param wavefront: wpg.Wavefront object or path to HDF5 file :param beamline: SRWLOptC container of beamline :param output_file: if parameter present - store propagaed wavefront to file :return: propagated wavefront object """ if not isinstance(beamline, Beamline): bl = Beamline(beamline) else: bl = beamline print(bl) if isinstance(wavefront, Wavefront): wfr = Wavefront(srwl_wavefront=wavefront._srwl_wf) else: print('*****reading wavefront from h5 file...') wfr = Wavefront() wfr.load_hdf5(wavefront) print_mesh(wfr) print('*****propagating wavefront (with resizing)...') bl.propagate(wfr) if output_file is not None: print('save hdf5:', output_file) wfr.store_hdf5(output_file) print('done') return wfr
def propagate_wavefront(wavefront, beamline, output_file=None): """ Propagate wavefront and store it in output file. :param wavefront: Wavefront object or path to HDF5 file :param beamline: SRWLOptC container of beamline :param output_file: if parameter present - store propagaed wavefront to file :return: propagated wavefront object: """ if not isinstance(beamline, Beamline): bl = Beamline(beamline) else: bl = beamline print(bl) if isinstance(wavefront, Wavefront): wfr = Wavefront(srwl_wavefront=wavefront._srwl_wf) else: print("*****reading wavefront from h5 file...") wfr = Wavefront() wfr.load_hdf5(wavefront) print_mesh(wfr) print("*****propagating wavefront (with resizing)...") bl.propagate(wfr) if output_file is not None: print("save hdf5:", output_file) wfr.store_hdf5(output_file) print("done") return wfr
def do_wpg_calculation(self): aperture = Aperture(shape='r', ap_or_ob='a', Dx=self.horApM1, Dy=self.range_xy) wavefront = self.input_data.get_wavefront() beamline_for_propagation = Beamline() beamline_for_propagation.append(aperture, Use_PP()) beamline_for_propagation.propagate(wavefront) return wavefront
def do_wpg_calculation(self): rMinCRL = 2 * self.delta * self.input_data.get_distance_to_previous( ) / self.nCRL #CRL radius at the tip of parabola [m] opCRL = create_CRL_from_file(self.working_directory, self.file_name, 3, self.delta, self.attenLen, 1, self.diamCRL, self.diamCRL, rMinCRL, self.nCRL, self.wallThickCRL, 0, 0, None) wavefront = self.input_data.get_wavefront() beamline_for_propagation = Beamline() beamline_for_propagation.append(opCRL, Use_PP()) beamline_for_propagation.append(Drift(self.distance), Use_PP(semi_analytical_treatment=1)) beamline_for_propagation.propagate(wavefront) return wavefront
def main(): d2waist = 270. # beam parameters: qnC = 0.1 # [nC] e-bunch charge thetaOM = 3.6e-3 ekev = 5.0 # calculate angular divergence: theta_fwhm = (17.2 - 6.4 * np.sqrt(qnC)) * 1e-6 / ekev**0.85 theta_rms = theta_fwhm / 2.35 sigX = 12.4e-10 / (ekev * 4 * np.pi * theta_rms) # define limits xmax = theta_rms * d2waist * 3.5 xmin = -xmax ymin = xmin ymax = xmax nx = 600 ny = nx nz = 5 tau = 0.12e-15 srw_wf = build_gauss_wavefront(nx, ny, nz, ekev, xmin, xmax, ymin, ymax, tau, sigX, sigX, d2waist) wf = wpg.Wavefront(srw_wf) b = Beamline() b.append(Drift(5), Use_PP()) b.propagate(wf) # srwl.ResizeElecField(srw_wf, 'c', [0, 0.25, 1, 0.25, 1]) if not os.path.exists('tests_data'): os.mkdir('tests_data') wf_hdf5_out_file_path = os.path.join('tests_data', 'my_gauss.h5') wf.store_hdf5(wf_hdf5_out_file_path) wf_out = wpg.Wavefront() wf_out.load_hdf5(wf_hdf5_out_file_path) return wf
def main(): d2waist = 270. # beam parameters: qnC = 0.1 # [nC] e-bunch charge thetaOM = 3.6e-3 ekev = 5.0 # calculate angular divergence: theta_fwhm = (17.2 - 6.4 * np.sqrt(qnC)) * 1e-6 / ekev ** 0.85 theta_rms = theta_fwhm / 2.35 sigX = 12.4e-10 / (ekev * 4 * np.pi * theta_rms) # define limits xmax = theta_rms * d2waist * 3.5 xmin = - xmax ymin = xmin ymax = xmax nx = 600 ny = nx nz = 5 tau = 0.12e-15 srw_wf = build_gauss_wavefront( nx, ny, nz, ekev, xmin, xmax, ymin, ymax, tau, sigX, sigX, d2waist) wf = wpg.Wavefront(srw_wf) b = Beamline() b.append(Drift(5), Use_PP()) b.propagate(wf) # srwl.ResizeElecField(srw_wf, 'c', [0, 0.25, 1, 0.25, 1]) if not os.path.exists('tests_data'): os.mkdir('tests_data') wf_hdf5_out_file_path = os.path.join('tests_data', 'my_gauss.h5') wf.store_hdf5(wf_hdf5_out_file_path) wf_out = wpg.Wavefront() wf_out.load_hdf5(wf_hdf5_out_file_path) return wf
def scale(self, wfr, iscx=1024, iscy=1024, ifov=800e-06): """ DEPR. narrow functionality for scaling a wavefront (ie the number of pixels) in the source plane :param wfr: wpg wfr strucutre :param isc: ideal scale :param ifov: ideal field of view :returns wfr: scaled wpg wfr structure """ nx, ny = wfr.params.Mesh.nx, wfr.params.Mesh.ny dx, dy = wfr.params.Mesh.xMax - wfr.params.Mesh.xMin, wfr.params.Mesh.yMax - wfr.params.Mesh.yMin scbl = Beamline() scbl.append( Aperture('r', 'a', 800e-06, 800e-06), propagation_parameters(dx / ifov, iscx / nx, dy / ifov, iscy / ny)) scbl.propagate(wfr) return wfr
delta = 4e-07 d2waist = (wav) / (np.arctan(.27 / 8) * np.pi) r = 75e-03 wfr = Wavefront( construct_gaussian(1024, 1024, 25, -15e-02, 15e-02, -15e-02, 15e-02, 3e-2, 3e-02, d2waist)) ### PLOT 1 plot_intensity_map(wfr) bl = Beamline() bl.append(Drift(1), propagation_parameters(1, 1, 1, 1)) bl.propagate(wfr) x = np.linspace(wfr.params.Mesh.xMin, wfr.params.Mesh.xMax, wfr.params.Mesh.nx) y = np.ones([wfr.params.Mesh.nx, wfr.params.Mesh.ny]) thickness = norm(cylinder_thickness(x, r, offset=0), lim=(0, 255)) sdir = "../../data/samples/cylinder_thickness.png" im = Image.fromarray(thickness * y) im = im.convert("L") im.save(sdir) np.save(sdir, thickness) rx, ry = wfr.get_spatial_resolution()