def get_SRW_Wavefront(self, source_wavefront_parameters=WavefrontParameters()): self.__source_wavefront_parameters = source_wavefront_parameters source_wavefront_parameters.photon_energy_min = self.photon_energy source_wavefront_parameters.photon_energy_max = self.photon_energy source_wavefront_parameters.photon_energy_points = 1 mesh = source_wavefront_parameters.to_SRWRadMesh() GsnBm = SRWLGsnBm() #Gaussian Beam structure (just parameters) GsnBm.x = self.beam_center_at_waist_x GsnBm.y = self.beam_center_at_waist_y GsnBm.z = self.beam_center_at_waist_z GsnBm.xp = self.average_angle_at_waist_x GsnBm.yp = self.average_angle_at_waist_y GsnBm.avgPhotEn = self.photon_energy GsnBm.pulseEn = self.energy_per_pulse GsnBm.repRate = self.repetition_rate GsnBm.polar = self.polarization GsnBm.sigX = self.horizontal_sigma_at_waist GsnBm.sigY = self.vertical_sigma_at_waist GsnBm.sigT = self.pulse_duration GsnBm.mx = self.transverse_gauss_hermite_mode_order_x GsnBm.my = self.transverse_gauss_hermite_mode_order_y wfr = SRWWavefront() wfr.allocate(mesh.ne, mesh.nx, mesh.ny) wfr.mesh = mesh wfr.partBeam.partStatMom1.x = GsnBm.x wfr.partBeam.partStatMom1.y = GsnBm.y wfr.partBeam.partStatMom1.z = GsnBm.z wfr.partBeam.partStatMom1.xp = GsnBm.xp wfr.partBeam.partStatMom1.yp = GsnBm.yp arPrecPar = [ source_wavefront_parameters._wavefront_precision_parameters. _sampling_factor_for_adjusting_nx_ny ] srwl.CalcElecFieldGaussian(wfr, GsnBm, arPrecPar) return wfr
def send_data(self): try: congruence.checkEmptyString(self.file_name, "File Name") congruence.checkFile(self.file_name) native_srw_wavefront = load_hdf5_2_wfr(self.file_name, self.data_path) self.send( "SRWData", SRWData(srw_wavefront=SRWWavefront.decorateSRWWF( native_srw_wavefront))) except Exception as e: QMessageBox.critical(self, "Error", str(e.args[0]), QMessageBox.Ok)
def convert_wavefront(self): if not self.wavefront is None: try: srw_wavefront = SRWWavefront.fromGenericWavefront( self.wavefront) srw_wavefront.Rx = self.Rx srw_wavefront.dRx = self.dRx srw_wavefront.Ry = self.Ry srw_wavefront.dRy = self.dRy self.send("SRWData", SRWData(srw_wavefront=srw_wavefront)) except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception
def do_propagation(self, parameters=PropagationParameters()): wavefront = parameters.get_wavefront() is_generic_wavefront = isinstance(wavefront, GenericWavefront2D) if is_generic_wavefront: wavefront = SRWWavefront.fromGenericWavefront(wavefront) else: if not isinstance(wavefront, SRWWavefront): raise ValueError( "wavefront cannot be managed by this propagator") srw_oe_array = [] srw_pp_array = [] propagation_mode = PropagationManager.Instance().get_propagation_mode( SRW_APPLICATION) if propagation_mode == SRWPropagationMode.STEP_BY_STEP: self.add_optical_element(parameters, 0, srw_oe_array, srw_pp_array, wavefront) elif propagation_mode == SRWPropagationMode.WHOLE_BEAMLINE: srw_beamline = parameters.get_additional_parameter( "working_beamline") for index in range(srw_beamline.get_beamline_elements_number()): self.add_optical_element_from_beamline(srw_beamline, index, srw_oe_array, srw_pp_array, wavefront) else: raise ValueError( "Propagation Mode not supported by this Propagator") if len(srw_oe_array) > 0: optBL = SRWLOptC(srw_oe_array, srw_pp_array) srwl.PropagElecField(wavefront, optBL) if is_generic_wavefront: return wavefront.toGenericWavefront() else: return wavefront
def do_specific_progation(self, wavefront, propagation_distance, parameters, prefix="after"): is_generic_wavefront = isinstance(wavefront, GenericWavefront2D) if is_generic_wavefront: wavefront = SRWWavefront.fromGenericWavefront(wavefront) else: if not isinstance(wavefront, SRWWavefront): raise ValueError("wavefront cannot be managed by this propagator") # # propagation (simple wavefront drift # optBL = SRWLOptC([SRWLOptD(propagation_distance)], # drift space [self.__get_drift_wavefront_propagation_parameters(parameters, prefix)]) srwl.PropagElecField(wavefront, optBL) if is_generic_wavefront: return wavefront.toGenericWavefront() else: return wavefront
def get_SRW_Wavefront(self, source_wavefront_parameters=WavefrontParameters()): self.__source_wavefront_parameters = source_wavefront_parameters mesh = source_wavefront_parameters.to_SRWRadMesh() wfr = SRWWavefront() wfr.allocate(mesh.ne, mesh.nx, mesh.ny) wfr.mesh = mesh wfr.partBeam = self._electron_beam.to_SRWLPartBeam() srwl.CalcElecFieldSR( wfr, 0, self._magnetic_structure.get_SRWLMagFldC(), source_wavefront_parameters._wavefront_precision_parameters. to_SRW_array()) return wfr
def propagate_new_wavefront(self, trigger): try: if trigger and trigger.new_object == True: if trigger.has_additional_parameter("variable_name"): if self.input_srw_data is None: raise Exception("No Input Data") variable_name = trigger.get_additional_parameter( "variable_name").strip() variable_display_name = trigger.get_additional_parameter( "variable_display_name").strip() variable_value = trigger.get_additional_parameter( "variable_value") variable_um = trigger.get_additional_parameter( "variable_um") if "," in variable_name: variable_names = variable_name.split(",") for variable_name in variable_names: setattr(self, variable_name.strip(), variable_value) else: setattr(self, variable_name, variable_value) self.input_srw_data.get_srw_wavefront().setScanningData( SRWWavefront.ScanningData(variable_name, variable_value, variable_display_name, variable_um)) self.propagate_wavefront() except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception
def __init__(self, srw_beamline=SRWBeamline(), srw_wavefront=SRWWavefront()): super().__init__() self.__srw_beamline = srw_beamline self.__srw_wavefront = srw_wavefront
# # oasys plots # from srxraylib.plot.gol import plot_image, plot from wofrysrw.propagator.wavefront2D.srw_wavefront import SRWWavefront import copy self = wfr w_srw_oasys = SRWWavefront(_arEx=copy.deepcopy(self.arEx), _arEy=copy.deepcopy(self.arEy), _typeE=self.numTypeElFld, _eStart=self.mesh.eStart, _eFin=self.mesh.eFin, _ne=self.mesh.ne, _xStart=self.mesh.xStart, _xFin=self.mesh.xFin, _nx=self.mesh.nx, _yStart=self.mesh.yStart, _yFin=self.mesh.yFin, _ny=self.mesh.ny, _zStart=self.mesh.zStart, _partBeam=self.partBeam) w_wofry = w_srw_oasys.toGenericWavefront() x = w_wofry.get_coordinate_x() y = w_wofry.get_coordinate_y() intensity = w_wofry.get_intensity() print("Total intensity: %g photons" % (intensity.sum() * 1e6 * (x[1] - x[0]) * (y[1] - y[0])))
def propagate_wavefront(self): try: self.progressBarInit() if self.input_srw_data is None: raise Exception("No Input Data") self.check_data() input_wavefront = self.input_srw_data.get_srw_wavefront( ).duplicate() srw_beamline = self.input_srw_data.get_srw_beamline().duplicate() optical_element = srw_beamline.get_beamline_element_at( -1).get_optical_element() coordinates = srw_beamline.get_beamline_element_at( -1).get_coordinates() if not isinstance(optical_element, SRWCRL): raise ValueError( "Thickness Error Phase Shift should be connected to a CRL optical element" ) if coordinates.q() != 0.0: raise ValueError( "Thickness Error Phase Shift should be applied on unpropagated wavefronts: put 'q' value to 0.0 in the previous optical element" ) crl_delta = optical_element.delta crl_w_mirr_2D_values = [ OWThicknessErrorPhaseShift.h5_readsurface(thickness_error_file) for thickness_error_file in self.crl_error_profiles ] # TO WOFRY generic_wavefront = input_wavefront.toGenericWavefront() for thickness_error_profile in crl_w_mirr_2D_values: phase_shift = OWThicknessErrorPhaseShift.get_crl_phase_shift( thickness_error_profile, crl_delta, generic_wavefront, self.crl_scaling_factor) generic_wavefront.add_phase_shift(phase_shift, Polarization.SIGMA) generic_wavefront.add_phase_shift(phase_shift, Polarization.PI) # TO SRW output_wavefront = SRWWavefront.fromGenericWavefront( generic_wavefront) output_wavefront.Rx = input_wavefront.Rx output_wavefront.Ry = input_wavefront.Ry output_wavefront.dRx = input_wavefront.dRx output_wavefront.dRy = input_wavefront.dRy output_wavefront.xc = input_wavefront.xc output_wavefront.yc = input_wavefront.yc output_wavefront.avgPhotEn = input_wavefront.avgPhotEn output_wavefront.presCA = input_wavefront.presCA output_wavefront.presFT = input_wavefront.presFT output_wavefront.unitElFld = input_wavefront.unitElFld output_wavefront.arElecPropMatr = copy.deepcopy( input_wavefront.arElecPropMatr) output_wavefront.arMomX = copy.deepcopy(input_wavefront.arMomX) output_wavefront.arMomY = copy.deepcopy(input_wavefront.arMomY) output_wavefront.arWfrAuxData = copy.deepcopy( input_wavefront.arWfrAuxData) output_wavefront.partBeam = copy.deepcopy(input_wavefront.partBeam) output_wavefront.setScanningData( input_wavefront.scanned_variable_data) output_srw_data = SRWData(srw_beamline=srw_beamline, srw_wavefront=output_wavefront) self.progressBarSet(50) self.initializeTabs() tickets = [] self.run_calculation_for_plots(output_wavefront=output_wavefront, tickets=tickets, progress_bar_value=50) self.plot_results(tickets, 80) self.progressBarFinished() self.setStatusMessage("") self.send("SRWData", output_srw_data) self.send("Trigger", TriggerIn(new_object=True)) except Exception as e: QMessageBox.critical(self, "Error", str(e.args[0]), QMessageBox.Ok) self.setStatusMessage("") self.progressBarFinished() if self.IS_DEVELOP: raise e