diff --git a/eis_qgis_plugin/wizard/old/basic_plots_pyqtgraph.py b/eis_qgis_plugin/wizard/old/basic_plots_pyqtgraph.py deleted file mode 100644 index ed84ca2..0000000 --- a/eis_qgis_plugin/wizard/old/basic_plots_pyqtgraph.py +++ /dev/null @@ -1,190 +0,0 @@ -import numpy as np -from qgis.core import QgsMapLayer -from qgis.gui import ( - QgsColorButton, - QgsFieldComboBox, - QgsMapLayerComboBox, - QgsOpacityWidget, -) -from qgis.PyQt.QtWidgets import QComboBox, QPushButton, QVBoxLayout, QWidget - -from eis_qgis_plugin import pyqtgraph as pg -from eis_qgis_plugin.qgis_plugin_tools.tools.resources import load_ui - -from .plot_utils import ( - CHART_MAPPINGS, - ChartType, - create_brush, - create_pen, - opacity_to_alpha, - update_color_selection, -) - -FORM_CLASS: QWidget = load_ui("explore/basic_charts_tab.ui") - - -### TEST DATA -chi_data = np.random.chisquare(2, 100) -normal_data = np.random.normal(size=100, loc=0) -x_data = np.arange(-50, 50) -line_test_data_1 = x_data, normal_data -line_test_data_2 = x_data, chi_data - -SCATTER_TEST_DATA = [ - np.random.normal(size=(2, 1000)), - np.random.normal(size=(2, 500), loc=4), -] -LINE_TEST_DATA = [line_test_data_1, line_test_data_2] -BAR_TEST_DATA = line_test_data_1 -BOX_TEST_DATA = normal_data, chi_data - -chi_data_1000 = np.random.chisquare(2, 1000) -normal_data_1000 = np.random.normal(size=1000, loc=5) -x_data_1000 = np.arange(1000) -HISTOGRAM_TEST_DATA = np.array([chi_data_1000, normal_data_1000]) - - -class BasicCharts(QWidget, FORM_CLASS): - # Plot parameters - layer_selection: QgsMapLayerComboBox - chart_selection: QComboBox - x_data_selection: QgsFieldComboBox - y_data_selection: QgsFieldComboBox - - # Plot style parameters - color_selection: QgsColorButton - marker_type_selection: QComboBox - line_type_selection: QComboBox - opacity_selection: QgsOpacityWidget - - # Other widgets - plot_container: QWidget - plot_button: QPushButton - clear_button: QPushButton - - def __init__(self): - # Initialize - super().__init__() - self.setupUi(self) - self.init_basic_charts() - - self.plot_number = 0 - - # Connect signals - self.layer_selection.layerChanged.connect(self.update_plot_parameters) - self.plot_button.clicked.connect(self.plot) - self.clear_button.clicked.connect(self.clear_plots) - - # Populate widgets - self.update_plot_parameters(self.layer_selection.currentLayer()) - update_color_selection(self.color_selection, self.plot_number) - - def init_basic_charts(self): - self.plot_widget = pg.PlotWidget(parent=self.plot_container) - self.plot_widget.setMinimumSize(450, 430) - self.styles = {"color": "r", "font-size": "14px"} - self.plot_widget.setLabel("left", "Y label", **self.styles) - self.plot_widget.setLabel("bottom", "X label", **self.styles) - self.plot_widget.addLegend() - self.plot_widget.setBackground("w") - self.plot_widget.setTitle("Chart title") - - self.plot_layout = QVBoxLayout(self.plot_container) - self.plot_layout.addWidget(self.plot_widget) - - def update_plot_parameters(self, layer: QgsMapLayer) -> None: - if layer is not None: - self.x_data_selection.setLayer(layer) - self.y_data_selection.setLayer(layer) - - def clear_plots(self): - """Called when clear_button is clicked. - - Clears all plots currently in the plot widget.""" - self.plot_widget.clear() - self.plot_number = 0 - update_color_selection(self.color_selection, self.plot_number) - - def get_field_data(self, layer, field_name): - return [feature[field_name] for feature in layer.getFeatures()] - - def plot(self): - """Called when plot_button is clicked. - - Calls a plot creation function based on chart type selection.""" - chart_type = CHART_MAPPINGS[self.chart_selection.currentText().lower()] - - if chart_type == ChartType.SCATTER: - # print(SCATTER_TEST_DATA[self.plot_number]) - layer = self.layer_selection.currentLayer() - - x_field = self.x_data_selection.currentField() - x_field_data = self.get_field_data(layer, x_field) - - y_field = self.y_data_selection.currentField() - y_field_data = self.get_field_data(layer, y_field) - - data = np.array([x_field_data, y_field_data]) - self.plot_scatterplot(data) - - self.plot_widget.setLabel("left", y_field, **self.styles) - self.plot_widget.setLabel("bottom", x_field, **self.styles) - - self.plot_number += 1 - - elif chart_type == ChartType.LINE: - self.plot_line_plot(LINE_TEST_DATA[self.plot_number]) - self.plot_number += 1 - - elif chart_type == ChartType.BAR: - self.plot_bar_plot(BAR_TEST_DATA) - self.plot_number += 1 - - elif chart_type == ChartType.HISTOGRAM: - self.plot_histogram(HISTOGRAM_TEST_DATA) - self.plot_number += 1 - - else: - print("Not implemented yet") - - update_color_selection(self.color_selection, self.plot_number) - - def plot_scatterplot(self, data): - brush = create_brush( - self.color_selection, opacity_to_alpha(self.opacity_selection.opacity()) - ) - scatterplot = pg.ScatterPlotItem(size=8, brush=brush) - pos = [{"pos": data[:, i]} for i in range(data.shape[1])] - scatterplot.setData(pos) - self.plot_widget.addItem(scatterplot) - - def plot_line_plot(self, data): - pen = create_pen( - self.color_selection, opacity_to_alpha(self.opacity_selection.opacity()) - ) - data_x = data[0] - data_y = data[1] - self.plot_widget.plot( - data_x, data_y, name=f"Dataset {self.plot_number}", pen=pen - ) - - def plot_bar_plot(self, data): - brush = create_brush( - self.color_selection, opacity_to_alpha(self.opacity_selection.opacity()) - ) - bargraph = pg.BarGraphItem(x=data[0], height=data[1], width=0.5, brush=brush) - self.plot_widget.addItem(bargraph) - - def plot_histogram(self, data): - brush = create_brush( - self.color_selection, opacity_to_alpha(self.opacity_selection.opacity()) - ) - hist, bins = np.histogram(data) - self.plot_widget.plot( - bins, - hist, - name=f"Dataset {self.plot_number}", - stepMode=True, - fillLevel=0, - brush=brush, - ) diff --git a/eis_qgis_plugin/wizard/old/create_proxy.py b/eis_qgis_plugin/wizard/old/create_proxy.py deleted file mode 100644 index c514310..0000000 --- a/eis_qgis_plugin/wizard/old/create_proxy.py +++ /dev/null @@ -1,47 +0,0 @@ -from PyQt5.QtWidgets import QWizardPage -from qgis import processing -from qgis.PyQt.QtWidgets import ( - QDialog, -) - -from eis_qgis_plugin.qgis_plugin_tools.tools.resources import load_ui - -from ...explore.old.wizard_explore import EISWizardExplore - -FORM_CLASS: QDialog = load_ui("preprocess/proxy_view_with_links.ui") - - -class EISWizardProxyCreation(QWizardPage, FORM_CLASS): - def __init__(self, parent) -> None: - super().__init__(parent) - self.setupUi(self) - - self.open_explore_btn.clicked.connect(self.open_explore) - - self.extract_by_attribute_btn.clicked.connect( - lambda: processing.execAlgorithmDialog("qgis:extractbyattribute", {}) - ) - self.extract_by_expression_btn.clicked.connect( - lambda: processing.execAlgorithmDialog("qgis:extractbyexpression", {}) - ) - - self.calculate_distances_vector_btn.clicked.connect( - lambda: processing.execAlgorithmDialog("eis:distance_computation", {}) - ) - self.calculate_distances_raster_btn.clicked.connect( - lambda: processing.execAlgorithmDialog("eis:distance_computation", {}) - ) - self.calculate_density_btn.clicked.connect( - lambda: processing.execAlgorithmDialog("eis:vector_density", {}) - ) - self.interpolate_idw_btn.clicked.connect( - lambda: processing.execAlgorithmDialog("eis:simple_idw", {}) - ) - self.interpolate_kriging_btn.clicked.connect( - lambda: processing.execAlgorithmDialog("eis:kriging_interpolation", {}) - ) - # self.binarize_btn.clicked.connect(processing.execAlgorithmDialog("eis:", {}) ) - - def open_explore(self): - self.explore_window = EISWizardExplore(self) - self.explore_window.show() diff --git a/eis_qgis_plugin/wizard/old/create_proxy_wizard.py b/eis_qgis_plugin/wizard/old/create_proxy_wizard.py deleted file mode 100644 index 8e41a01..0000000 --- a/eis_qgis_plugin/wizard/old/create_proxy_wizard.py +++ /dev/null @@ -1,83 +0,0 @@ -import matplotlib.pyplot as plt -from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas -from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar -from qgis.core import QgsMapLayerProxyModel -from qgis.gui import QgsFieldComboBox, QgsFieldExpressionWidget, QgsMapLayerComboBox -from qgis.PyQt.QtWidgets import QDialog, QSizePolicy, QVBoxLayout, QWizardPage - -import eis_qgis_plugin.libs.seaborn as sns - -from ...explore.old.wizard_explore import EISWizardExplore - - -class EISWizardProxy(QWizardPage): - layer_selection: QgsMapLayerComboBox - attribute_selection: QgsFieldComboBox - field_expression: QgsFieldExpressionWidget - - def __init__(self, parent) -> None: - super().__init__(parent) - self.setupUi(self) - - self.layer_selection.setFilters(QgsMapLayerProxyModel.VectorLayer) - - self.layer_selection.layerChanged.connect(self.set_layer) - self.attribute_selection.fieldChanged.connect(self.set_field) - - # self.compute_and_plot_btn.clicked.connect(self.show_plot) - # self.compute_and_plot_btn.clicked.connect(self.show_plot2) - self.create_file_btn.clicked.connect(self.create_file) - self.open_explore_btn.clicked.connect(self.open_explore) - - def set_layer(self, layer): - self.attribute_selection.setLayer(layer) - self.set_field(self.attribute_selection.currentField()) - - def set_field(self, field_name): - self.field_expression.setField(field_name) - - def open_explore(self): - self.explore_window = EISWizardExplore(self) - self.explore_window.show() - - def create_file(self): - pass - - def show_plot2(self): - layout = QVBoxLayout() - - # Create Seaborn plot - penguins = sns.load_dataset("penguins") - fig, ax = plt.subplots() - sns.histplot(data=penguins, x="flipper_length_mm", ax=ax) - canvas = FigureCanvas(fig) - canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - - toolbar = NavigationToolbar(canvas, self.plot_widget) - layout.addWidget(toolbar) - layout.addWidget(canvas) - - self.plot_widget.setLayout(layout) - - def show_plot(self): - dialog = QDialog() - dialog.setWindowTitle("Seaborn Plot") - dialog.resize(500, 400) - - layout = QVBoxLayout() - - # Create Seaborn plot - tips = sns.load_dataset("tips") - fig, ax = plt.subplots() - sns.barplot(x="day", y="total_bill", data=tips, ax=ax) - # plt.show() - - # Embed plot into PyQt5 dialog - canvas = FigureCanvas(fig) - canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - toolbar = NavigationToolbar(canvas, dialog) - layout.addWidget(toolbar) - layout.addWidget(canvas) - - dialog.setLayout(layout) - dialog.exec_() diff --git a/eis_qgis_plugin/wizard/old/parallel_coordinates_plot.py b/eis_qgis_plugin/wizard/old/parallel_coordinates_plot.py deleted file mode 100644 index 9e9379c..0000000 --- a/eis_qgis_plugin/wizard/old/parallel_coordinates_plot.py +++ /dev/null @@ -1,214 +0,0 @@ -from qgis.core import QgsMapLayer, QgsStyle, QgsVectorLayer -from qgis.gui import ( - QgsColorButton, - QgsColorRampButton, - QgsFieldComboBox, - QgsMapLayerComboBox, - QgsOpacityWidget, -) -from qgis.PyQt.QtWidgets import ( - QComboBox, - QFormLayout, - QPushButton, - QVBoxLayout, - QWidget, -) - -from eis_qgis_plugin import pyqtgraph as pg -from eis_qgis_plugin.qgis_plugin_tools.tools.resources import load_ui - -from ..plot_utils import generate_color_mapping, opacity_to_alpha - -FORM_CLASS: QWidget = load_ui("explore/parallel_chart_tab.ui") - - -class ParallelChart(QWidget, FORM_CLASS): - plot_container_parallel: QWidget - - layer_selection_parallel: QgsMapLayerComboBox - color_field_selection_parallel: QgsFieldComboBox - color_selection_parallel: QgsColorButton - line_type_selection_parallel: QComboBox - line_opacity_parallel: QgsOpacityWidget - - plot_button_parallel: QPushButton - plot_button_parallel_plotly: QPushButton - plot_button_seaborn: QPushButton - clear_button_parallel: QPushButton - clear_seaborn: QPushButton - - plot_style_form: QFormLayout - - def __init__(self): - super().__init__() - self.setupUi(self) - self.init_parallel_plotting() - - # Connect signals - self.layer_selection_parallel.layerChanged.connect(self.update) - self.plot_button_parallel.clicked.connect(self.plot_parallel_coordinates) - self.plot_button_parallel_plotly.clicked.connect( - self.plot_parallel_coordinates_plotly - ) - self.plot_button_seaborn.clicked.connect(self.open_seaborn_graph) - self.clear_button_parallel.clicked.connect(self.clear) - self.clear_seaborn.clicked.connect(self.clear_fig) - - self.update(self.layer_selection_parallel.currentLayer()) - - def init_parallel_plotting(self): - # window = pg.GraphicsLayoutWidget() - # self.plot_widget_parallel = win.addPlot() - - # # Assuming you have a list of your variable names - # variable_names = ["var1", "var2", "var3"] - - # axis_items = [] - # for i, var in enumerate(variable_names): - # # create an AxisItem for this variable - # axis = AxisItem("left") - # # set the label of the AxisItem - # axis.setLabel(var) - # # Create a plot with axis - # plot_item = window.addPlot(axisItems={'left': axis}) - # # add the AxisItem to the plot - # axis.linkToView(plot_item.vb) - # axis_items.append(axis) - - # # Assuming you have some data for your variables - # data = [[1, 2, 3], [2, 3, 1], [3, 1, 2]] - - # for i, d in enumerate(data): - # # create a plot for this data, linked to the corresponding AxisItem - # plot_item.plot(d, pen=(i, len(data))) - - self.plot_widget_parallel = pg.PlotWidget(parent=self.plot_container_parallel) - self.plot_widget_parallel.setMinimumSize(450, 430) - self.plot_widget_parallel.setBackground("w") - self.plot_widget_parallel.setTitle("Parallel coordinates plot") - self.styles = {"color": "r", "font-size": "14px"} - self.plot_widget_parallel.setLabel("left", "Y label", **self.styles) - self.plot_widget_parallel.setLabel("bottom", "X label", **self.styles) - - self.plot_layout_parallel = QVBoxLayout(self.plot_container_parallel) - self.plot_layout_parallel.addWidget(self.plot_widget_parallel) - - # Add color ramp widget (it is not available in Qt Designer) - self.color_ramp_button = QgsColorRampButton() - self.plot_style_form.insertRow(1, "Color ramp", self.color_ramp_button) - - # Get the default style manager - style_manager = QgsStyle.defaultStyle() - - # Get a predefined color ramp by its name - spectral_color_ramp = style_manager.colorRamp("Spectral") - - self.color_ramp_button.setDefaultColorRamp(spectral_color_ramp) - self.color_ramp_button.setColorRamp(spectral_color_ramp) - - def update(self, layer: QgsMapLayer) -> None: - if layer is not None: - self.color_field_selection_parallel.setLayer(layer) - - def clear(self): - self.plot_widget_parallel.clear() - - @staticmethod - def normalize_value(layer: QgsVectorLayer, value: float, i: int): - data_min = float(layer.minimumValue(i)) - data_max = float(layer.maximumValue(i)) - if data_max != data_min: # to prevent division by zero - normalized_value = (value - data_min) / (data_max - data_min) - else: - normalized_value = 0 - return normalized_value - - def plot_parallel_coordinates(self): - layer = self.layer_selection_parallel.currentLayer() - if not layer: - print("No layer selected") - return - - color_field_name = self.color_field_selection_parallel.currentField() - if not color_field_name: - print("No category field selected") - return - - fields = layer.fields() - alpha = opacity_to_alpha(self.line_opacity_parallel.opacity()) - color_mapping = generate_color_mapping( - layer, color_field_name, self.color_ramp_button.colorRamp() - ) - numerical_field_names = [ - field.name() for field in fields if field.name() != color_field_name - ] - data_x = list(range(len(numerical_field_names))) - field_labels = zip(data_x, numerical_field_names) - - for feature in layer.getFeatures(): - # Determine feature color - color_field_value = feature[color_field_name] - pen_color = color_mapping[color_field_value] - pen = pg.mkPen( - pen_color.red(), pen_color.green(), pen_color.blue(), alpha, width=3 - ) - - # Collect data - data_y = [] - for i, field in enumerate(fields): - field_name = field.name() - if field_name in numerical_field_names: - value = float(feature[field_name]) - normalized_value = self.normalize_value(layer, value, i) - data_y.append(normalized_value) - - self.plot_widget_parallel.plot( - data_x, data_y, pen=pen, name=str(value), labels=field_labels - ) - - # Rename axis labels - bottom_axis = self.plot_widget_parallel.getAxis("bottom") - # print(numerical_field_names) - bottom_axis.setTicks([field_labels]) - - - def open_seaborn_graph(self): - from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas - from matplotlib.figure import Figure - from PyQt5.QtWidgets import QDialog, QVBoxLayout - - from eis_qgis_plugin.libs.seaborn import barplot - - # self.plot_dialog = QDialog() - - # layout = QVBoxLayout() - # self.plot_dialog.setLayout(layout) - - # pixmap = QtGui.QPixmap("/home/niko/Downloads/sns_out.svg") - # label = QLabel() - # label.setPixmap(pixmap) - - # layout.addWidget(label) - # self.plot_dialog.show() - - # In your main application / widget, you would then create and show the dialog: - dialog = QDialog() - self.fig = Figure() - self.canvas = FigureCanvas(self.fig) - - # Create a Seaborn plot - ax = self.fig.add_subplot(111) - barplot(x=[1, 2, 3, 4], y=[1, 2, 3, 4], ax=ax) - - # Add the Matplotlib canvas to the dialog - layout = QVBoxLayout() - layout.addWidget(self.canvas) - dialog.setLayout(layout) - self.canvas.draw() - - dialog.show() - dialog.exec() - - def clear_fig(self): - self.fig.clear() - self.canvas.draw() diff --git a/eis_qgis_plugin/wizard/old/wizard_explore.py b/eis_qgis_plugin/wizard/old/wizard_explore.py deleted file mode 100644 index 640d0e4..0000000 --- a/eis_qgis_plugin/wizard/old/wizard_explore.py +++ /dev/null @@ -1,120 +0,0 @@ -import numpy as np -from qgis.PyQt.QtWidgets import QDialog, QTabWidget, QVBoxLayout, QWidget -from qgis.utils import iface - -from eis_qgis_plugin import pyqtgraph as pg -from eis_qgis_plugin.qgis_plugin_tools.tools.resources import load_ui - -from .basic_plots_pyqtgraph import BasicCharts -from .parallel_coordinates_plot import ParallelChart - -FORM_CLASS: QDialog = load_ui("explore/wizard_explore_window.ui") - - -class EISWizardExplore(QDialog, FORM_CLASS): - tab_widget: QTabWidget - - container: QWidget - - def __init__(self, parent=None) -> None: - super().__init__(parent) - self.setupUi(self) - self.iface = iface - - self.basic_charts_tab = BasicCharts() - self.parallel_charts_tab = ParallelChart() - - self.tab_widget.addTab(self.basic_charts_tab, "Basic charts") - self.tab_widget.addTab(self.parallel_charts_tab, "Parallel coordinates") - - self.create_roi() - - def create_roi(self): - self.plot_widget_roi = pg.PlotWidget(parent=self.container) - roi = pg.ROI([10, 10], [10, 10]) - self.plot_widget_roi.addItem(roi) - - self.plot_widget_roi.setMinimumSize(450, 430) - self.styles = {"color": "r", "font-size": "14px"} - self.plot_widget_roi.setLabel("left", "Y label", **self.styles) - self.plot_widget_roi.setLabel("bottom", "X label", **self.styles) - self.plot_widget_roi.addLegend() - self.plot_widget_roi.setBackground("w") - self.plot_widget_roi.setTitle("Chart title") - - self.plot_layout = QVBoxLayout(self.container) - self.plot_layout.addWidget(self.plot_widget_roi) - - def plot_boxplot(self, data): - for i, dataset in enumerate(data): - for item in self.create_box(dataset, i): - self.plot_widget.addItem(item) - - def create_box(self, data, position): - # Data for box - quartile1 = np.percentile(data, 25) - quartile3 = np.percentile(data, 75) - med = np.median(data) - iqr = quartile3 - quartile1 - whisker = 1.5 * iqr - - # Exclude data beyond whiskers - data = data[(data > quartile1 - whisker) & (data < quartile3 + whisker)] - - width = 0.3 - - # Generate box - box = pg.ErrorBarItem( - x=np.array([position]), - y=np.array([med]), - height=np.array([quartile3 - quartile1]), - width=width, - brush=(0, 0, 0, 30), - ) - whisker_top = pg.ErrorBarItem( - x=np.array([position]), - y=np.array([quartile3]), - height=np.array([quartile3 - data.max()]), - width=width, - pen=(255, 0, 0), - ) - whisker_bottom = pg.ErrorBarItem( - x=np.array([position]), - y=np.array([quartile1]), - height=np.array([data.min() - quartile1]), - width=width, - pen=(255, 0, 0), - ) - - # Draw scatter points for all data - scatter = pg.ScatterPlotItem( - x=np.full(data.shape, position), - y=data, - pen=(0, 0, 50), - brush=(0, 0, 0), - size=5, - ) - - return [box, whisker_top, whisker_bottom, scatter] - - -class EISWizardExploreBig( - QDialog, load_ui("old_designs_and_tests/wizard_explore_big_plotly_test.ui") -): - def __init__(self) -> None: - super().__init__() - self.setupUi(self) - self.iface = iface - - -# def plot_3D_scatterplot(self, data): -# # NOTE: Need to use GlViewWidget, maybe better to have 3D in another tab? -# # Create 3D scatter plot data -# n = 1000 -# x = np.random.normal(size=n) -# y = np.random.normal(size=n) -# z = np.random.normal(size=n) - -# # Create the GLScatterPlotItem -# scatterplot = gl.GLScatterPlotItem(pos=np.vstack([x,y,z]).T, size=8, pxMode=True) -# self.plot_widget.addItem(scatterplot) diff --git a/eis_qgis_plugin/wizard/old/wizard_preprocess.py b/eis_qgis_plugin/wizard/old/wizard_preprocess.py deleted file mode 100644 index cab7c5e..0000000 --- a/eis_qgis_plugin/wizard/old/wizard_preprocess.py +++ /dev/null @@ -1,334 +0,0 @@ -import json -import os -from pathlib import Path -from typing import Dict, List, Tuple - -from qgis.gui import ( - QgsFieldComboBox, - QgsFieldExpressionWidget, - QgsFileWidget, - QgsMapLayerComboBox, -) -from qgis.PyQt import QtGui -from qgis.PyQt.QtWidgets import ( - QDialog, - QGridLayout, - QHBoxLayout, - QLabel, - QLineEdit, - QPushButton, - QScrollArea, - QSizePolicy, - QVBoxLayout, - QWidget, -) - -from eis_qgis_plugin.qgis_plugin_tools.tools.resources import load_ui - -from ..preprocess.create_proxy import EISWizardProxy - -FORM_CLASS: QDialog = load_ui("preprocess/wizard_preprocess_iocg.ui") -# FORM_CLASS: QWizard = load_ui("preprocess/wizard_preprocess_iocg_3.ui") -path = Path(os.path.dirname(__file__)).parent.parent - - -class EISWizardPreprocess(QDialog, FORM_CLASS): - layer_selection: QgsMapLayerComboBox - attribute_selection: QgsFieldComboBox - field_expression: QgsFieldExpressionWidget - - output_file: QgsFileWidget - - def __init__(self, scale, mineral_system) -> None: - super().__init__() - self.setupUi(self) - - # PAGE 1 - self.proxy_widgets: Dict[str, Tuple[str, list, QWidget]] = {} - - self.bold_font = QtGui.QFont() - self.bold_font.setBold(True) - - self.init_proxies(mineral_system, scale) - - # Repaint - self.source_tab.repaint() - self.pathway_tab.repaint() - self.depositional_tab.repaint() - self.mineralisation_tab.repaint() - - # self.open_explore_btn.clicked.connect(self.open_explore) - - # # PAGE 2 - # self.selected_layer: QgsVectorLayer = None - # self.selected_field: QgsField = None - # self.layer_selection.setFilters(QgsMapLayerProxyModel.VectorLayer) - # self.layer_selection.layerChanged.connect(self.set_layer) - # self.attribute_selection.fieldChanged.connect(self.set_field) - - # # Connect buttons - # self.compute_and_plot_btn.clicked.connect(self.compute_and_plot) - # self.select_data_btn.clicked.connect(self.select_data) - # self.create_file_btn.clicked.connect(self.create_file_from_selection) - # self.idw_btn.clicked.connect(lambda _: processing.execAlgorithmDialog("eis:simple_idw", {}) ) - # self.kriging_btn.clicked.connect(lambda _: processing.execAlgorithmDialog("eis:kriging_interpolation", {}) ) - # self.distance_raster_btn.clicked.connect( - # lambda _: processing.execAlgorithmDialog("eis:distance_computation", {}) - # ) - - # # Set plot layout - # self.plot_layout = QVBoxLayout() - # self.plot_widget.setLayout(self.plot_layout) - - def importance_value(self, importance_str): - if importance_str.lower() == "high": - return 1 - elif importance_str.lower() == "moderate": - return 2 - elif importance_str.lower() == "low": - return 3 - elif importance_str == "-": - return 4 - else: - raise Exception(f"Unidentified importance value {importance_str}") - - def init_proxies(self, mineral_system: str, scale: str): - # Read json - with open(os.path.join(path, "resources/proxies.json"), "r") as f: - data = json.loads(f.read()) - proxy_categories = ["source", "pathway", "depositional", "mineralisation"] - - for category in proxy_categories: - grid_layout = QGridLayout() - proxies = data[mineral_system][category] - - # Label row - self.create_row( - grid_layout, 0, "Proxy name", "Importance", ["Keywords"], label=True - ) - - sorted_proxies = dict( - sorted( - proxies.items(), - key=lambda proxy: self.importance_value( - proxy[1]["importance"][scale] - ), - ) - ) - for i, (proxy_name, proxy_details) in enumerate(sorted_proxies.items()): - i = i + 1 # Skip first row - self.create_row( - grid_layout=grid_layout, - row=i, - name=proxy_name, - importance=proxy_details["importance"][scale], - keywords=proxy_details["keywords"], - ) - - # Crete main layout, add search layout and proxy layout - self.main_layout = QVBoxLayout() - - self.search_layout = QHBoxLayout() - self.search_label = QLabel("Search") - self.search_bar = QLineEdit() - self.search_bar.textChanged.connect(self.update_widgets) - self.search_layout.addWidget(self.search_label) - self.search_layout.addWidget(self.search_bar) - self.main_layout.addLayout(self.search_layout) - - scroll_widget = QWidget() - scroll_layout = QVBoxLayout() - scroll_layout.addLayout(grid_layout) - scroll_layout.addStretch() - scroll_widget.setLayout(scroll_layout) - scroll_area = QScrollArea() - scroll_area.setWidgetResizable(True) - scroll_area.setWidget(scroll_widget) - self.main_layout.addWidget(scroll_area) - - # Set the main layout - tab: QWidget = getattr(self, category + "_tab") - tab.setLayout(self.main_layout) - - def create_row( - self, - grid_layout: QGridLayout, - row: int, - name: str, - importance: str, - keywords: List[str], - label=False, - ): - # Name label - name_label = QLabel(name) - name_label.setWordWrap(True) - name_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) - grid_layout.addWidget(name_label, row, 0) - - # Importance label - importance_label = QLabel(importance) - grid_layout.addWidget(importance_label, row, 1) - - # Keywords label - keywords_label = QLabel(", ".join(keywords)) - keywords_label.setWordWrap(True) - grid_layout.addWidget(keywords_label, row, 2) - - if label: - name_label.setFont(self.bold_font) - importance_label.setFont(self.bold_font) - keywords_label.setFont(self.bold_font) - - else: - # Process button - process_button = QPushButton("Process") - process_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) - process_button.clicked.connect(self.open_proxy_creation) - grid_layout.addWidget(process_button, row, 3) - - # Load button - load_button = QPushButton("Load") - load_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) - grid_layout.addWidget(load_button, row, 4) - - self.proxy_widgets[name] = ( - importance, - keywords, - name_label, - importance_label, - keywords_label, - process_button, - load_button, - ) - - def update_widgets(self, text): - for proxy, ( - importance, - keywords, - name_label, - importance_label, - keywords_label, - process_button, - load_button, - ) in self.proxy_widgets.items(): - if ( - text.lower() in proxy.lower() - or text.lower() in importance.lower() - or any(text.lower() in word.lower() for word in keywords) - ): - name_label.show() - importance_label.show() - keywords_label.show() - process_button.show() - load_button.show() - else: - name_label.hide() - importance_label.hide() - keywords_label.hide() - process_button.hide() - load_button.hide() - - def open_proxy_creation(self): - self.proxy_window = EISWizardProxy(self) - self.proxy_window.show() - - # def open_explore(self): - # self.explore_window = EISWizardExplore(self) - # self.explore_window.show() - - # ----- PAGE 2 ----- - - # def set_layer(self, layer): - # self.attribute_selection.setLayer(layer) - # self.selected_layer = layer - # self.set_field(self.attribute_selection.currentField()) - - # def set_field(self, field_name): - # self.selected_field = field_name - # self.field_expression.setField(field_name) - - # def compute_and_plot(self): - # if self.selected_layer is None or self.selected_field is None: - # print("Select a layer and field first!") - # else: - # self.get_statistics() - # self.plot_distribution() - - # def select_data(self): - # if self.field_expression.isValidExpression(): - # self.selected_layer.selectByExpression(self.field_expression.expression(), QgsVectorLayer.SetSelection) - # else: - # print("Expression invalid!") - - # def create_file_from_selection(self): - # print(self.output_file.filePath()) - # self.output_file.set - - # def get_statistics(self): - # # my_result = processing.run("eis:descriptive_statistics", - # # { - # # 'input_layer': '/data/lines.shp', - # # 'output_file': '/data/buffers.shp' - # # } - # # ) - # # output = my_result['OUTPUT'] - # self.max_output.setText("1") - # self.min_output.setText("2") - # self.mean_output.setText("3") - # self.median_output.setText("4") - - # def plot_distribution(self): - # for i in reversed(range(self.plot_layout.count())): - # widget = self.plot_layout.itemAt(i).widget() - # if widget is not None: - # widget.deleteLater() - - # # Create Seaborn plot - # values = [feature.attribute(self.selected_field) for feature in self.selected_layer.getFeatures()] - # values_no_null = [value for value in values if value != NULL] - - # fig, ax = plt.subplots() - # sns.histplot(data=values_no_null, ax=ax) - # canvas = FigureCanvas(fig) - # canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - # toolbar = NavigationToolbar(canvas, self.plot_widget) - - # # # Create Seaborn plot - # # penguins = sns.load_dataset("penguins") - # # fig, ax = plt.subplots() - # # sns.histplot(data=penguins, x="flipper_length_mm", ax=ax) - # # canvas = FigureCanvas(fig) - # # canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - - # self.plot_layout.addWidget(toolbar) - # self.plot_layout.addWidget(canvas) - - # def create_scroll_area(self): - # page = self.geoprocessing_3 - - # h_layout = QtWidgets.QHBoxLayout() - # scroll = QtWidgets.QScrollArea(page) - # scroll.setWidgetResizable(True) # CRITICAL - - # inner = QtWidgets.QFrame(scroll) - # inner.setGeometry(QtCore.QRect(460, 80, 500, 500)) - - # layout = QtWidgets.QVBoxLayout() - - # inner.setLayout(layout) - # scroll.setWidget(inner) # CRITICAL - # h_layout.addWidget(scroll) - - # for i in range(10): - - # # b = QtWidgets.QPushButton(inner) - # # b.setText(str(i)) - - # # b = self.create_group_box(i) - - # b = QtWidgets.QGroupBox(inner) - # b.setTitle(f"AAA {i}") - - # c = QtWidgets.QPushButton(b) - # c.setText(str(i)) - # inner.layout().addWidget(b)