def plot_xy_fast(self, beam_out, progressBarValue, var_x, var_y, plot_canvas_index, title, xtitle, ytitle, is_footprint=False): if self.plot_canvas[plot_canvas_index] is None: self.plot_canvas[plot_canvas_index] = oasysgui.plotWindow( roi=False, control=False, position=True) self.plot_canvas[plot_canvas_index].setDefaultPlotLines(False) self.plot_canvas[plot_canvas_index].setActiveCurveColor( color='blue') 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, conv=self.workspace_units_to_cm, is_footprint=is_footprint) self.progressBarSet(progressBarValue)
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: pass else: if self.x_range == 1: congruence.checkLessThan(self.x_range_min, self.x_range_max, "X range min", "X range max") xrange = [ self.x_range_min / factor1, self.x_range_max / factor1 ] if self.y_range == 1: congruence.checkLessThan(self.y_range_min, self.y_range_max, "Y range min", "Y range max") yrange = [ self.y_range_min / factor2, self.y_range_max / factor2 ] return xrange, yrange
def plot_histo(self, beam, col, nbins=100, ref=23, title="", xtitle="", ytitle="", histo_index=0, scan_variable_name="Variable", scan_variable_value=0, offset=0.0, xrange=None, show_reference=True, add_labels=True, has_colormap=True, colormap=cm.rainbow): factor=ShadowPlot.get_factor(col, conv=self.workspace_units_to_cm) if histo_index==0 and xrange is None: ticket = beam._beam.histo1(col, xrange=None, nbins=nbins, nolost=1, ref=ref) fwhm = ticket['fwhm'] xrange = ticket['xrange'] centroid = get_average(ticket['histogram'], ticket['bin_center']) if not fwhm is None: xrange = [centroid - 2*fwhm , centroid + 2*fwhm] ticket = beam._beam.histo1(col, xrange=xrange, nbins=nbins, nolost=1, ref=ref) if not ytitle is None: ytitle = ytitle + ' weighted by ' + ShadowPlot.get_shadow_label(ref) histogram = ticket['histogram_path'] bins = ticket['bin_path']*factor histogram_stats = ticket['histogram'] bins_stats = ticket['bin_center'] sigma = get_sigma(histogram_stats, bins_stats)*factor fwhm = sigma*2.35 if ticket['fwhm'] is None else ticket['fwhm']*factor centroid = get_average(histogram_stats, bins_stats)*factor peak_intensity = numpy.average(histogram_stats[numpy.where(histogram_stats>=numpy.max(histogram_stats)*0.90)]) integral_intensity = numpy.sum(histogram_stats) rcParams['axes.formatter.useoffset']='False' self.set_xrange(bins) self.set_labels(title=title, xlabel=xtitle, ylabel=scan_variable_name, zlabel=ytitle) self.add_histo(scan_variable_value, histogram, has_colormap, colormap, histo_index) return HistogramData(histogram=histogram_stats, bins=bins_stats, xrange=xrange, fwhm=fwhm, sigma=sigma, centroid=centroid, peak_intensity=peak_intensity, integral_intensity=integral_intensity)
def plot_xy_hybrid(self, progressBarValue, scaled_matrix, plot_canvas_index, title, xtitle, ytitle, var1, var2): if self.plot_canvas[plot_canvas_index] is None: self.plot_canvas[plot_canvas_index] = ImageView() self.plot_canvas[plot_canvas_index].setColormap({"name":"temperature", "normalization":"linear", "autoscale":True, "vmin":0, "vmax":0, "colors":256}) self.plot_canvas[plot_canvas_index].setMinimumWidth(590) self.plot_canvas[plot_canvas_index].setMaximumWidth(590) self.tab[plot_canvas_index].layout().addWidget(self.plot_canvas[plot_canvas_index]) factor1 = ShadowPlot.get_factor(var1, self.workspace_units_to_cm) factor2 = ShadowPlot.get_factor(var2, self.workspace_units_to_cm) xmin, xmax = min(scaled_matrix.x_coord), max(scaled_matrix.x_coord) ymin, ymax = min(scaled_matrix.y_coord), max(scaled_matrix.y_coord) dim_x, dim_y = scaled_matrix.shape() origin = (xmin*factor1, ymin*factor2) scale = (abs((xmax-xmin)/dim_x)*factor1, abs((ymax-ymin)/dim_y)*factor2) data_to_plot = [] for y_index in range(0, dim_y): x_values = [] for x_index in range(0, dim_x): x_values.append(scaled_matrix.z_values[x_index, y_index]) data_to_plot.append(x_values) self.plot_canvas[plot_canvas_index].setImage(numpy.array(data_to_plot), origin=origin, scale=scale) 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.progressBarSet(progressBarValue)
def replace_fig(self, beam, var_x, var_y, var_color, title, xtitle, ytitle, xrange, yrange, nolost, xum, yum): if self.backend == 0: use_backend = 'matplotlib' elif self.backend == 1: if not has_opengl: QMessageBox.information( self, "Plot Scatter Information", "It seems that PyOpenGL is not installed in your system.\n Install it to get much faster scatter plots.", QMessageBox.Ok) use_backend = 'matplotlib' self.backend = 0 else: use_backend = 'gl' if self.plot_canvas is None: self.plot_canvas = ScatterView(backend=use_backend) else: self.image_box.layout().removeWidget(self.plot_canvas) self.plot_canvas = None self.plot_canvas = ScatterView(backend=use_backend) if self.color_column != 0: color_array = beam.getshonecol(var_color, nolost=nolost) else: color_array = beam.getshonecol(1, nolost=nolost) * 0.0 factor1 = ShadowPlot.get_factor(var_x, self.workspace_units_to_cm) factor2 = ShadowPlot.get_factor(var_y, self.workspace_units_to_cm) factorC = ShadowPlot.get_factor(var_color, self.workspace_units_to_cm) if self.weight_transparency == 1: self.plot_canvas.setData( beam.getshonecol(var_x, nolost=nolost) * factor1, beam.getshonecol(var_y, nolost=nolost) * factor2, color_array * factorC, alpha=beam.getshonecol(23, nolost=nolost)) else: self.plot_canvas.setData( beam.getshonecol(var_x, nolost=nolost) * factor1, beam.getshonecol(var_y, nolost=nolost) * factor2, color_array * factorC, ) self.plot_canvas.resetZoom() self.plot_canvas.setGraphTitle(title) self.plot_canvas.setColormap(Colormap('viridis')) ax = self.plot_canvas.getPlotWidget().getXAxis() if self.x_range == 1: ax.setLimits(self.x_range_min, self.x_range_max) ax.setLabel(xtitle) ay = self.plot_canvas.getPlotWidget().getYAxis() if self.y_range == 1: ay.setLimits(self.y_range_min, self.y_range_max) ay.setLabel(ytitle) self.image_box.layout().addWidget(self.plot_canvas)
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 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: congruence.checkLessThan(self.x_range_min, self.x_range_max, "X range min", "X range max") xrange = [ self.x_range_min / factor1, self.x_range_max / factor1 ] if self.y_range == 1: congruence.checkLessThan(self.y_range_min, self.y_range_max, "Y range min", "Y range max") yrange = [ self.y_range_min / factor2, self.y_range_max / factor2 ] return xrange, yrange
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] = oasysgui.plotWindow(roi=False, control=False, position=True) self.plot_canvas[plot_canvas_index].setDefaultPlotLines(True) self.plot_canvas[plot_canvas_index].setActiveCurveColor(color='blue') 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)
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)
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)
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
def replace_fig(self, beam, var_x, var_y, title, xtitle, ytitle, xrange, yrange, nbins, nolost, xum, yum): if self.plot_canvas is None: self.plot_canvas = ShadowPlot.DetailedPlotWidget(y_scale_factor=1.14) self.image_box.layout().addWidget(self.plot_canvas) try: if self.autosave == 1: if self.autosave_file is None: self.autosave_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(self.autosave_file_name)) elif self.autosave_file.filename != congruence.checkFileName(self.autosave_file_name): self.autosave_file.close() self.autosave_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(self.autosave_file_name)) if self.keep_result == 1: self.cumulated_ticket, last_ticket = self.plot_canvas.plot_xy(beam, var_x, var_y, title, xtitle, ytitle, xrange=xrange, yrange=yrange, nbins=nbins, nolost=nolost, xum=xum, yum=yum, conv=self.workspace_units_to_cm, ref=self.weight_column_index, ticket_to_add=self.cumulated_ticket) self.plotted_ticket = self.cumulated_ticket if self.autosave == 1: self.autosave_prog_id += 1 self.autosave_file.write_coordinates(self.cumulated_ticket) dataset_name = self.weight_column.itemText(self.weight_column_index) self.autosave_file.add_plot_xy(self.cumulated_ticket, dataset_name=dataset_name) if self.autosave_partial_results == 1: if last_ticket is None: self.autosave_file.add_plot_xy(self.cumulated_ticket, plot_name="Plot XY #" + str(self.autosave_prog_id), dataset_name=dataset_name) else: self.autosave_file.add_plot_xy(last_ticket, plot_name="Plot X #" + str(self.autosave_prog_id), dataset_name=dataset_name) self.autosave_file.flush() else: ticket, _ = self.plot_canvas.plot_xy(beam, var_x, var_y, title, xtitle, ytitle, xrange=xrange, yrange=yrange, nbins=nbins, nolost=nolost, xum=xum, yum=yum, conv=self.workspace_units_to_cm, ref=self.weight_column_index) self.cumulated_ticket = None self.plotted_ticket = ticket if self.autosave == 1: self.autosave_prog_id += 1 self.autosave_file.write_coordinates(ticket) self.autosave_file.add_plot_xy(ticket, dataset_name=self.weight_column.itemText(self.weight_column_index)) self.autosave_file.flush() except Exception as e: if not self.IS_DEVELOP: raise Exception("Data not plottable: No good rays or bad content") else: raise e
def plot_xy(self, beam_out, progressBarValue, var_x, var_y, plot_canvas_index, title, xtitle, ytitle, xum="", yum="", is_footprint=False): if self.plot_canvas[plot_canvas_index] is None: self.plot_canvas[ plot_canvas_index] = ShadowPlot.DetailedPlotWidget() self.tab[plot_canvas_index].layout().addWidget( self.plot_canvas[plot_canvas_index]) self.plot_canvas[plot_canvas_index].plot_xy( beam_out._beam, var_x, var_y, title, xtitle, ytitle, xum=xum, yum=yum, conv=self.workspace_units_to_cm, is_footprint=is_footprint) self.progressBarSet(progressBarValue)
def plot_histo(self, beam_out, progressBarValue, var, plot_canvas_index, title, xtitle, ytitle, xum=""): if self.plot_canvas[plot_canvas_index] is None: self.plot_canvas[ plot_canvas_index] = ShadowPlot.DetailedHistoWidget() self.tab[plot_canvas_index].layout().addWidget( self.plot_canvas[plot_canvas_index]) self.plot_canvas[plot_canvas_index].plot_histo( beam_out._beam, var, 1, None, 23, title, xtitle, ytitle, xum=xum, conv=self.workspace_units_to_cm) self.progressBarSet(progressBarValue)
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: congruence.checkLessThan(self.x_range_min, self.x_range_max, "X range min", "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
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] = oasysgui.plotWindow( roi=False, control=False, position=True) self.plot_canvas[plot_canvas_index].setDefaultPlotLines(True) self.plot_canvas[plot_canvas_index].setActiveCurveColor( color='blue') self.plot_canvas[plot_canvas_index].setInteractiveMode(mode='zoom') 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]._backend.ax.get_yaxis( ).get_major_formatter().set_useOffset(True) self.plot_canvas[plot_canvas_index]._backend.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)
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")
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
def save_results(self): if not self.plotted_ticket is None: try: file_name, _ = QtWidgets.QFileDialog.getSaveFileName( self, "Save Current Plot", filter="HDF5 Files (*.hdf5 *.h5 *.hdf)") if not file_name is None and not file_name.strip() == "": if not (file_name.endswith("hd5") or file_name.endswith("hdf5") or file_name.endswith("hdf")): file_name += ".hdf5" save_file = ShadowPlot.HistogramHdf5File( congruence.checkDir(file_name)) save_file.write_coordinates(self.plotted_ticket) dataset_name = self.weight_column.itemText( self.weight_column_index) save_file.add_histogram(self.plotted_ticket, dataset_name=dataset_name) save_file.close() except Exception as exception: QtWidgets.QMessageBox.critical(self, "Error", str(exception), QtWidgets.QMessageBox.Ok) if self.IS_DEVELOP: raise exception
def selectPlotFile(self): file_name = oasysgui.selectFileFromDialog(self, None, "Select File", file_extension_filter="HDF5 Files (*.hdf5 *.h5 *.hdf)") if not file_name is None: self.le_loaded_plot_file_name.setText(os.path.basename(os.path.normpath(file_name))) plot_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(file_name), mode="r") ticket = {} ticket["histogram"], ticket["histogram_h"], ticket["histogram_v"], attributes = plot_file.get_last_plot(dataset_name="power_density") ticket["bin_h_center"], ticket["bin_v_center"], ticket["h_label"], ticket["v_label"] = plot_file.get_coordinates() ticket["intensity"] = attributes["intensity"] ticket["nrays"] = attributes["total_rays"] ticket["good_rays"] = attributes["good_rays"] if self.plot_canvas is None: self.plot_canvas = PowerPlotXYWidget() self.image_box.layout().addWidget(self.plot_canvas) else: if not self.plotted_ticket is None: if QMessageBox.question(self, "Load Plot", "Merge with current Plot?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes: if ticket["histogram"].shape == self.plotted_ticket["histogram"].shape and \ ticket["bin_h_center"].shape == self.plotted_ticket["bin_h_center"].shape and \ ticket["bin_v_center"].shape == self.plotted_ticket["bin_v_center"].shape and \ ticket["bin_h_center"][0] == self.plotted_ticket["bin_h_center"][0] and \ ticket["bin_h_center"][-1] == self.plotted_ticket["bin_h_center"][-1] and \ ticket["bin_v_center"][0] == self.plotted_ticket["bin_v_center"][0] and \ ticket["bin_v_center"][-1] == self.plotted_ticket["bin_v_center"][-1]: ticket["histogram"] += self.plotted_ticket["histogram"] if QMessageBox.question(self, "Load Plot", "Average with current Plot?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes: ticket["histogram"] *= 0.5 else: raise ValueError("The plots cannot be merged: the should have same dimensions and ranges") cumulated_power_plot = numpy.sum(ticket["histogram"])*(ticket["bin_h_center"][1]-ticket["bin_h_center"][0])*(ticket["bin_v_center"][1]-ticket["bin_v_center"][0]) try: energy_min=0.0 energy_max=0.0 energy_step=0.0 self.plot_canvas.cumulated_power_plot = cumulated_power_plot self.plot_canvas.plot_power_density_ticket(ticket, ticket["h_label"], ticket["v_label"], cumulated_total_power=0.0, energy_min=energy_min, energy_max=energy_max, energy_step=energy_step) self.cumulated_ticket = None self.plotted_ticket = ticket self.plotted_ticket_original = ticket.copy() except Exception as e: QMessageBox.critical(self, "Error", str(e), QMessageBox.Ok) if self.IS_DEVELOP: raise e
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 save_cumulated_data_hdf5(self, file_name): if not self.plotted_ticket is None: try: save_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(os.path.splitext(file_name)[0] + ".hdf5")) save_file.write_coordinates(self.plotted_ticket) save_file.add_plot_xy(self.plotted_ticket, dataset_name="power_density") save_file.close() except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok) if self.IS_DEVELOP: raise exception
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 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)
def replace_fig(self, beam, var, xrange, title, xtitle, ytitle, xum): if self.plot_canvas is None: if self.iterative_mode < 2: self.plot_canvas = ShadowPlot.DetailedHistoWidget( y_scale_factor=1.14) else: if self.plot_type == 0: self.plot_canvas = ScanHistoWidget( self.workspace_units_to_cm) elif self.plot_type == 1: self.plot_canvas = Scan3DHistoWidget( self.workspace_units_to_cm, type=Scan3DHistoWidget.PlotType.LINES if self.plot_type_3D == 0 else Scan3DHistoWidget.PlotType.SURFACE) self.plot_canvas_stats = DoublePlotWidget(parent=None) self.image_box_stats.layout().addWidget(self.plot_canvas_stats) self.image_box.layout().addWidget(self.plot_canvas) if self.iterative_mode == 0: self.last_ticket = None self.current_histo_data = None self.current_stats = None self.last_histo_data = None self.histo_index = -1 self.plot_canvas.plot_histo(beam._beam, var, self.rays, xrange, self.weight_column_index, title, xtitle, ytitle, nbins=self.number_of_bins, xum=xum, conv=self.workspace_units_to_cm) elif self.iterative_mode == 1: self.current_histo_data = None self.current_stats = None self.last_histo_data = None self.histo_index = -1 self.last_ticket = self.plot_canvas.plot_histo( beam._beam, var, self.rays, xrange, self.weight_column_index, title, xtitle, ytitle, nbins=self.number_of_bins, xum=xum, conv=self.workspace_units_to_cm, ticket_to_add=self.last_ticket) else: if not beam.scanned_variable_data is None: self.last_ticket = None self.histo_index += 1 um = beam.scanned_variable_data.get_scanned_variable_um() um = " " + um if um.strip() == "" else " [" + um + "]" histo_data = self.plot_canvas.plot_histo( beam=beam, col=var, nbins=self.number_of_bins, title=title, xtitle=xtitle, ytitle=ytitle, histo_index=self.histo_index, scan_variable_name=beam.scanned_variable_data. get_scanned_variable_display_name() + um, scan_variable_value=beam.scanned_variable_data. get_scanned_variable_value(), offset=0.0 if self.last_histo_data is None else self.last_histo_data.offset, xrange=xrange, show_reference=False, add_labels=self.add_labels == 1, has_colormap=self.has_colormap == 1) scanned_variable_value = beam.scanned_variable_data.get_scanned_variable_value( ) if isinstance(scanned_variable_value, str): histo_data.scan_value = self.histo_index + 1 else: histo_data.scan_value = beam.scanned_variable_data.get_scanned_variable_value( ) if not histo_data.bins is None: if self.current_histo_data is None: self.current_histo_data = HistogramDataCollection( histo_data) else: self.current_histo_data.add_histogram_data(histo_data) if self.current_stats is None: self.current_stats = StatisticalDataCollection(histo_data) else: self.current_stats.add_statistical_data(histo_data) self.last_histo_data = histo_data if self.sigma_fwhm_size == 0: sizes = self.current_stats.get_sigmas() label_size = "Sigma " + xum else: sizes = self.current_stats.get_fwhms() label_size = "FWHM " + xum if self.absolute_relative_intensity == 0: #relative if self.peak_integral_intensity == 0: # peak intensities = self.current_stats.get_relative_peak_intensities( ) label_intensity = "Relative Peak Intensity" else: intensities = self.current_stats.get_relative_integral_intensities( ) label_intensity = "Relative Integral Intensity" else: if self.peak_integral_intensity == 0: # peak intensities = self.current_stats.get_absolute_peak_intensities( ) label_intensity = "Absolute Peak Intensity" else: intensities = self.current_stats.get_absolute_integral_intensities( ) label_intensity = "Absolute Integral Intensity" self.plot_canvas_stats.plotCurves( self.current_stats.get_scan_values(), sizes, intensities, "Statistics", beam.scanned_variable_data. get_scanned_variable_display_name() + um, label_size, label_intensity)
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(False) self.spectro_plot_canvas.setDefaultPlotPoints(True) 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() self.spectro_plot_canvas.setDefaultPlotLines(False) self.spectro_plot_canvas.setDefaultPlotPoints(True) ax3 = self.spectro_plot_canvas._plot.graph.fig.axes[-1] ax3.cla() number_of_bins = self.spectro_number_of_bins + 1 x, y, auto_x_title, auto_y_title, xum, yum = self.get_titles() if self.plotted_beam is None: self.plotted_beam = self.input_beam xrange, yrange = self.get_ranges(self.plotted_beam._beam, x, y) 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) factor_y = ShadowPlot.get_factor(y, 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, y, factor_x, factor_y, title=self.title + str(index), color=color) self.spectro_plot_canvas.setGraphXLimits(xrange[0] * factor_x, xrange[1] * factor_x) self.spectro_plot_canvas.setGraphYLimits(yrange[0] * factor_y, yrange[1] * factor_y) self.spectro_plot_canvas.setGraphXLabel(auto_x_title) self.spectro_plot_canvas.setGraphYLabel(auto_y_title) self.spectro_plot_canvas.replot()
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)
def plot_histo(self, beam, col, nbins=100, title="", xtitle="", ytitle="", histo_index=0, scan_variable_name="Variable", scan_variable_value=0, offset=0.0, xrange=None, show_reference=True, add_labels=True, has_colormap=True, colormap=cm.rainbow): factor = ShadowPlot.get_factor(col, conv=self.workspace_units_to_cm) if histo_index == 0 and xrange is None: ticket = beam._beam.histo1(col, xrange=None, nbins=nbins, nolost=1, ref=23) fwhm = ticket['fwhm'] xrange = ticket['xrange'] centroid = xrange[0] + (xrange[1] - xrange[0]) * 0.5 if not fwhm is None: xrange = [centroid - 2 * fwhm, centroid + 2 * fwhm] ticket = beam._beam.histo1(col, xrange=xrange, nbins=nbins, nolost=1, ref=23) if not ytitle is None: ytitle = ytitle + ' weighted by ' + ShadowPlot.get_shadow_label(23) histogram = ticket['histogram_path'] bins = ticket['bin_path'] * factor histogram_stats = ticket['histogram'] bins_stats = ticket['bin_center'] fwhm = ticket['fwhm'] sigma = get_sigma(histogram_stats, bins_stats) * factor fwhm = sigma * 2.35 if fwhm is None else fwhm * factor peak_intensity = numpy.average(histogram_stats[numpy.where( histogram_stats >= numpy.max(histogram_stats) * 0.85)]) if histo_index == 0 and show_reference: h_title = "Reference" else: h_title = scan_variable_name + ": " + str(scan_variable_value) color = "#000000" import matplotlib matplotlib.rcParams['axes.formatter.useoffset'] = 'False' if histo_index == 0: offset = int(peak_intensity * 0.3) self.plot_canvas.addCurve(bins, histogram + offset * histo_index, h_title, symbol='', color=color, xlabel=xtitle, ylabel=ytitle, replace=False) #'+', '^', ',' if add_labels: self.plot_canvas._backend.ax.text(xrange[0] * factor * 1.05, offset * histo_index * 1.05, h_title) if not xtitle is None: self.plot_canvas.setGraphXLabel(xtitle) if not ytitle is None: self.plot_canvas.setGraphYLabel(ytitle) if not title is None: self.plot_canvas.setGraphTitle(title) for label in self.plot_canvas._backend.ax.yaxis.get_ticklabels(): label.set_color('white') label.set_fontsize(1) self.plot_canvas.setActiveCurveColor(color="#00008B") self.plot_canvas.setDrawModeEnabled(True, 'rectangle') self.plot_canvas.setInteractiveMode('zoom', color='orange') self.plot_canvas.resetZoom() self.plot_canvas.replot() self.plot_canvas.setGraphXLimits(xrange[0] * factor, xrange[1] * factor) self.plot_canvas.setActiveCurve(h_title) self.plot_canvas.setDefaultPlotLines(True) self.plot_canvas.setDefaultPlotPoints(False) self.plot_canvas.getLegendsDockWidget().setFixedHeight(510) self.plot_canvas.getLegendsDockWidget().setVisible(True) self.plot_canvas.addDockWidget(Qt.RightDockWidgetArea, self.plot_canvas.getLegendsDockWidget()) return HistogramData(histogram_stats, bins_stats, offset, xrange, fwhm, sigma, peak_intensity)
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 = oasysgui.plotWindow(roi=False, control=False, position=True) self.plot_canvas_x.setDefaultPlotLines(True) self.plot_canvas_x.setActiveCurveColor(color='blue') self.plot_canvas_x.setInteractiveMode(mode='zoom') self.plot_canvas_x.toolBar().setVisible(False) self.plot_canvas_z = oasysgui.plotWindow(roi=False, control=False, position=True) self.plot_canvas_z.setDefaultPlotLines(True) self.plot_canvas_z.setActiveCurveColor(color='red') self.plot_canvas_z.setInteractiveMode(mode='zoom') self.plot_canvas_z.toolBar().setVisible(False) self.plot_canvas_t = oasysgui.plotWindow(roi=False, control=False, position=True) self.plot_canvas_t.setDefaultPlotLines(True) self.plot_canvas_t.setActiveCurveColor(color='green') self.plot_canvas_t.setInteractiveMode(mode='zoom') self.plot_canvas_t.toolBar().setVisible(False) gridLayout = QtWidgets.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 = QtWidgets.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._backend.ax.get_yaxis().get_major_formatter( ).set_useOffset(True) self.plot_canvas_x._backend.ax.get_yaxis().get_major_formatter( ).set_scientific(True) self.plot_canvas_x._backend.ax.set_position(pos) self.plot_canvas_x._backend.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._backend.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._backend.ax.get_yaxis().get_major_formatter( ).set_useOffset(True) self.plot_canvas_z._backend.ax.get_yaxis().get_major_formatter( ).set_scientific(True) self.plot_canvas_z._backend.ax.set_position(pos) self.plot_canvas_z._backend.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._backend.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._backend.ax.get_yaxis().get_major_formatter( ).set_useOffset(True) self.plot_canvas_t._backend.ax.get_yaxis().get_major_formatter( ).set_scientific(True) self.plot_canvas_t._backend.ax.set_position(pos) self.plot_canvas_t._backend.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._backend.ax.set_title( "X,Z (Combined)", horizontalalignment='left') self.plot_canvas_t.replot()
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")
def replace_fig(self, beam, var, xrange, title, xtitle, ytitle, xum): if self.plot_canvas is None: if self.iterative_mode < 2: self.plot_canvas = ShadowPlot.DetailedHistoWidget( y_scale_factor=1.14) else: if self.plot_type == 0: self.plot_canvas = ScanHistoWidget( self.workspace_units_to_cm) elif self.plot_type == 1: self.plot_canvas = Scan3DHistoWidget( self.workspace_units_to_cm, type=Scan3DHistoWidget.PlotType.LINES if self.plot_type_3D == 0 else Scan3DHistoWidget.PlotType.SURFACE) self.plot_canvas_stats = DoublePlotWidget(parent=None) self.image_box_stats.layout().addWidget(self.plot_canvas_stats) self.image_box.layout().addWidget(self.plot_canvas) try: if self.iterative_mode == 0: self.last_ticket = None self.current_histo_data = None self.current_stats = None self.last_histo_data = None self.histo_index = -1 self.plot_canvas.plot_histo(beam._beam, var, self.rays, xrange, self.weight_column_index, title, xtitle, ytitle, nbins=self.number_of_bins, xum=xum, conv=self.workspace_units_to_cm) elif self.iterative_mode == 1: self.current_histo_data = None self.current_stats = None self.last_histo_data = None self.histo_index = -1 self.last_ticket = self.plot_canvas.plot_histo( beam._beam, var, self.rays, xrange, self.weight_column_index, title, xtitle, ytitle, nbins=self.number_of_bins, xum=xum, conv=self.workspace_units_to_cm, ticket_to_add=self.last_ticket) else: if not beam.scanned_variable_data is None: self.last_ticket = None self.histo_index += 1 histo_data = self.plot_canvas.plot_histo( beam=beam, col=var, nbins=self.number_of_bins, title=title, xtitle=xtitle, ytitle=ytitle, histo_index=self.histo_index, scan_variable_name=beam.scanned_variable_data. get_scanned_variable_display_name() + " [" + beam.scanned_variable_data.get_scanned_variable_um() + "]", scan_variable_value=beam.scanned_variable_data. get_scanned_variable_value(), offset=0.0 if self.last_histo_data is None else self.last_histo_data.offset, xrange=xrange, show_reference=False, add_labels=self.add_labels == 1, has_colormap=self.has_colormap == 1) histo_data.scan_value = beam.scanned_variable_data.get_scanned_variable_value( ) if not histo_data.bins is None: if self.current_histo_data is None: self.current_histo_data = HistogramDataCollection( histo_data) else: self.current_histo_data.add_histogram_data( histo_data) if self.current_stats is None: self.current_stats = StatisticalDataCollection( histo_data) else: self.current_stats.add_statistical_data(histo_data) self.last_histo_data = histo_data self.plot_canvas_stats.plotCurves( self.current_stats.get_scan_values(), self.current_stats.get_sigmas() if self.stats_to_plot == 0 else self.current_stats.get_fwhms(), self.current_stats.get_relative_intensities(), "Statistics", beam.scanned_variable_data. get_scanned_variable_display_name() + " [" + beam.scanned_variable_data.get_scanned_variable_um() + "]", "Sigma " + xum if self.stats_to_plot == 0 else "FWHM " + xum, "Relative Peak Intensity") except Exception as e: if self.IS_DEVELOP: raise e else: raise Exception( "Data not plottable: No good rays or bad content")
def replace_fig(self, shadow_beam, var_x, var_y, xrange, yrange, nbins, nolost): if self.plot_canvas is None: self.plot_canvas = PowerPlotXYWidget() self.image_box.layout().addWidget(self.plot_canvas) try: if self.autosave == 1: if self.autosave_file is None: self.autosave_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(self.autosave_file_name)) elif self.autosave_file.filename != congruence.checkFileName(self.autosave_file_name): self.autosave_file.close() self.autosave_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(self.autosave_file_name)) if self.keep_result == 1: self.cumulated_ticket, last_ticket = self.plot_canvas.plot_power_density(shadow_beam, var_x, var_y, self.total_power, self.cumulated_total_power, self.energy_min, self.energy_max, self.energy_step, nbins=nbins, xrange=xrange, yrange=yrange, nolost=nolost, ticket_to_add=self.cumulated_ticket, to_mm=self.workspace_units_to_mm, show_image=self.view_type==1, kind_of_calculation=self.kind_of_calculation, replace_poor_statistic=self.replace_poor_statistic, good_rays_limit=self.good_rays_limit, center_x=self.center_x, center_y=self.center_y, sigma_x=self.sigma_x, sigma_y=self.sigma_y, gamma=self.gamma) self.plotted_ticket = self.cumulated_ticket self.plotted_ticket_original = self.plotted_ticket.copy() if self.autosave == 1: self.autosave_file.write_coordinates(self.cumulated_ticket) dataset_name = "power_density" self.autosave_file.add_plot_xy(self.cumulated_ticket, dataset_name=dataset_name) if self.autosave_partial_results == 1: if last_ticket is None: self.autosave_file.add_plot_xy(self.cumulated_ticket, plot_name="Energy Range: " + str(round(self.energy_max-self.energy_step, 2)) + "-" + str(round(self.energy_max, 2)), dataset_name=dataset_name) else: self.autosave_file.add_plot_xy(last_ticket, plot_name="Energy Range: " + str(round(self.energy_max-self.energy_step, 2)) + "-" + str(round(self.energy_max, 2)), dataset_name=dataset_name) self.autosave_file.flush() else: ticket, _ = self.plot_canvas.plot_power_density(shadow_beam, var_x, var_y, self.total_power, self.cumulated_total_power, self.energy_min, self.energy_max, self.energy_step, nbins=nbins, xrange=xrange, yrange=yrange, nolost=nolost, to_mm=self.workspace_units_to_mm, show_image=self.view_type==1, kind_of_calculation=self.kind_of_calculation, replace_poor_statistic=self.replace_poor_statistic, good_rays_limit=self.good_rays_limit, center_x=self.center_x, center_y=self.center_y, sigma_x=self.sigma_x, sigma_y=self.sigma_y, gamma=self.gamma) self.cumulated_ticket = None self.plotted_ticket = ticket self.plotted_ticket_original = self.plotted_ticket.copy() if self.autosave == 1: self.autosave_file.write_coordinates(ticket) self.autosave_file.add_plot_xy(ticket, dataset_name="power_density") self.autosave_file.flush() except Exception as e: if not self.IS_DEVELOP: raise Exception("Data not plottable: No good rays or bad content") else: raise e
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 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()