def on_add_peak(self, *_args): """Adds a peak to the currently active region.""" regionID = self.view.get_active_region() def create_peak(center, height, angle): """Add peak""" if self.view.get_visible("region-background"): peakID = self.dh.add_peak(regionID, totalheight=height, angle=angle, center=center) else: peakID = self.dh.add_peak(regionID, height=height, angle=angle, center=center) logger.info("added peak {} to region {}".format(peakID, regionID)) wedgeprops = { "edgecolor": __colors__.get("plotting", "peak-wedge-edge"), "facecolor": __colors__.get("plotting", "peak-wedge-face") } plot_toolbar = self.builder.get_object("plot_toolbar") rmin = self.dh.get(regionID, "emin") rmax = self.dh.get(regionID, "emax") plot_toolbar.get_wedge(create_peak, **wedgeprops, limits=(rmin, rmax))
def render_isplotted(_col, renderer, model, iter_, *_data): """Renders the cell light blue if this spectrum is plotted.""" if model.get_value(iter_, col_index_active): renderer.set_property( "cell-background", __colors__.get("treeview", "tv-highlight-bg")) renderer.set_property("weight", Pango.Weight.BOLD) else: renderer.set_property("cell-background", bgcolor) renderer.set_property("weight", Pango.Weight.NORMAL)
def set_ticks(self): """Configures axes ticks.""" self.ax.spines["bottom"].set_visible(False) self.ax.tick_params( reset=True, axis="both", direction="out", # pad=-20, labelsize="large", labelcolor=__colors__.get("plotting", "axisticks"), color=__colors__.get("plotting", "axisticks"), labelleft=False, top=False, left=False, right=False, bottom=False) if self._xy[0] == np.inf: self.ax.tick_params(which="both", bottom=False, top=False, left=False, right=False, labelbottom=False)
def _plot_rsfs(self, elements, source): """Plots RSF values for given elements with given X-ray souce.""" # fetch data through the rsfhandler if not self._doplot["rsfs"]: return rsfs = [] for element in elements: dicts = self.rsfhandler.get_element(element, source) if dicts: rsfs.append(dicts) else: logger.warning("canvas: element {} not found".format(element)) # set up colors and maximum rsf intensity for scaling the vlines if not rsfs: return max_rsf = max(max([[d["RSF"] + 1e-9 for d in ds] for ds in rsfs])) colorstr = __colors__.get("plotting", "rsf-vlines").replace(" ", "") colors = colorstr.split(",") * 10 # plot the individual vlines for i, peaks in enumerate(rsfs): for peak in peaks: if peak["RSF"] == 0: rsf = 0.5 * self._fig.get_ymax() else: rsf = peak["RSF"] * self._fig.get_ymax() / max_rsf * 0.8 self._ax.vlines(peak["BE"], 0, rsf, colors=colors[i], lw=2) self._ax.annotate(peak["Fullname"], xy=(peak["BE"], rsf), color=__colors__.get("plotting", "rsf-annotation"), textcoords="data", ha="center", va="bottom")
def _plot_peak(self, peakID): """Plots a peak.""" energy = self._dh.get(peakID, "energy") background = self._dh.get(peakID, "background") if not self._doplot["region-background"]: background = [0] * len(background) fit_cps = self._dh.get(peakID, "fit_cps") if self._doplot["peak"]: if peakID == ActiveIDs.PEAK: color = __colors__.get("plotting", "peak-active") lineprops = { "color": color, "linewidth": 1, "linestyle": "--", "alpha": 0.2 } self._ax.fill_between(energy, background + fit_cps, background, **lineprops) self._ax.plot(energy, background + fit_cps, **lineprops) else: color = __colors__.get("plotting", "peak") lineprops = {"color": color, "linewidth": 1, "linestyle": "--"} self._ax.plot(energy, background + fit_cps, **lineprops)
def on_add_region(self, _widget, *_args): """Adds a region to the currently selected spectrum.""" spectrumIDs = self.view.get_active_spectra() if len(spectrumIDs) != 1: return spectrumID = spectrumIDs[0] def create_region(emin, emax): """Add region""" regionID = self.dh.add_region(spectrumID, emin=emin, emax=emax) logger.info("added region {} to spectrum {}" "".format(regionID, spectrumID)) rectcolor = __colors__.get("plotting", "region-vlines") rectprops = {"edgecolor": rectcolor, "linewidth": 2} plot_toolbar = self.builder.get_object("plot_toolbar") plot_toolbar.get_span(create_region, **rectprops)
def plot(self, keepaxes=True): """Plots every ID in self._plotIDs after checking for child and grandchild IDs. Also plots RSF data""" if keepaxes: self._fig.store_xylims() self._update_active() # check if there actually is something to plot if not self._plotIDs: self._draglines.clear() self._ax.cla() self._fig.restore_xylims() self._canvas.draw_idle() self._navbar.disable_tools() return self._draglines.clear() self._fig.reset_xy_centerlims() self._ax.cla() s_colorstr = __colors__.get("plotting", "spectra").replace(" ", "") s_colors = cycle(s_colorstr.split(",")) # call the individual plot jobs for ID in self._plotIDs: if self._dh.isspectrum(ID): self._plot_spectrum(ID, next(s_colors)) elif self._dh.isregion(ID): self._plot_region(ID) elif self._dh.ispeak(ID): self._plot_peak(ID) else: raise TypeError("ID {} can not be plotted".format(ID)) if self.rsf_filter[0]: self._plot_rsfs(self.rsf_filter[0], self.rsf_filter[1]) logger.debug("canvas: plot rsfs {}".format(self.rsf_filter)) # restore xylims if necessary and then redraw if keepaxes: self._fig.restore_xylims() else: self._fig.center_view() self._canvas.draw_idle() self._navbar.disable_tools() logger.debug("canvas: plot IDs {}".format(self._plotIDs))
def _plot_region(self, regionID): """Plots a region by plotting its limits with DraggableVLines and plotting the background intensity.""" emin = self._dh.get(regionID, "emin") emax = self._dh.get(regionID, "emax") energy = self._dh.get(regionID, "energy") background = self._dh.get(regionID, "background") if not self._doplot["region-background"]: background = [0] * len(background) fit_cps = self._dh.get(regionID, "fit_cps") if self._doplot["region-boundaries"]: if regionID == ActiveIDs.REGION: color = __colors__.get("plotting", "region-vlines-active") else: color = __colors__.get("plotting", "region-vlines") lineprops = { "color": color, "linewidth": 2, "linestyle": "--", "alpha": 1 } line = self._ax.axvline(emin, 0, 1, **lineprops) self._draglines.append( DraggableAttributeLine(line, regionID, "emin", self.dragline_callback)) line = self._ax.axvline(emax, 0, 1, **lineprops) self._draglines.append( DraggableAttributeLine(line, regionID, "emax", self.dragline_callback)) if self._doplot["region-background"] and any(background): if regionID == ActiveIDs.REGION: color = __colors__.get("plotting", "region-background-active") else: color = __colors__.get("plotting", "region-background") lineprops = {"color": color, "linewidth": 1, "linestyle": "--"} self._ax.plot(energy, background, **lineprops) if self._doplot["region-fit"] and any(fit_cps): if regionID == ActiveIDs.REGION: color = __colors__.get("plotting", "peak-sum-active") else: color = __colors__.get("plotting", "peak-sum") lineprops = {"color": color, "linewidth": 1, "linestyle": "--"} self._ax.plot(energy, background + fit_cps, **lineprops)