def traceOpticalElement(self): try: self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if ShadowGui.checkEmptyBeam(self.input_beam): if ShadowGui.checkGoodBeam(self.input_beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.checkFields() shadow_oe = ShadowCompoundOpticalElement.create_compound_oe() 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 ShadowGui.checkEmptyBeam(beam): proceed = True if not ShadowGui.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) self.current_number_of_rays = self.current_number_of_rays + len(beam.beam.rays[go]) if self.current_number_of_rays <= 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: 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.input_beam = None else: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", "Number of Accumulated Rays reached, please push \'Send Signal\' button", QtGui.QMessageBox.Ok)
def plot_results(self, beam_out, progressBarValue=80): if not self.view_type == 2: if ShadowGui.checkEmptyBeam(beam_out): if ShadowGui.checkGoodBeam(beam_out): self.view_type_combo.setEnabled(False) try: if self.view_type == 1: self.plot_xy_fast(beam_out, progressBarValue + 4, 1, 3, plot_canvas_index=0, title="X,Z", xtitle=r'X [$\mu$m]', ytitle=r'Z [$\mu$m]') self.plot_xy_fast(beam_out, progressBarValue + 8, 4, 6, plot_canvas_index=1, title="X',Z'", xtitle="X' [$\mu$rad]", ytitle="Z' [$\mu$rad]") self.plot_xy_fast(beam_out, progressBarValue + 12, 1, 4, plot_canvas_index=2, title="X,X'", xtitle=r'X [$\mu$m]', ytitle="X' [$\mu$rad]") self.plot_xy_fast(beam_out, progressBarValue + 16, 3, 6, plot_canvas_index=3, title="Z,Z'", xtitle=r'Z [$\mu$m]', ytitle="Z' [$\mu$rad]") self.plot_histo_fast(beam_out, progressBarValue + 20, 11, plot_canvas_index=4, title="Energy", xtitle="Energy [eV]", ytitle="Number of Rays") elif self.view_type == 0: self.plot_xy(beam_out, progressBarValue + 4, 1, 3, plot_canvas_index=0, title="X,Z", xtitle=r'X [$\mu$m]', ytitle=r'Z [$\mu$m]', xum=("X [" + u"\u03BC" + "m]"), yum=("Z [" + u"\u03BC" + "m]")) self.plot_xy(beam_out, progressBarValue + 8, 4, 6, plot_canvas_index=1, title="X',Z'", xtitle="X' [$\mu$rad]", ytitle="Z' [$\mu$rad]", xum="X' [" + u"\u03BC" + "rad]", yum="Z' [" + u"\u03BC" + "rad]") self.plot_xy(beam_out, progressBarValue + 12, 1, 4, plot_canvas_index=2, title="X,X'", xtitle=r'X [$\mu$m]', ytitle="X' [$\mu$rad]", xum=("X [" + u"\u03BC" + "m]"), yum="X' [" + u"\u03BC" + "rad]") self.plot_xy(beam_out, progressBarValue + 16, 3, 6, plot_canvas_index=3, title="Z,Z'", xtitle=r'Z [$\mu$m]', ytitle="Z' [$\mu$rad]", xum=("Z [" + u"\u03BC" + "m]"), yum="Z' [" + u"\u03BC" + "rad]") self.plot_histo(beam_out, progressBarValue + 20, 11, plot_canvas_index=4, title="Energy", xtitle="Energy [eV]", ytitle="Number of Rays", xum="[eV]") 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 ShadowGui.checkEmptyBeam(beam): if ShadowGui.checkGoodBeam(beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.input_beam = beam self.sysInfo.setText("\n\n\n\n\nNot Available") optical_element_list = [] for history_element in self.input_beam.getOEHistory(): if not history_element.shadow_source_start is None: optical_element_list.append(history_element.shadow_source_start.src) elif not history_element.shadow_oe_start is None: optical_element_list.append(history_element.shadow_oe_start.oe) if not history_element.shadow_source_end is None: self.sourceInfo.append(history_element.shadow_source_end.src.sourcinfo()) elif not history_element.shadow_oe_end is None: self.mirInfo.append(history_element.shadow_oe_end.oe.mirinfo(title="O.E. #" + str(history_element.oe_number))) self.pythonScript.setText(ST.make_python_script_from_list(optical_element_list)) else: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", "Data not displayable: No good rays or bad content", QtGui.QMessageBox.Ok)
def setBeam(self, beam): if ShadowGui.checkEmptyBeam(beam): if ShadowGui.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 ShadowGui.checkEmptyBeam(self.input_beam): if (self.input_beam._oe_number == 0): # IS THE SOURCE self.image_plane = 0 self.set_ImagePlane() self.image_plane_combo.setEnabled(False) if self.is_automatic_run: self.plot_results() else: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", "Data not displayable: No good rays or bad content", QtGui.QMessageBox.Ok)