def propagate(self, wfr, propagation_parameters): """ Propagate wavefront through empty propagator, used for sampling and resizing wavefront """ beamline = wpg.srwlib.SRWLOptC([], propagation_parameters) srwl.PropagElecField(wfr._srwl_wf, beamline)
def propagate_run(ifname, ofname, optBL, bSaved=False): """ Propagate wavefront through a beamline and save the result (optionally). :param ifname: input hdf5 file name with wavefront to be propagated :param ofname: output hdf5 file name :param optBL: beamline :param bSaved: if True, save propagated wavefront in h5 file :return: propagated wavefront """ print_beamline(optBL) startTime = time.time() print('*****reading wavefront from h5 file...') w2 = Wavefront() w2.load_hdf5(ifname + '.h5') wfr = w2._srwl_wf print('*****propagating wavefront (with resizing)...') srwl.PropagElecField(wfr, optBL) mwf = Wavefront(wfr) print('[nx, ny, xmin, xmax, ymin, ymax]', get_mesh(mwf)) if bSaved: print('save hdf5:', ofname + '.h5') mwf.store_hdf5(ofname + '.h5') print('done') print('propagation lasted:', round((time.time() - startTime) / 6.) / 10., 'min') return wfr
def propagate(self, wfr): """ Propagate wavefront through beamline. :param wfr: Input wavefront (will be re-writed after propagation) :type wfr: wpg.wavefront.Wavefront """ for propagation_option in self.propagation_options: if all([ isinstance(o, srwlib.SRWLOpt) for o in propagation_option['optical_elements'] ]): srwl_beamline = srwlib.SRWLOptC( propagation_option['optical_elements'], propagation_option['propagation_parameters']) srwl.PropagElecField(wfr._srwl_wf, srwl_beamline) # fixing wf._srwl_wf.mesh.zStart bug for Drift # TODO: Try to fix it with _treat parameter for opt_element in propagation_option['optical_elements']: if isinstance(opt_element, srwlib.SRWLOptD): wfr.params.Mesh.zCoord = wfr.params.Mesh.zCoord + \ opt_element.L else: raise ValueError('Unknown type of propagators')
def propagate_sequential(self, wfr, outdir=None): """ Propagate sequentially through each optical element in beamline. :param wfr: Input wavefront (will be re-writed after propagation) :param outdir: save directory """ plotIntensity(wfr) print(outdir) if outdir is not None: if os.path.exists(outdir) == False: assert (ValueError, "Output Directory Could Not Be Found") else: pass if outdir is not None: wfr.write(outdir + "initialSource") plotIntensity(wfr, save=outdir + "source") for itr in range(len(self.propagation_options[0]['optical_elements'])): oe = self.propagation_options[0]['optical_elements'][itr] pp = self.propagation_options[0]['propagation_parameters'][itr] bl = srwlib.SRWLOptC([oe], [pp]) print(oe.name) srwl.PropagElecField(wfr._srwl_wf, bl) if oe.name is None: oe.name = "el{}".format(itr) if outdir is not None: plotIntensity(wfr, save=outdir + oe.name) with open(outdir + "beamline_parameters.json", 'w') as f: json.dump(self.params, f) elif outdir is None: plotIntensity(wfr)