def setFootprintBeam(self, footprint): if not footprint is None: beam = footprint[1] if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam self.x_column_index = 1 self.x_range = 0 self.y_column_index = 0 self.y_range = 0 self.image_plane = 0 self.set_XRange() self.set_YRange() self.set_ImagePlane() if self.is_automatic_run: self.plot_results() else: QMessageBox.critical( self, "Error", "Data not displayable: No good rays, bad content, bad limits or axes", QMessageBox.Ok)
def setFlux(self, exchange_data): if not exchange_data is None: if exchange_data.get_program_name() == "XOPPY" and exchange_data.get_widget_name() == "BM": if exchange_data.get_content("is_log_plot") == 1: raise Exception("Logarithmic X scale of Xoppy Energy distribution not supported") elif exchange_data.get_content("calculation_type") == 0 and (exchange_data.get_content("psi") == 0 or exchange_data.get_content("psi") == 2): index_flux = 5 else: raise Exception("Xoppy result is not an Flux vs Energy distribution integrated in a rectangular space") else: raise Exception("Exchange data are not from a XOPPY BM widget") spectrum = exchange_data.get_content("xoppy_data") self.initial_flux = spectrum[:, index_flux] self.initial_energy = spectrum[:, 0] initial_energy_step = self.initial_energy[1] - self.initial_energy[0] self.total_initial_power = self.initial_flux.sum() * 1e3 * codata.e * initial_energy_step print("Total Initial Power from XOPPY", self.total_initial_power) if not self.input_beam is None: if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): self.plot_results() else: self.initial_flux = None self.initial_energy = None
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.run_hybrid()
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.run_hybrid()
def traceOpticalElement(self): try: self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.checkFields() shadow_oe = ShadowOpticalElement.create_screen_slit() self.populateFields(shadow_oe) self.doSpecificSetting(shadow_oe) self.progressBarSet(10) self.completeOperations(shadow_oe) else: raise Exception("Input Beam with no good rays") else: raise Exception("Empty Input Beam") except Exception as exception: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", str(exception), QtGui.QMessageBox.Ok) self.error_id = self.error_id + 1 self.error(self.error_id, "Exception occurred: " + str(exception)) self.progressBarFinished()
def setBeam(self, input_beam): self.cb_rays.setEnabled(True) if not input_beam is None: if not input_beam.scanned_variable_data is None and input_beam.scanned_variable_data.has_additional_parameter("total_power"): self.input_beam = input_beam self.total_power = self.input_beam.scanned_variable_data.get_additional_parameter("total_power") if self.energy_min is None: self.energy_min = self.input_beam.scanned_variable_data.get_scanned_variable_value() self.cumulated_total_power = self.total_power else: self.cumulated_total_power += self.total_power self.energy_step = self.input_beam.scanned_variable_data.get_additional_parameter("photon_energy_step") self.energy_max = self.input_beam.scanned_variable_data.get_scanned_variable_value() if self.input_beam.scanned_variable_data.has_additional_parameter("is_footprint"): if self.input_beam.scanned_variable_data.get_additional_parameter("is_footprint"): self.cb_rays.setEnabled(False) self.rays = 0 # transmitted, absorbed doesn't make sense since is precalculated by footprint object else: self.cb_rays.setEnabled(True) if ShadowCongruence.checkEmptyBeam(input_beam): if ShadowCongruence.checkGoodBeam(input_beam): self.plot_results()
def traceOpticalElement(self): try: self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.checkFields() shadow_oe = ShadowOpticalElement.create_screen_slit() self.populateFields(shadow_oe) self.doSpecificSetting(shadow_oe) self.progressBarSet(10) self.completeOperations(shadow_oe) else: raise Exception("Input Beam with no good rays") else: raise Exception("Empty Input Beam") except Exception as exception: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", str(exception), QtGui.QMessageBox.Ok) self.error_id = self.error_id + 1 self.error(self.error_id, "Exception occurred: " + str(exception)) self.progressBarFinished()
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): proceed = True if not ShadowCongruence.checkGoodBeam(beam): if not ConfirmDialog.confirmed( parent=self, message="Beam contains bad values, skip it?"): proceed = False if proceed: scanned_variable_data = beam.scanned_variable_data go = numpy.where(beam._beam.rays[:, 9] == 1) nr_good = len(beam._beam.rays[go]) nr_total = len(beam._beam.rays) nr_lost = nr_total - nr_good intensity = beam._beam.histo1(1, nolost=1, ref=23)['intensity'] self.current_number_of_rays += nr_good self.current_intensity += intensity self.le_current_intensity.setText("{:10.3f}".format( self.current_intensity)) self.current_number_of_lost_rays += nr_lost self.current_number_of_total_rays += nr_total if (self.kind_of_accumulation == 0 and self.current_number_of_rays <= self.number_of_accumulated_rays) or \ (self.kind_of_accumulation == 1 and self.current_intensity <= self.number_of_accumulated_rays): if self.keep_go_rays == 1: beam._beam.rays = copy.deepcopy(beam._beam.rays[go]) if not self.input_beam is None: self.input_beam = ShadowBeam.mergeBeams( self.input_beam, beam) else: beam._beam.rays[:, 11] = numpy.arange( 1, len(beam._beam.rays) + 1, 1) # ray_index self.input_beam = beam self.input_beam.setScanningData(scanned_variable_data) self.send("Trigger", TriggerIn(new_object=True)) else: if self.is_automatic_run: self.sendSignal() self.current_number_of_rays = 0 self.current_intensity = 0.0 self.current_number_of_lost_rays = 0 self.current_number_of_total_rays = 0 self.input_beam = None else: QtWidgets.QMessageBox.critical( self, "Error", "Number of Accumulated Rays reached, please push \'Send Signal\' button", QtWidgets.QMessageBox.Ok)
def plot_results(self, beam_out, footprint_beam=None, progressBarValue=80): if not self.view_type == 2: if ShadowCongruence.checkEmptyBeam(beam_out): if ShadowCongruence.checkGoodBeam(beam_out): self.view_type_combo.setEnabled(False) ShadowPlot.set_conversion_active(self.getConversionActive()) if self.isFootprintEnabled() and footprint_beam is None: footprint_beam = ShadowBeam() if beam_out._oe_number < 10: footprint_beam.loadFromFile(file_name="mirr.0" + str(beam_out._oe_number)) else: footprint_beam.loadFromFile(file_name="mirr." + str(beam_out._oe_number)) variables = self.getVariablestoPlot() titles = self.getTitles() xtitles = self.getXTitles() ytitles = self.getYTitles() xums = self.getXUM() yums = self.getYUM() try: if self.view_type == 1: self.plot_xy_fast(beam_out, progressBarValue + 4, variables[0][0], variables[0][1], plot_canvas_index=0, title=titles[0], xtitle=xtitles[0], ytitle=ytitles[0]) self.plot_xy_fast(beam_out, progressBarValue + 8, variables[1][0], variables[1][1], plot_canvas_index=1, title=titles[1], xtitle=xtitles[1], ytitle=ytitles[1]) self.plot_xy_fast(beam_out, progressBarValue + 12, variables[2][0], variables[2][1], plot_canvas_index=2, title=titles[2], xtitle=xtitles[2], ytitle=ytitles[2]) self.plot_xy_fast(beam_out, progressBarValue + 16, variables[3][0], variables[3][1], plot_canvas_index=3, title=titles[3], xtitle=xtitles[3], ytitle=ytitles[3]) self.plot_histo_fast(beam_out, progressBarValue + 20, variables[4], plot_canvas_index=4, title=titles[4], xtitle=xtitles[4], ytitle=ytitles[4]) if self.isFootprintEnabled(): self.plot_xy_fast(footprint_beam, progressBarValue + 20, 2, 1, plot_canvas_index=5, title="Footprint", xtitle="Y [" + self.workspace_units_label +"]", ytitle="X [" + self.workspace_units_label +"]", is_footprint=True) elif self.view_type == 0: self.plot_xy(beam_out, progressBarValue + 4, variables[0][0], variables[0][1], plot_canvas_index=0, title=titles[0], xtitle=xtitles[0], ytitle=ytitles[0], xum=xums[0], yum=yums[0]) self.plot_xy(beam_out, progressBarValue + 8, variables[1][0], variables[1][1], plot_canvas_index=1, title=titles[1], xtitle=xtitles[1], ytitle=ytitles[1], xum=xums[1], yum=yums[1]) self.plot_xy(beam_out, progressBarValue + 12, variables[2][0], variables[2][1], plot_canvas_index=2, title=titles[2], xtitle=xtitles[2], ytitle=ytitles[2], xum=xums[2], yum=yums[2]) self.plot_xy(beam_out, progressBarValue + 16, variables[3][0], variables[3][1], plot_canvas_index=3, title=titles[3], xtitle=xtitles[3], ytitle=ytitles[3], xum=xums[3], yum=yums[3]) self.plot_histo(beam_out, progressBarValue + 20, variables[4], plot_canvas_index=4, title=titles[4], xtitle=xtitles[4], ytitle=ytitles[4], xum=xums[4] ) if self.isFootprintEnabled(): self.plot_xy(footprint_beam, progressBarValue + 20, 2, 1, plot_canvas_index=5, title="Footprint", xtitle="Y [" + self.workspace_units_label +"]", ytitle="X [" + self.workspace_units_label +"]", xum=("Y [" + self.workspace_units_label +"]"), yum=("X [" + self.workspace_units_label +"]"), is_footprint=True) except Exception as e: self.view_type_combo.setEnabled(True) raise Exception("Data not plottable: No good rays or bad content\nexception: " + str(e)) self.view_type_combo.setEnabled(True) else: raise Exception("Beam with no good rays") else: raise Exception("Empty Beam") self.plotted_beam = beam_out
def plot_results(self, beam_out, progressBarValue=80): if not self.view_type == 2: if ShadowCongruence.checkEmptyBeam(beam_out): if ShadowCongruence.checkGoodBeam(beam_out): self.view_type_combo.setEnabled(False) ShadowPlot.set_conversion_active(self.getConversionActive()) if self.isFootprintEnabled(): beam_foot_print = ShadowBeam() if beam_out._oe_number < 10: beam_foot_print.loadFromFile(file_name="mirr.0" + str(beam_out._oe_number)) else: beam_foot_print.loadFromFile(file_name="mirr." + str(beam_out._oe_number)) variables = self.getVariablestoPlot() titles = self.getTitles() xtitles = self.getXTitles() ytitles = self.getYTitles() xums = self.getXUM() yums = self.getYUM() try: if self.view_type == 1: self.plot_xy_fast(beam_out, progressBarValue + 4, variables[0][0], variables[0][1], plot_canvas_index=0, title=titles[0], xtitle=xtitles[0], ytitle=ytitles[0]) self.plot_xy_fast(beam_out, progressBarValue + 8, variables[1][0], variables[1][1], plot_canvas_index=1, title=titles[1], xtitle=xtitles[1], ytitle=ytitles[1]) self.plot_xy_fast(beam_out, progressBarValue + 12, variables[2][0], variables[2][1], plot_canvas_index=2, title=titles[2], xtitle=xtitles[2], ytitle=ytitles[2]) self.plot_xy_fast(beam_out, progressBarValue + 16, variables[3][0], variables[3][1], plot_canvas_index=3, title=titles[3], xtitle=xtitles[3], ytitle=ytitles[3]) self.plot_histo_fast(beam_out, progressBarValue + 20, variables[4], plot_canvas_index=4, title=titles[4], xtitle=xtitles[4], ytitle=ytitles[4]) if self.isFootprintEnabled(): self.plot_xy_fast(beam_foot_print, progressBarValue + 20, 2, 1, plot_canvas_index=5, title="Footprint", xtitle="Y [" + self.workspace_units_label +"]", ytitle="X [" + self.workspace_units_label +"]", is_footprint=True) elif self.view_type == 0: self.plot_xy(beam_out, progressBarValue + 4, variables[0][0], variables[0][1], plot_canvas_index=0, title=titles[0], xtitle=xtitles[0], ytitle=ytitles[0], xum=xums[0], yum=yums[0]) self.plot_xy(beam_out, progressBarValue + 8, variables[1][0], variables[1][1], plot_canvas_index=1, title=titles[1], xtitle=xtitles[1], ytitle=ytitles[1], xum=xums[1], yum=yums[1]) self.plot_xy(beam_out, progressBarValue + 12, variables[2][0], variables[2][1], plot_canvas_index=2, title=titles[2], xtitle=xtitles[2], ytitle=ytitles[2], xum=xums[2], yum=yums[2]) self.plot_xy(beam_out, progressBarValue + 16, variables[3][0], variables[3][1], plot_canvas_index=3, title=titles[3], xtitle=xtitles[3], ytitle=ytitles[3], xum=xums[3], yum=yums[3]) self.plot_histo(beam_out, progressBarValue + 20, variables[4], plot_canvas_index=4, title=titles[4], xtitle=xtitles[4], ytitle=ytitles[4], xum=xums[4] ) if self.isFootprintEnabled(): self.plot_xy(beam_foot_print, progressBarValue + 20, 2, 1, plot_canvas_index=5, title="Footprint", xtitle="Y [" + self.workspace_units_label +"]", ytitle="X [" + self.workspace_units_label +"]", xum=("Y [" + self.workspace_units_label +"]"), yum=("X [" + self.workspace_units_label +"]"), is_footprint=True) except Exception: self.view_type_combo.setEnabled(True) raise Exception("Data not plottable: No good rays or bad content") self.view_type_combo.setEnabled(True) else: raise Exception("Beam with no good rays") else: raise Exception("Empty Beam") self.plotted_beam = beam_out
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam( beam[0]) and ShadowCongruence.checkGoodBeam(beam[0]): if beam[0].scanned_variable_data and beam[ 0].scanned_variable_data.has_additional_parameter( "total_power"): self.input_beam = beam[0] self.footprint_beam = beam[1] self.calculate_footprint()
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.calculate() else: QtGui.QMessageBox.critical(self, "Error", "Data not displayable: No good rays or bad content", QtGui.QMessageBox.Ok)
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.plot_results() else: QtWidgets.QMessageBox.critical(self, "Error", "Data not displayable: No good rays, bad content, bad limits or axes", QtWidgets.QMessageBox.Ok)
def setBeam(self, beam): try: if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.calculate_flux() except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.write_file() else: QtWidgets.QMessageBox.critical(self, "Error", "No good rays or bad content", QtWidgets.QMessageBox.Ok)
def setBeam(self, beam): if not beam is None: if ShadowCongruence.checkEmptyBeam( beam[0]) and ShadowCongruence.checkGoodBeam(beam[0]): self.input_beam = beam[0] self.footprint_beam = beam[1] self.calculate_footprint() else: self.input_beam = None self.footprint_beam = None
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.write_file() else: QtGui.QMessageBox.critical(self, "Error", "No good rays or bad content", QtGui.QMessageBox.Ok)
def setBeam(self, beam): self.input_beam = None if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.generate_energy_spectrum() else: QtGui.QMessageBox.critical(self, "Error", "Input Beam not usable: No good rays or bad content", QtGui.QMessageBox.Ok)
def setBeam10(self, beam): self.le_weight_input_beam10.setEnabled(False) self.input_beam10 = None if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam10 = beam if self.use_weights==1: self.le_weight_input_beam10.setEnabled(True) else: QtWidgets.QMessageBox.critical(self, "Error", "Data #10 not displayable: No good rays or bad content", QtWidgets.QMessageBox.Ok)
def setBeam2(self, beam): self.input_beam2 = None if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam2 = beam if self.is_automatic_run: self.calculate_rotation_angle() else: QtGui.QMessageBox.critical(self, "Error", "Data #2 not usable: No good rays or bad content", QtGui.QMessageBox.Ok)
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.calculate() else: QtWidgets.QMessageBox.critical( self, "Error", "Data not displayable: No good rays or bad content", QtWidgets.QMessageBox.Ok)
def setBeam10(self, beam): self.le_weight_input_beam10.setEnabled(False) self.input_beam10 = None if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam10 = beam if self.use_weights==1: self.le_weight_input_beam10.setEnabled(True) else: QtGui.QMessageBox.critical(self, "Error", "Data #10 not displayable: No good rays or bad content", QtGui.QMessageBox.Ok)
def setBeam1(self, beam): self.input_beam1 = None if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam1 = beam if self.is_automatic_run: self.calculate_rotation_angle() else: QtGui.QMessageBox.critical( self, "Error", "Data #1 not usable: No good rays or bad content", QtGui.QMessageBox.Ok)
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): if self.keep_result == 1 and not self.input_beam is None: self.input_beam = ShadowBeam.mergeBeams(self.input_beam, beam) else: self.input_beam = beam if self.is_automatic_run: self.plot_results() else: QtGui.QMessageBox.critical(self, "Error", "Data not displayable: No good rays, bad content, bad limits or axes", QtGui.QMessageBox.Ok)
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): proceed = True if not ShadowCongruence.checkGoodBeam(beam): if not ConfirmDialog.confirmed(parent=self, message="Beam contains bad values, skip it?"): proceed = False if proceed: go = numpy.where(beam._beam.rays[:, 9] == 1) nr_good = len(beam._beam.rays[go]) nr_total = len(beam._beam.rays) nr_lost = nr_total - nr_good intensity = beam._beam.histo1(1, nolost=1, ref=23)['intensity'] self.current_number_of_rays += nr_good self.current_intensity += intensity self.le_current_intensity.setText("{:10.3f}".format(self.current_intensity)) self.current_number_of_lost_rays += nr_lost self.current_number_of_total_rays += nr_total if (self.kind_of_accumulation == 0 and self.current_number_of_rays <= self.number_of_accumulated_rays) or \ (self.kind_of_accumulation == 1 and self.current_intensity <= self.number_of_accumulated_rays): if self.keep_go_rays == 1: beam._beam.rays = copy.deepcopy(beam._beam.rays[go]) if not self.input_beam is None: self.input_beam = ShadowBeam.mergeBeams(self.input_beam, beam) else: beam._beam.rays[:, 11] = numpy.arange(1, len(beam._beam.rays) + 1, 1) # ray_index self.input_beam = beam self.send("Trigger", ShadowTriggerIn(new_beam=True)) else: if self.is_automatic_run: self.sendSignal() self.current_number_of_rays = 0 self.current_intensity = 0.0 self.current_number_of_lost_rays = 0 self.current_number_of_total_rays = 0 self.input_beam = None else: QtGui.QMessageBox.critical(self, "Error", "Number of Accumulated Rays reached, please push \'Send Signal\' button", QtGui.QMessageBox.Ok)
def setBeam(self, beam): send_footprint_beam = QSettings().value("output/send-footprint", 0, int) == 1 if send_footprint_beam and isinstance(beam, list): self.input_beam = beam[1] elif ShadowCongruence.checkEmptyBeam( beam) and ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam else: QtWidgets.QMessageBox.critical(self, "Error", "No good rays or bad content", QtWidgets.QMessageBox.Ok) return if self.is_automatic_run: self.write_file()
def setBeam(self, beam): if not beam is None: send_footprint_beam = QSettings().value("output/send-footprint", 0, int) == 1 if send_footprint_beam and isinstance(beam, list): footprint_beam = beam[1] if ShadowCongruence.checkEmptyBeam(footprint_beam): if ShadowCongruence.checkGoodBeam(footprint_beam): self.input_beam = footprint_beam self.x_column_index = 1 self.x_range = 0 self.y_column_index = 0 self.y_range = 0 self.image_plane = 0 self.set_XRange() self.set_YRange() self.set_ImagePlane() if self.is_automatic_run: self.plot_results() else: QMessageBox.critical( self, "Error", "Data not displayable: No good rays, bad content, bad limits or axes", QMessageBox.Ok) elif isinstance(beam, ShadowBeam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): self.input_beam = beam if self.is_automatic_run: self.plot_results() else: QMessageBox.critical( self, "Error", "Data not displayable: No good rays, bad content, bad limits or axes", QMessageBox.Ok) else: QMessageBox.critical( self, "Error", "Data not displayable: input type not recognized (must be Shadow Beam or Footprint)", QMessageBox.Ok)
def setBeam(self, beam): self.not_interactive = self.check_not_interactive_conditions(beam) if ShadowCongruence.checkEmptyBeam(beam): self.input_beam = beam if self.is_automatic_run: self.traceOpticalElement()
def setBeam(self, beam): self.onReceivingInput() if ShadowCongruence.checkEmptyBeam(beam): self.input_beam = beam if self.is_automatic_run: self.traceOpticalElement()
def setBeam(self, beam): self.onReceivingInput() if ShadowCongruence.checkEmptyBeam(beam): self.input_beam = beam if self.is_automatic_run: self.reconstructWavefront()
def setBeam(self, input_beam): self.cb_rays.setEnabled(True) if not input_beam is None: self.input_beam = input_beam.duplicate() if self.input_beam.scanned_variable_data and self.input_beam.scanned_variable_data.has_additional_parameter("is_footprint"): if self.input_beam.scanned_variable_data.get_additional_parameter("is_footprint"): self.cb_rays.setEnabled(False) self.rays = 0 # transmitted, absorbed doesn't make sense since is precalculated by footprint object else: self.cb_rays.setEnabled(True) if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): if not self.initial_flux is None: self.plot_results()
def setBeam(self, beam): self.onReceivingInput() if ShadowCongruence.checkEmptyBeam(beam): self.input_beam = beam if self.is_automatic_run: self.reconstructWavefront()
def _set_input_shadow_beam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): print("<><> CONVERTER has received GOOD Shadow BEAM)") self._input_available = True self.incoming_shadow_beam = beam self.send_shadow_beam(beam) # # translate # photon_bunch = self.from_shadow_beam_to_photon_bunch() self.send_photon_bunch(photon_bunch) else: QtGui.QMessageBox.critical( self, "Error", "Data not displayable: No good rays or bad content", QtGui.QMessageBox.Ok)
def setBeam(self, beam): self.onReceivingInput() if ShadowCongruence.checkEmptyBeam(beam): self.input_beam = beam if self.is_automatic_run: self.traceOpticalElement()
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): output_beam = beam.duplicate(history=True) good = numpy.where(output_beam._beam.rays[:, 9] == 1) output_beam._beam.rays = copy.deepcopy( output_beam._beam.rays[good]) self.send("Beam", output_beam) self.send("Trigger", TriggerIn(new_object=True))
def write_file(self): self.setStatusMessage("") try: if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): if congruence.checkFileName(self.beam_file_name): self.input_beam.writeToFile(self.beam_file_name) path, file_name = os.path.split(self.beam_file_name) self.setStatusMessage("File Out: " + file_name) self.send("Beam", self.input_beam) else: QtGui.QMessageBox.critical(self, "Error", "No good rays or bad content", QtGui.QMessageBox.Ok) except Exception as exception: QtGui.QMessageBox.critical(self, "Error", str(exception), QtGui.QMessageBox.Ok)
def write_file(self): self.setStatusMessage("") try: if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): if congruence.checkFileName(self.beam_file_name): self.input_beam.writeToFile(self.beam_file_name) path, file_name = os.path.split(self.beam_file_name) self.setStatusMessage("File Out: " + file_name) self.send("Beam", self.input_beam) else: QtWidgets.QMessageBox.critical(self, "Error", "No good rays or bad content", QtWidgets.QMessageBox.Ok) except Exception as exception: QtWidgets.QMessageBox.critical(self, "Error", str(exception), QtWidgets.QMessageBox.Ok)
def traceOpticalElement(self): try: #self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.checkFields() shadow_oe = ShadowCompoundOpticalElement.create_compound_oe( workspace_units_to_cm=self.workspace_units_to_cm) self.populateFields(shadow_oe) self.doSpecificSetting(shadow_oe) self.progressBarSet(10) self.completeOperations(shadow_oe) else: if self.not_interactive: self.sendEmptyBeam() else: raise Exception("Input Beam with no good rays") else: if self.not_interactive: self.sendEmptyBeam() else: raise Exception("Empty Input Beam") except Exception as exception: QtWidgets.QMessageBox.critical(self, "Error", str(exception), QtWidgets.QMessageBox.Ok) #self.error_id = self.error_id + 1 #self.error(self.error_id, "Exception occurred: " + str(exception)) if self.IS_DEVELOP: raise exception self.progressBarFinished()
def plot_results(self): try: sys.stdout = EmittingStream(textWritten=self.writeStdOut) if ShadowCongruence.checkEmptyBeam(self.input_beam): self.number_of_bins = congruence.checkStrictlyPositiveNumber(self.number_of_bins, "Number of Bins") self.plot_xy(self.x_column_index+1, self.y_column_index+1) time.sleep(0.1) # prevents a misterious dead lock in the Orange cycle when refreshing the histogram except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception
def plot_results(self): try: plotted = False sys.stdout = EmittingStream(textWritten=self.writeStdOut) if self.trace_shadow: grabber = TTYGrabber() grabber.start() if ShadowCongruence.checkEmptyBeam(self.input_beam): ShadowPlot.set_conversion_active(self.getConversionActive()) # self.number_of_bins = congruence.checkStrictlyPositiveNumber(self.number_of_bins, "Number of Bins") x, y, c, auto_x_title, auto_y_title, xum, yum = self.get_titles( ) self.plot_scatter(x, y, c, title=self.title, xtitle=auto_x_title, ytitle=auto_y_title, xum=xum, yum=yum) plotted = True if self.trace_shadow: grabber.stop() for row in grabber.ttyData: self.writeStdOut(row) time.sleep( 0.5 ) # prevents a misterious dead lock in the Orange cycle when refreshing the histogram return plotted except Exception as exception: QtWidgets.QMessageBox.critical(self, "Error", str(exception), QtWidgets.QMessageBox.Ok) if self.IS_DEVELOP: raise exception return False
def plot_xy(self, var_x, var_y): beam_to_plot = self.input_beam.duplicate() if ShadowCongruence.checkGoodBeam(beam_to_plot): if self.image_plane == 1: new_shadow_beam = self.input_beam.duplicate(history=False) if self.image_plane_rel_abs_position == 1: # relative dist = self.image_plane_new_position else: # absolute if self.input_beam.historySize() == 0: historyItem = None else: historyItem = self.input_beam.getOEHistory(oe_number=self.input_beam._oe_number) if historyItem is None: image_plane = 0.0 elif self.input_beam._oe_number == 0: image_plane = 0.0 else: image_plane = historyItem._shadow_oe_end._oe.T_IMAGE dist = self.image_plane_new_position - image_plane self.retrace_beam(new_shadow_beam, dist) beam_to_plot = new_shadow_beam else: # no good rays in the region of interest: creates a 0 power step with 1 good ray beam_to_plot._beam.rays[0, 9] = 1 # convert to good rays beam_to_plot._beam.rays[:, 6] = 0.0 beam_to_plot._beam.rays[:, 7] = 0.0 beam_to_plot._beam.rays[:, 8] = 0.0 beam_to_plot._beam.rays[:, 15] = 0.0 beam_to_plot._beam.rays[:, 16] = 0.0 beam_to_plot._beam.rays[:, 17] = 0.0 xrange, yrange = self.get_ranges() self.replace_fig(beam_to_plot, var_x, var_y, xrange=xrange, yrange=yrange, nbins_h=int(self.number_of_bins), nbins_v=int(self.number_of_bins_v), nolost=self.rays+1)
def plot_results(self): #self.error(self.error_id) try: plotted = False sys.stdout = EmittingStream(textWritten=self.writeStdOut) if self.trace_shadow: grabber = TTYGrabber() grabber.start() if ShadowCongruence.checkEmptyBeam(self.input_beam): ShadowPlot.set_conversion_active(self.getConversionActive()) self.number_of_bins = congruence.checkStrictlyPositiveNumber(self.number_of_bins, "Number of Bins") x, y, auto_x_title, auto_y_title, xum, yum = self.get_titles() self.plot_xy(x, y, title=self.title, xtitle=auto_x_title, ytitle=auto_y_title, xum=xum, yum=yum) plotted = True if self.trace_shadow: grabber.stop() for row in grabber.ttyData: self.writeStdOut(row) time.sleep(0.5) # prevents a misterious dead lock in the Orange cycle when refreshing the histogram return plotted except Exception as exception: QtGui.QMessageBox.critical(self, "Error", str(exception), QtGui.QMessageBox.Ok) #self.error_id = self.error_id + 1 #self.error(self.error_id, "Exception occurred: " + str(exception)) return False
def traceOpticalElement(self): try: self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.progressBarSet(10) self.checkFields() self.setStatusMessage("Running SHADOW") if self.trace_shadow: grabber = TTYGrabber() grabber.start() self.progressBarSet(50) ########################################### # TODO: TO BE ADDED JUST IN CASE OF BROKEN # ENVIRONMENT: MUST BE FOUND A PROPER WAY # TO TEST SHADOW self.fixWeirdShadowBug() ########################################### shadow_oe_1 = ShadowOpticalElement.create_screen_slit() self.populateFields_1(shadow_oe_1) beam_out = ShadowBeam.traceFromOE(self.input_beam, shadow_oe_1) self.adjust_first_divergence(beam_out) self.progressBarSet(60) shadow_oe_2 = ShadowOpticalElement.create_screen_slit() self.populateFields_2(shadow_oe_2) beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_2) self.adjust_second_divergence_and_intensity(beam_out) self.progressBarSet(70) shadow_oe_3 = ShadowOpticalElement.create_screen_slit() self.populateFields_3(shadow_oe_3) beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_3) if self.trace_shadow: grabber.stop() for row in grabber.ttyData: self.writeStdOut(row) self.setStatusMessage("Plotting Results") self.plot_results(beam_out) self.setStatusMessage("") self.send("Beam", beam_out) self.send("Trigger", TriggerIn(new_object=True)) else: raise Exception("Input Beam with no good rays") else: raise Exception("Empty Input Beam") except Exception as exception: QtWidgets.QMessageBox.critical(self, "QMessageBox.critical()", str(exception), QtWidgets.QMessageBox.Ok) self.error_id = self.error_id + 1 self.error(self.error_id, "Exception occurred: " + str(exception)) self.progressBarFinished()
def setBeam(self, beam): if ShadowCongruence.checkEmptyBeam(beam): if ShadowCongruence.checkGoodBeam(beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.input_beam = beam optical_element_list_start = [] optical_element_list_end = [] self.sysInfo.setText("") self.mirInfo.setText("") self.sourceInfo.setText("") self.distancesSummary.setText("") self.pythonScript.setText("") for history_element in self.input_beam.getOEHistory(): if not history_element._shadow_source_start is None: optical_element_list_start.append(history_element._shadow_source_start.src) elif not history_element._shadow_oe_start is None: optical_element_list_start.append(history_element._shadow_oe_start._oe) if not history_element._shadow_source_end is None: optical_element_list_end.append(history_element._shadow_source_end.src) elif not history_element._shadow_oe_end is None: optical_element_list_end.append(history_element._shadow_oe_end._oe) if not history_element._shadow_source_end is None: try: self.sourceInfo.append(history_element._shadow_source_end.src.sourcinfo()) except: self.sourceInfo.append("Problem in calculating Source Info:\n" + str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1])) elif not history_element._shadow_oe_end is None: try: if isinstance(history_element._shadow_oe_end._oe, CompoundOE): self.mirInfo.append(history_element._shadow_oe_end._oe.mirinfo()) else: self.mirInfo.append(history_element._shadow_oe_end._oe.mirinfo(title="O.E. #" + str(history_element._oe_number))) except: self.sourceInfo.append("Problem in calculating Mir Info for O.E. #:" + str(history_element._oe_number) + "\n" + str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1])) coe_end = ShadowCompoundOpticalElement.create_compound_oe(workspace_units_to_cm=self.workspace_units_to_cm) for oe in optical_element_list_end: coe_end._oe.append(oe) try: self.sysInfo.setText(coe_end._oe.sysinfo()) except: self.distancesSummary.setText("Problem in calculating SysInfo:\n" + str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1])) try: self.distancesSummary.setText(coe_end._oe.info()) except: self.distancesSummary.setText("Problem in calculating Distance Summary:\n" + str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1])) try: self.pythonScript.setText(ST.make_python_script_from_list(optical_element_list_start)) except: self.pythonScript.setText("Problem in writing python script:\n" + str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1])) else: QtGui.QMessageBox.critical(self, "Error", "Data not displayable: No good rays or bad content", QtGui.QMessageBox.Ok)
def calculate(self): if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): beam_to_analize = self.input_beam._beam if self.image_plane == 1: new_shadow_beam = self.input_beam.duplicate(history=False) dist = 0.0 if self.image_plane_rel_abs_position == 1: # relative dist = self.image_plane_new_position else: # absolute historyItem = self.input_beam.getOEHistory(oe_number=self.input_beam._oe_number) if historyItem is None: image_plane = 0.0 elif self.input_beam._oe_number == 0: image_plane = 0.0 else: image_plane = historyItem._shadow_oe_end._oe.T_IMAGE dist = self.image_plane_new_position - image_plane new_shadow_beam._beam.retrace(dist) beam_to_analize = new_shadow_beam._beam if self.mode==2: center=[self.center_x, self.center_z] else: center=[0.0, 0.0] if self.y_range == 1: if self.y_range_min >= self.y_range_max: raise Exception("Y range min cannot be greater or than Y range max") ticket = ST.focnew(beam_to_analize, mode=self.mode, center=center) self.focnewInfo.setText(ticket["text"]) if self.plot_canvas_x is None: self.plot_canvas_x = PlotWindow(roi=False, control=False, position=True, plugins=False) self.plot_canvas_x.setDefaultPlotLines(True) self.plot_canvas_x.setActiveCurveColor(color='blue') self.plot_canvas_x.setDrawModeEnabled(False) self.plot_canvas_x.setZoomModeEnabled(False) self.plot_canvas_x.toolBar.setVisible(False) self.plot_canvas_z = PlotWindow(roi=False, control=False, position=True, plugins=False) self.plot_canvas_z.setDefaultPlotLines(True) self.plot_canvas_z.setActiveCurveColor(color='red') self.plot_canvas_z.setDrawModeEnabled(False) self.plot_canvas_z.setZoomModeEnabled(False) self.plot_canvas_z.toolBar.setVisible(False) self.plot_canvas_t = PlotWindow(roi=False, control=False, position=True, plugins=False) self.plot_canvas_t.setDefaultPlotLines(True) self.plot_canvas_t.setActiveCurveColor(color='green') self.plot_canvas_t.setDrawModeEnabled(False) self.plot_canvas_t.setZoomModeEnabled(False) self.plot_canvas_t.toolBar.setVisible(False) gridLayout = QtGui.QGridLayout() gridLayout.addWidget(self.plot_canvas_x, 0, 0) gridLayout.addWidget(self.plot_canvas_z, 0, 1) gridLayout.addWidget(self.plot_canvas_t, 1, 0) widget = QtGui.QWidget() widget.setLayout(gridLayout) self.image_box.layout().addWidget(widget) if self.y_range == 0: y = numpy.linspace(-10.0, 10.0, 1001) else: y = numpy.linspace(self.y_range_min, self.y_range_max, self.y_npoints) pos = [0.25, 0.15, 0.7, 0.75] self.plot_canvas_x.addCurve(y, 2.35*ST.focnew_scan(ticket["AX"], y)*ShadowPlot.get_factor(1, self.workspace_units_to_cm), "x (tangential)", symbol='', color="blue", replace=True) #'+', '^', ',' self.plot_canvas_x._plot.graph.ax.get_yaxis().get_major_formatter().set_useOffset(True) self.plot_canvas_x._plot.graph.ax.get_yaxis().get_major_formatter().set_scientific(True) self.plot_canvas_x._plot.graph.ax.set_position(pos) self.plot_canvas_x._plot.graph.ax2.set_position(pos) self.plot_canvas_x.setGraphXLabel("Y [" + self.workspace_units_label + "]") self.plot_canvas_x.setGraphYLabel("2.35*<X> [$\mu$m]") self.plot_canvas_x._plot.graph.ax.set_title("X", horizontalalignment='left') self.plot_canvas_x.replot() self.plot_canvas_z.addCurve(y, 2.35*ST.focnew_scan(ticket["AZ"], y)*ShadowPlot.get_factor(3, self.workspace_units_to_cm), "z (sagittal)", symbol='', color="red", replace=False) #'+', '^', ',' self.plot_canvas_z._plot.graph.ax.get_yaxis().get_major_formatter().set_useOffset(True) self.plot_canvas_z._plot.graph.ax.get_yaxis().get_major_formatter().set_scientific(True) self.plot_canvas_z._plot.graph.ax.set_position(pos) self.plot_canvas_z._plot.graph.ax2.set_position(pos) self.plot_canvas_z.setGraphXLabel("Y [" + self.workspace_units_label + "]") self.plot_canvas_z.setGraphYLabel("2.35*<Z> [$\mu$m]") self.plot_canvas_z._plot.graph.ax.set_title("Z", horizontalalignment='left') self.plot_canvas_z.replot() self.plot_canvas_t.addCurve(y, 2.35*ST.focnew_scan(ticket["AT"], y)*ShadowPlot.get_factor(1, self.workspace_units_to_cm), "combined x,z", symbol='', color="green", replace=True) #'+', '^', ',' self.plot_canvas_t._plot.graph.ax.get_yaxis().get_major_formatter().set_useOffset(True) self.plot_canvas_t._plot.graph.ax.get_yaxis().get_major_formatter().set_scientific(True) self.plot_canvas_t._plot.graph.ax.set_position(pos) self.plot_canvas_t._plot.graph.ax2.set_position(pos) self.plot_canvas_t.setGraphXLabel("Y [" + self.workspace_units_label + "]") self.plot_canvas_t.setGraphYLabel("2.35*<X,Z> [$\mu$m]") self.plot_canvas_t._plot.graph.ax.set_title("X,Z (Combined)", horizontalalignment='left') self.plot_canvas_t.replot()
def traceOpticalElement(self): try: self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.progressBarSet(10) self.checkFields() self.setStatusMessage("Running SHADOW") if self.trace_shadow: grabber = TTYGrabber() grabber.start() self.progressBarSet(50) ########################################### # TODO: TO BE ADDED JUST IN CASE OF BROKEN # ENVIRONMENT: MUST BE FOUND A PROPER WAY # TO TEST SHADOW self.fixWeirdShadowBug() ########################################### shadow_oe_1 = ShadowOpticalElement.create_screen_slit() self.populateFields_1(shadow_oe_1) beam_out = ShadowBeam.traceFromOE(self.input_beam, shadow_oe_1) self.adjust_first_divergence(beam_out) self.progressBarSet(60) shadow_oe_2 = ShadowOpticalElement.create_screen_slit() self.populateFields_2(shadow_oe_2) beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_2) self.adjust_second_divergence_and_intensity(beam_out) self.progressBarSet(70) shadow_oe_3 = ShadowOpticalElement.create_screen_slit() self.populateFields_3(shadow_oe_3) beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_3) if self.trace_shadow: grabber.stop() for row in grabber.ttyData: self.writeStdOut(row) self.setStatusMessage("Plotting Results") self.plot_results(beam_out) self.setStatusMessage("") self.send("Beam", beam_out) self.send("Trigger", ShadowTriggerIn(new_beam=True)) else: raise Exception("Input Beam with no good rays") else: raise Exception("Empty Input Beam") except Exception as exception: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", str(exception), QtGui.QMessageBox.Ok) self.error_id = self.error_id + 1 self.error(self.error_id, "Exception occurred: " + str(exception)) self.progressBarFinished()
def run_hybrid(self): try: self.setStatusMessage("") self.progressBarInit() if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): sys.stdout = EmittingStream(textWritten=self.write_stdout) input_parameters = hybrid_control.HybridInputParameters() input_parameters.ghy_lengthunit = self.workspace_units input_parameters.widget = self input_parameters.shadow_beam = self.input_beam input_parameters.ghy_diff_plane = self.ghy_diff_plane + 1 input_parameters.ghy_calcType = self.ghy_calcType + 1 if self.distance_to_image_calc == 0: input_parameters.ghy_distance = -1 else: input_parameters.ghy_distance = self.ghy_distance if self.focal_length_calc == 0: input_parameters.ghy_focallength = -1 else: input_parameters.ghy_focallength = self.ghy_focallength if self.ghy_calcType != 0: input_parameters.ghy_nf = self.ghy_nf else: input_parameters.ghy_nf = 0 input_parameters.ghy_nbins_x = self.ghy_nbins_x input_parameters.ghy_nbins_z = self.ghy_nbins_z input_parameters.ghy_npeak = self.ghy_npeak input_parameters.ghy_fftnpts = self.ghy_fftnpts input_parameters.file_to_write_out = self.file_to_write_out calculation_parameters = hybrid_control.hy_run(input_parameters) self.ghy_focallength = input_parameters.ghy_focallength self.ghy_distance = input_parameters.ghy_distance self.ghy_nbins_x = input_parameters.ghy_nbins_x self.ghy_nbins_z = input_parameters.ghy_nbins_z self.ghy_npeak = input_parameters.ghy_npeak self.ghy_fftnpts = input_parameters.ghy_fftnpts if input_parameters.ghy_calcType != 3: do_plot = not (calculation_parameters.beam_not_cut_in_x or calculation_parameters.beam_not_cut_in_z) else: do_plot = True if do_plot: self.setStatusMessage("Plotting Results") do_nf = input_parameters.ghy_nf == 1 and input_parameters.ghy_calcType > 1 if do_nf: if self.ghy_diff_plane == 0: self.plot_histo_hybrid(84, calculation_parameters.dif_xp, 0, title=u"\u2206" + "Xp", xtitle=r'$\Delta$Xp [$\mu$rad]', ytitle=r'Arbitrary Units', var=4) self.plot_histo(calculation_parameters.ff_beam, 84, 1, plot_canvas_index=1, title="X", xtitle=r'X [$\mu$m]', ytitle=r'Number of Rays', xum=("X [" + u"\u03BC" + "m]")) self.plot_histo_hybrid(88, calculation_parameters.dif_x, 2, title=u"\u2206" + "X", xtitle=r'$\Delta$X [$\mu$m]', ytitle=r'Arbitrary Units', var=1) self.plot_histo(calculation_parameters.nf_beam, 96, 1, plot_canvas_index=3, title="X", xtitle=r'X [$\mu$m]', ytitle=r'Number of Rays', xum=("X [" + u"\u03BC" + "m]")) elif self.ghy_diff_plane == 1: self.plot_histo_hybrid(84, calculation_parameters.dif_zp, 0, title=u"\u2206" + "Zp", xtitle=r'$\Delta$Zp [$\mu$rad]', ytitle=r'Arbitrary Units', var=6) self.plot_histo(calculation_parameters.ff_beam, 84, 3, plot_canvas_index=1, title="Z", xtitle=r'Z [$\mu$m]', ytitle=r'Number of Rays', xum=("Z [" + u"\u03BC" + "m]")) self.plot_histo_hybrid(88, calculation_parameters.dif_z, 2, title=u"\u2206" + "Z", xtitle=r'$\Delta$Z [$\mu$m]', ytitle=r'Arbitrary Units', var=2) self.plot_histo(calculation_parameters.nf_beam, 96, 3, plot_canvas_index=3, title="Z", xtitle=r'Z [$\mu$m]', ytitle=r'Number of Rays', xum=("Z [" + u"\u03BC" + "m]")) else: if self.ghy_diff_plane == 0: self.plot_histo_hybrid(88, calculation_parameters.dif_xp, 0, title=u"\u2206" + "Xp", xtitle=r'$\Delta$Xp [$\mu$rad]', ytitle=r'Arbitrary Units', var=4) self.plot_histo(calculation_parameters.ff_beam, 96, 1, plot_canvas_index=1, title="X", xtitle=r'X [$\mu$m]', ytitle=r'Number of Rays', xum=("X [" + u"\u03BC" + "m]")) elif self.ghy_diff_plane == 1: self.plot_histo_hybrid(88, calculation_parameters.dif_zp, 0, title=u"\u2206" + "Zp", xtitle=r'$\Delta$Zp [$\mu$rad]', ytitle=r'Arbitrary Units', var=6) self.plot_histo(calculation_parameters.ff_beam, 96, 3, plot_canvas_index=1, title="Z", xtitle=r'Z [$\mu$m]', ytitle=r'Number of Rays', xum=("Z [" + u"\u03BC" + "m]")) self.send("Output Beam (Far Field)", calculation_parameters.ff_beam) else: raise Exception("Input Beam with no good rays") else: raise Exception("Empty Input Beam") except Exception as exception: #self.error_id = self.error_id + 1 #self.error(self.error_id, "Exception occurred: " + str(exception)) QtGui.QMessageBox.critical(self, "Error", str(exception), QtGui.QMessageBox.Ok) #raise exception self.setStatusMessage("") self.progressBarFinished()
def reconstructWavefront(self): try: self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if ShadowCongruence.checkEmptyBeam(self.input_beam): if ShadowCongruence.checkGoodBeam(self.input_beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.progressBarSet(10) self.checkFields() self.setStatusMessage("Modifing coordinates to equal optical paths") if self.trace_shadow: grabber = TTYGrabber() grabber.start() self.progressBarSet(50) beam_out = self.input_beam.duplicate() reference_distance = 0.0 for history_element in beam_out.getOEHistory(): if not history_element._shadow_oe_end is None: reference_distance += ( history_element._shadow_oe_end._oe.SSOUR + history_element._shadow_oe_end._oe.SIMAG ) for index in range(0, len(beam_out._beam.rays)): optical_path_difference = beam_out._beam.rays[index, 12] - reference_distance beam_out._beam.rays[index, 0] = ( beam_out._beam.rays[index, 0] + optical_path_difference * beam_out._beam.rays[index, 3] ) beam_out._beam.rays[index, 1] = ( beam_out._beam.rays[index, 1] + optical_path_difference * beam_out._beam.rays[index, 4] ) beam_out._beam.rays[index, 2] = ( beam_out._beam.rays[index, 2] + optical_path_difference * beam_out._beam.rays[index, 5] ) beam_out._beam.rays[index, 12] = reference_distance last_element = beam_out.getOEHistory()[-self.element_before] alpha = last_element._shadow_oe_end._oe.T_INCIDENCE beta = last_element._shadow_oe_end._oe.T_REFLECTION delta_calculated = numpy.round( numpy.degrees(numpy.arctan(numpy.tan(beta) - (numpy.sin(alpha) / numpy.cos(beta)))), 4 ) # y max cursor_1 = numpy.where(beam_out._beam.rays[:, 1] == numpy.max(beam_out._beam.rays[:, 1])) cursor_2 = numpy.where(beam_out._beam.rays[:, 1] == numpy.min(beam_out._beam.rays[:, 1])) point_1 = [beam_out._beam.rays[cursor_1, 2][0][0], beam_out._beam.rays[cursor_1, 1][0][0]] point_2 = [beam_out._beam.rays[cursor_2, 2][0][0], beam_out._beam.rays[cursor_2, 1][0][0]] delta_shadow = numpy.round( numpy.degrees(numpy.arctan((point_1[1] - point_2[1]) / (point_1[0] - point_2[0]))), 4 ) self.delta_angle_calculated = delta_calculated self.delta_angle_shadow = delta_shadow if self.trace_shadow: grabber.stop() for row in grabber.ttyData: self.writeStdOut(row) self.setStatusMessage("Plotting Results") self.plot_results(beam_out) self.setStatusMessage("") self.send("Beam", beam_out) self.send("Trigger", ShadowTriggerIn(new_beam=True)) else: raise Exception("Input Beam with no good rays") else: raise Exception("Empty Input Beam") except Exception as exception: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", str(exception), QtGui.QMessageBox.Ok) self.error_id = self.error_id + 1 self.error(self.error_id, "Exception occurred: " + str(exception)) self.progressBarFinished()