def set_statistics(self, stats_for=None): if stats_for == self.pc_name: from pca4cd.gui.main_analysis_dialog import MainAnalysisDialog with block_signals_to(self.QCBox_StatsLayer): self.QCBox_StatsLayer.setCurrentIndex(0) self.statistics(self.pc_data_flat, MainAnalysisDialog.pca_stats) self.histogram_plot(data=self.pc_data_flat) if stats_for == "Areas Of Interest": with block_signals_to(self.QCBox_StatsLayer): self.QCBox_StatsLayer.setCurrentIndex(1) self.statistics(self.aoi_data) self.histogram_plot(data=self.aoi_data)
def enable(self): with block_signals_to(self.render_widget): # activate some parts of this view self.QLabel_ViewName.setEnabled(True) self.render_widget.setEnabled(True) self.layerStyleEditor.setEnabled(True) self.render_widget.canvas.setCanvasColor(QColor(255, 255, 255)) # set status for view widget self.is_active = True
def disable(self): with block_signals_to(self.render_widget): self.render_widget.canvas.setLayers([]) self.render_widget.canvas.clearCache() self.render_widget.canvas.refresh() self.render_widget.layer = None # deactivate some parts of this view self.QLabel_ViewName.setDisabled(True) self.render_widget.setDisabled(True) self.layerStyleEditor.setDisabled(True) self.render_widget.canvas.setCanvasColor(QColor(245, 245, 245)) # set status for view widget self.is_active = False
def render_layer(self, layer): with block_signals_to(self): # set the CRS of the canvas view if self.crs: self.canvas.setDestinationCrs(self.crs) # set the sampling over the layer to view self.canvas.setLayers([layer]) # set init extent from other view if any is activated else set layer extent from pca4cd.gui.main_analysis_dialog import MainAnalysisDialog others_view = [ view_widget.render_widget.canvas.extent() for view_widget in MainAnalysisDialog.view_widgets if not view_widget.render_widget.canvas.extent().isEmpty() ] if others_view: extent = others_view[0] self.update_canvas_to(extent) else: self.canvas.setExtent(layer.extent()) self.canvas.refresh() self.layer = layer
def histogram_plot(self, data=None, bins=None): # which plot stats_for = self.QCBox_StatsLayer.currentText() if stats_for == self.pc_name: hist_bins = self.hist_bins["pc"] if stats_for == "Areas Of Interest": hist_bins = self.hist_bins["aoi"] # check and set data if data is not None: self.hist_data = data if self.hist_data is None or self.hist_data.size <= 1: self.HistogramPlot.clear() return # histogram bins if bins is not None: if isinstance(bins, int): set_bins = bins elif bins == "custom": hist_bins["type"] = bins self.HistogramCustomBins.show() self.HistogramCustomBins.setValue(hist_bins["bins"]) return else: self.HistogramCustomBins.hide() hist_bins["type"] = bins set_bins = bins else: # from set_statistics functions if hist_bins["type"] == "custom": set_bins = hist_bins["bins"] self.HistogramCustomBins.show() with block_signals_to(self.HistogramTypeBins): self.HistogramTypeBins.setCurrentIndex( self.HistogramTypeBins.findText("custom")) with block_signals_to(self.HistogramCustomBins): self.HistogramCustomBins.setValue(hist_bins["bins"]) else: set_bins = hist_bins["type"] self.HistogramCustomBins.hide() with block_signals_to(self.HistogramTypeBins): self.HistogramTypeBins.setCurrentIndex( self.HistogramTypeBins.findText(hist_bins["type"])) # plot if stats_for == self.pc_name and set_bins in [ "auto", "doane", "scott", "rice" ]: if self.hist_data_pc[set_bins] is not None: y, x = self.hist_data_pc[set_bins] # restore histogram values else: try: bin_edges = np.histogram_bin_edges(self.hist_data, bins=set_bins) da_hist_data = da.from_array(self.hist_data, chunks=(8000000, )) y, x = da.histogram(da_hist_data, bins=bin_edges) y = y.compute(scheduler='threads', num_workers=cpu_count()) except: # TODO: after some time delete, compatibility to old numpy version Qgis < 3.4 y, x = np.histogram(self.hist_data, bins=set_bins) self.hist_data_pc[set_bins] = (y, x) else: try: bin_edges = np.histogram_bin_edges(self.hist_data, bins=set_bins) da_hist_data = da.from_array(self.hist_data, chunks=(8000000, )) y, x = da.histogram(da_hist_data, bins=bin_edges) y = y.compute(scheduler='threads', num_workers=cpu_count()) except: # TODO: after some time delete, compatibility to old numpy version Qgis < 3.4 y, x = np.histogram(self.hist_data, bins=set_bins) self.HistogramPlot.clear() self.HistogramPlot.plot(x, y, stepMode=True, fillLevel=0, brush=(80, 80, 80)) self.HistogramPlot.autoRange() self.HistogramPlot.addItem(self.linear_region) hist_bins["bins"] = len(y) # store bins
def update_canvas_to(self, new_extent): with block_signals_to(self.canvas): self.canvas.setExtent(new_extent) self.canvas.refresh()