コード例 #1
0
    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
コード例 #2
0
    def plot_xy_fast(self, beam_out, progressBarValue, var_x, var_y, plot_canvas_index, title, xtitle, ytitle):
        if self.plot_canvas[plot_canvas_index] is None:
            self.plot_canvas[plot_canvas_index] = PlotWindow(roi=False, control=False, position=False, plugins=False)
            self.plot_canvas[plot_canvas_index].setDefaultPlotLines(False)
            self.plot_canvas[plot_canvas_index].setActiveCurveColor(color='darkblue')

            self.tab[plot_canvas_index].layout().addWidget(self.plot_canvas[plot_canvas_index])

        ShadowPlot.plotxy_preview(self.plot_canvas[plot_canvas_index], beam_out.beam, var_x, var_y, nolost=1, title=title, xtitle=xtitle, ytitle=ytitle)

        self.progressBarSet(progressBarValue)
コード例 #3
0
    def plot_histo_fast(self, beam_out, progressBarValue, var, plot_canvas_index, title, xtitle, ytitle):
        if self.plot_canvas[plot_canvas_index] is None:
            self.plot_canvas[plot_canvas_index] = PlotWindow(roi=False, control=False, position=True, plugins=False)
            self.plot_canvas[plot_canvas_index].setDefaultPlotLines(True)
            self.plot_canvas[plot_canvas_index].setActiveCurveColor(color='darkblue')

            self.tab[plot_canvas_index].layout().addWidget(self.plot_canvas[plot_canvas_index])

        ShadowPlot.plot_histo_preview(self.plot_canvas[plot_canvas_index], beam_out._beam, var, 1, 23, title, xtitle, ytitle, conv=self.workspace_units_to_cm)

        self.progressBarSet(progressBarValue)
コード例 #4
0
ファイル: ow_plot_xy.py プロジェクト: lucarebuffi/ShadowOui
    def get_ranges(self, beam_to_plot, var_x, var_y):
        xrange = None
        yrange = None
        factor1 = ShadowPlot.get_factor(var_x, self.workspace_units_to_cm)
        factor2 = ShadowPlot.get_factor(var_y, self.workspace_units_to_cm)

        if self.x_range == 0 and self.y_range == 0:
            if self.cartesian_axis == 1:
                x_max = 0
                y_max = 0
                x_min = 0
                y_min = 0

                x, y, good_only = beam_to_plot.getshcol((var_x, var_y, 10))

                x_to_plot = copy.deepcopy(x)
                y_to_plot = copy.deepcopy(y)

                go = numpy.where(good_only == 1)
                lo = numpy.where(good_only != 1)

                if self.rays == 0:
                    x_max = numpy.array(x_to_plot[0:], float).max()
                    y_max = numpy.array(y_to_plot[0:], float).max()
                    x_min = numpy.array(x_to_plot[0:], float).min()
                    y_min = numpy.array(y_to_plot[0:], float).min()
                elif self.rays == 1:
                    x_max = numpy.array(x_to_plot[go], float).max()
                    y_max = numpy.array(y_to_plot[go], float).max()
                    x_min = numpy.array(x_to_plot[go], float).min()
                    y_min = numpy.array(y_to_plot[go], float).min()
                elif self.rays == 2:
                    x_max = numpy.array(x_to_plot[lo], float).max()
                    y_max = numpy.array(y_to_plot[lo], float).max()
                    x_min = numpy.array(x_to_plot[lo], float).min()
                    y_min = numpy.array(y_to_plot[lo], float).min()

                xrange = [x_min, x_max]
                yrange = [y_min, y_max]
        else:
            if self.x_range == 1:
                if self.x_range_min >= self.x_range_max:
                    raise Exception("X range min cannot be greater or equal than X range max")

                xrange = [self.x_range_min / factor1, self.x_range_max / factor1]

            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")

                yrange = [self.y_range_min / factor2, self.y_range_max / factor2]

        return xrange, yrange
コード例 #5
0
ファイル: ow_histogram.py プロジェクト: lucarebuffi/ShadowOui
    def get_range(self, beam_to_plot, var_x):
        if self.x_range == 0:
            x_max = 0
            x_min = 0

            x, good_only = beam_to_plot.getshcol((var_x, 10))

            x_to_plot = copy.deepcopy(x)

            go = numpy.where(good_only == 1)
            lo = numpy.where(good_only != 1)

            if self.rays == 0:
                x_max = numpy.array(x_to_plot[0:], float).max()
                x_min = numpy.array(x_to_plot[0:], float).min()
            elif self.rays == 1:
                x_max = numpy.array(x_to_plot[go], float).max()
                x_min = numpy.array(x_to_plot[go], float).min()
            elif self.rays == 2:
                x_max = numpy.array(x_to_plot[lo], float).max()
                x_min = numpy.array(x_to_plot[lo], float).min()

            xrange = [x_min, x_max]
        else:
            if self.x_range_min >= self.x_range_max:
                raise Exception("X range min cannot be greater or equal than X range max")

            factor1 = ShadowPlot.get_factor(var_x, self.workspace_units_to_cm)

            xrange = [self.x_range_min / factor1, self.x_range_max / factor1]

        return xrange
コード例 #6
0
ファイル: ow_plot_xy.py プロジェクト: lucarebuffi/ShadowOui
    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
コード例 #7
0
    def plot_histo_hybrid(self, progressBarValue, scaled_array, plot_canvas_index, title, xtitle, ytitle, var):
        if self.plot_canvas[plot_canvas_index] is None:
            self.plot_canvas[plot_canvas_index] = PlotWindow(roi=False, control=False, position=True, plugins=False)
            self.plot_canvas[plot_canvas_index].setDefaultPlotLines(True)
            self.plot_canvas[plot_canvas_index].setActiveCurveColor(color='darkblue')
            self.plot_canvas[plot_canvas_index].setDrawModeEnabled(True, 'rectangle')
            self.plot_canvas[plot_canvas_index].setZoomModeEnabled(True)

            self.tab[plot_canvas_index].layout().addWidget(self.plot_canvas[plot_canvas_index])

        factor = ShadowPlot.get_factor(var, self.workspace_units_to_cm)

        self.plot_canvas[plot_canvas_index].addCurve(scaled_array.scale*factor, scaled_array.np_array, "crv_"+ytitle, symbol='', color="blue", replace=True) #'+', '^', ','
        self.plot_canvas[plot_canvas_index]._plot.graph.ax.get_yaxis().get_major_formatter().set_useOffset(True)
        self.plot_canvas[plot_canvas_index]._plot.graph.ax.get_yaxis().get_major_formatter().set_scientific(True)
        self.plot_canvas[plot_canvas_index].setGraphXLabel(xtitle)
        self.plot_canvas[plot_canvas_index].setGraphYLabel(ytitle)
        self.plot_canvas[plot_canvas_index].setGraphTitle(title)
        self.plot_canvas[plot_canvas_index].replot()

        self.progressBarSet(progressBarValue)
コード例 #8
0
    def plot_xy(self, var_x, var_y, title, xtitle, ytitle, xum, yum):
        beam_to_plot = self.input_beam._beam

        if self.image_plane == 1:
            new_shadow_beam = self.input_beam.duplicate(history=False)

            historyItem = self.input_beam.getOEHistory(oe_number=self.input_beam._oe_number)
            if historyItem is None: raise Exception("Calculation impossible: Beam has no history")

            dist = 0.0

            if self.image_plane_rel_abs_position == 1:  # relative
                image_plane = 0.0

                if type(historyItem._shadow_oe_end) == ShadowOpticalElement:
                    image_plane = historyItem._shadow_oe_end._oe.T_IMAGE
                elif type(historyItem._shadow_oe_end) == ShadowCompoundOpticalElement:
                    image_plane = historyItem._shadow_oe_end._oe.list[historyItem._shadow_oe_end._oe.number_oe() - 1].T_IMAGE

                if self.image_plane_new_position < 0 and abs(self.image_plane_new_position) > image_plane:
                    raise Exception("Image plane new position cannot be before the O.E.")

                dist = self.image_plane_new_position
            else:  # absolute
                ShadowGui.checkPositiveNumber(self.image_plane_new_position, "Image Plane new Position")

                dist = self.image_plane_new_position - historyItem._shadow_oe_end._oe.T_IMAGE

            new_shadow_beam._beam.retrace(dist)

            beam_to_plot = new_shadow_beam._beam

        xrange = None
        yrange = None

        factor1 = ShadowPlot.get_factor(var_x)
        factor2 = ShadowPlot.get_factor(var_y)

        if self.x_range == 0 and self.y_range == 0:
            if self.cartesian_axis == 1:
                x_max = 0
                y_max = 0
                x_min = 0
                y_min = 0

                x, y, good_only = beam_to_plot.getshcol((var_x, var_y, 10))

                x_to_plot = copy.deepcopy(x)
                y_to_plot = copy.deepcopy(y)

                go = numpy.where(good_only == 1)
                lo = numpy.where(good_only != 1)

                if self.rays == 0:
                    x_max = numpy.array(x_to_plot[0:], float).max()
                    y_max = numpy.array(y_to_plot[0:], float).max()
                    x_min = numpy.array(x_to_plot[0:], float).min()
                    y_min = numpy.array(y_to_plot[0:], float).min()
                elif self.rays == 1:
                    x_max = numpy.array(x_to_plot[go], float).max()
                    y_max = numpy.array(y_to_plot[go], float).max()
                    x_min = numpy.array(x_to_plot[go], float).min()
                    y_min = numpy.array(y_to_plot[go], float).min()
                elif self.rays == 2:
                    x_max = numpy.array(x_to_plot[lo], float).max()
                    y_max = numpy.array(y_to_plot[lo], float).max()
                    x_min = numpy.array(x_to_plot[lo], float).min()
                    y_min = numpy.array(y_to_plot[lo], float).min()

                temp = numpy.array([x_max, y_max, x_min, y_min], float)

                xrange = [temp.min(), temp.max()]
                yrange = [temp.min(), temp.max()]
        else:
            if self.x_range == 1:
                if self.x_range_min >= self.x_range_max:
                    raise Exception("X range min cannot be greater or equal than X range max")

                xrange = [self.x_range_min / factor1, self.x_range_max / factor1]

            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")

                yrange = [self.y_range_min / factor2, self.y_range_max / factor1]

        self.replace_fig(beam_to_plot, var_x, var_y, title, xtitle, ytitle, xrange=xrange, yrange=yrange, nbins=int(self.number_of_bins), nolost=self.rays, xum=xum, yum=yum)
コード例 #9
0
ファイル: ow_focnew.py プロジェクト: lucarebuffi/ShadowOui
    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()
コード例 #10
0
    def plot_results(self):
        self.plotted_beam = None

        if super().plot_results():
            if self.spectro_plot_canvas is None:
                self.spectro_plot_canvas = PlotWindow.PlotWindow(roi=False, control=False, position=False, plugins=False, logx=False, logy=False)
                self.spectro_plot_canvas.setDefaultPlotLines(True)
                self.spectro_plot_canvas.setDefaultPlotPoints(False)
                self.spectro_plot_canvas.setZoomModeEnabled(True)
                self.spectro_plot_canvas.setMinimumWidth(673)
                self.spectro_plot_canvas.setMaximumWidth(673)
                pos = self.spectro_plot_canvas._plot.graph.ax.get_position()
                self.spectro_plot_canvas._plot.graph.ax.set_position([pos.x0, pos.y0 , pos.width*0.86, pos.height])
                pos = self.spectro_plot_canvas._plot.graph.ax2.get_position()
                self.spectro_plot_canvas._plot.graph.ax2.set_position([pos.x0, pos.y0 , pos.width*0.86, pos.height])
                ax3 = self.spectro_plot_canvas._plot.graph.fig.add_axes([.82, .15, .05, .75])

                self.spectro_image_box.layout().addWidget(self.spectro_plot_canvas)
            else:
                self.spectro_plot_canvas.clear()
                ax3 = self.spectro_plot_canvas._plot.graph.fig.axes[-1]
                ax3.cla()

            number_of_bins = self.spectro_number_of_bins + 1

            x, auto_title, xum = self.get_titles()

            if self.plotted_beam is None: self.plotted_beam = self.input_beam

            xrange  = self.get_range(self.plotted_beam._beam, x)

            min_k = numpy.min(self.plotted_beam._beam.rays[:, 10])
            max_k = numpy.max(self.plotted_beam._beam.rays[:, 10])

            if self.spectro_variable == 0: #Energy
                energy_min = ShadowPhysics.getEnergyFromShadowK(min_k)
                energy_max = ShadowPhysics.getEnergyFromShadowK(max_k)

                bins = energy_min + numpy.arange(0, number_of_bins + 1)*((energy_max-energy_min)/number_of_bins)
                normalization = colors.Normalize(vmin=energy_min, vmax=energy_max)
            else: #wavelength
                wavelength_min = ShadowPhysics.getWavelengthfromShadowK(max_k)
                wavelength_max = ShadowPhysics.getWavelengthfromShadowK(min_k)

                bins = wavelength_min + numpy.arange(0, number_of_bins + 1)*((wavelength_max-wavelength_min)/number_of_bins)
                normalization = colors.Normalize(vmin=wavelength_min, vmax=wavelength_max)

            scalarMap = cmx.ScalarMappable(norm=normalization, cmap=self.color_map)

            cb1 = colorbar.ColorbarBase(ax3,
                                        cmap=self.color_map,
                                        norm=normalization,
                                        orientation='vertical')

            if self.spectro_variable == 0: #Energy
                cb1.set_label('Energy [eV]')
            else:
                cb1.set_label('Wavelength [Å]')

            go = numpy.where(self.plotted_beam._beam.rays[:, 9] == 1)
            lo = numpy.where(self.plotted_beam._beam.rays[:, 9] != 1)

            rays_to_plot = self.plotted_beam._beam.rays

            if self.rays == 1:
                rays_to_plot = self.plotted_beam._beam.rays[go]
            elif self.rays == 2:
                rays_to_plot = self.plotted_beam._beam.rays[lo]

            factor_x = ShadowPlot.get_factor(x, self.workspace_units_to_cm)

            for index in range (0, number_of_bins):
                min_value = bins[index]
                max_value = bins[index+1]

                if index < number_of_bins-1:
                    if self.spectro_variable == 0: #Energy
                        cursor = numpy.where((numpy.round(ShadowPhysics.getEnergyFromShadowK(rays_to_plot[:, 10]), 4) >= numpy.round(min_value, 4)) &
                                             (numpy.round(ShadowPhysics.getEnergyFromShadowK(rays_to_plot[:, 10]), 4) < numpy.round(max_value, 4)))
                    else:
                        cursor = numpy.where((numpy.round(ShadowPhysics.getWavelengthfromShadowK(rays_to_plot[:, 10]), 4) >= numpy.round(min_value, 4)) &
                                             (numpy.round(ShadowPhysics.getWavelengthfromShadowK(rays_to_plot[:, 10]), 4) < numpy.round(max_value, 4)))
                else:
                    if self.spectro_variable == 0: #Energy
                        cursor = numpy.where((numpy.round(ShadowPhysics.getEnergyFromShadowK(rays_to_plot[:, 10]), 4) >= numpy.round(min_value, 4)) &
                                             (numpy.round(ShadowPhysics.getEnergyFromShadowK(rays_to_plot[:, 10]), 4) <= numpy.round(max_value, 4)))
                    else:
                        cursor = numpy.where((numpy.round(ShadowPhysics.getWavelengthfromShadowK(rays_to_plot[:, 10]), 4) >= numpy.round(min_value, 4)) &
                                             (numpy.round(ShadowPhysics.getWavelengthfromShadowK(rays_to_plot[:, 10]), 4) <= numpy.round(max_value, 4)))

                color = scalarMap.to_rgba((bins[index] + bins[index+1])/2)

                if index == 0: self.spectro_plot_canvas.setActiveCurveColor(color=color)

                self.replace_spectro_fig(rays_to_plot[cursor], x, factor_x, xrange,
                                         title=self.title + str(index), color=color)

            self.spectro_plot_canvas.setDrawModeEnabled(True, 'rectangle')
            self.spectro_plot_canvas.setGraphXLimits(xrange[0]*factor_x, xrange[1]*factor_x)
            self.spectro_plot_canvas.setGraphXLabel(auto_title)
            self.spectro_plot_canvas.replot()
コード例 #11
0
    def replace_spectro_fig(self, rays_to_plot, var_x, factor_x, xrange, title, color):
        try:
            beam = ShadowBeam()
            beam._beam.rays = rays_to_plot

            ticket = beam._beam.histo1(var_x, nbins=self.number_of_bins, xrange=xrange, nolost=self.rays, ref=self.weight_column_index)

            if self.weight_column_index != 0:
                self.spectro_plot_canvas.setGraphYLabel("Number of rays weighted by " + ShadowPlot.get_shadow_label(self.weight_column_index))
            else:
                self.spectro_plot_canvas.setGraphYLabel("Number of Rays")

            histogram = ticket['histogram_path']
            bins = ticket['bin_path']*factor_x

            self.spectro_plot_canvas.addCurve(bins, histogram, title, symbol='', color=color, replace=False) #'+', '^', ','
        except Exception as e:
            print(e)
            raise Exception("Data not plottable: No good rays or bad content")