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): self.onReceivingInput() if ShadowGui.checkEmptyBeam(beam): self.input_beam = beam if self.is_automatic_run: self.traceOpticalElement()
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)
def plot_results(self): self.error(self.error_id) try: sys.stdout = EmittingStream(textWritten=self.writeStdOut) if self.trace_shadow: grabber = TTYGrabber() grabber.start() if ShadowGui.checkEmptyBeam(self.input_beam): self.number_of_bins = ShadowGui.checkPositiveNumber(self.number_of_bins, "Number of Bins") auto_x_title = self.x_column.currentText().split(":", 2)[1] auto_y_title = self.y_column.currentText().split(":", 2)[1] xum = auto_x_title + " " yum = auto_y_title + " " self.title = auto_x_title + "," + auto_y_title x = self.x_column_index + 1 if x == 1 or x == 2 or x == 3: xum = xum + "[" + u"\u03BC" + "m]" auto_x_title = auto_x_title + " [$\mu$m]" elif x == 4 or x == 5 or x == 6: xum = xum + "[" + u"\u03BC" + "rad]" auto_x_title = auto_x_title + " [$\mu$rad]" elif x == 11: xum = xum + "[eV]" auto_x_title = auto_x_title + " [eV]" elif x == 13: xum = xum + "[cm]" auto_x_title = auto_x_title + " [cm]" elif x == 14: xum = xum + "[rad]" auto_x_title = auto_x_title + " [rad]" elif x == 15: xum = xum + "[rad]" auto_x_title = auto_x_title + " [rad]" elif x == 19: xum = xum + "[Å]" auto_x_title = auto_x_title + " [Å]" elif x == 20: xum = xum + "[cm]" auto_x_title = auto_x_title + " [cm]" elif x == 21: xum = xum + "[rad]" auto_x_title = auto_x_title + " [rad]" elif x >= 25 and x <= 28: xum = xum + "[Å-1]" auto_x_title = auto_x_title + " [Å-1]" y = self.y_column_index + 1 if y == 1 or y == 2 or y == 3: yum = yum + "[" + u"\u03BC" + "m]" auto_y_title = auto_y_title + " [$\mu$m]" elif y == 4 or y == 5 or y == 6: yum = yum + "[" + u"\u03BC" + "rad]" auto_y_title = auto_y_title + " [$\mu$rad]" elif y == 11: yum = yum + "[eV]" auto_y_title = auto_y_title + " [eV]" elif y == 13: yum = yum + "[cm]" auto_y_title = auto_y_title + " [cm]" elif y == 14: yum = yum + "[rad]" auto_y_title = auto_y_title + " [rad]" elif y == 15: yum = yum + "[rad]" auto_y_title = auto_y_title + " [rad]" elif y == 19: yum = yum + "[Å]" auto_y_title = auto_y_title + " [Å]" elif y == 20: yum = yum + "[cm]" auto_y_title = auto_y_title + " [cm]" elif y == 21: yum = yum + "[rad]" auto_y_title = auto_y_title + " [rad]" elif y >= 25 and y <= 28: yum = yum + "[Å-1]" auto_y_title = auto_y_title + " [Å-1]" self.plot_xy(x, y, title=self.title, xtitle=auto_x_title, ytitle=auto_y_title, xum=xum, yum=yum) 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 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))