Example #1
0
    def __init__(self, config_file, storage_client, parent):
        QMainWindow.__init__(self, parent)

        if storage_client:
            self._api = storage_client
        else:
            self._api = PlotApi(ERT.enkf_facade)

        self.setMinimumWidth(850)
        self.setMinimumHeight(650)

        self.setWindowTitle("Plotting - {}".format(config_file))
        self.activateWindow()
        self._key_definitions = self._api.all_data_type_keys()
        self._plot_customizer = PlotCustomizer(self, self._key_definitions)

        self._plot_customizer.settingsChanged.connect(self.keySelected)

        self._central_tab = QTabWidget()

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self._central_tab)

        self.setCentralWidget(central_widget)

        self._plot_widgets = []
        """:type: list of PlotWidget"""

        self.addPlotWidget(ENSEMBLE, EnsemblePlot())
        self.addPlotWidget(STATISTICS, StatisticsPlot())
        self.addPlotWidget(HISTOGRAM, HistogramPlot())
        self.addPlotWidget(GAUSSIAN_KDE, GaussianKDEPlot())
        self.addPlotWidget(DISTRIBUTION, DistributionPlot())
        self.addPlotWidget(CROSS_CASE_STATISTICS, CrossCaseStatisticsPlot())

        self._central_tab.currentChanged.connect(self.currentPlotChanged)

        cases = self._api.get_all_cases_not_running()
        case_names = [case["name"] for case in cases if not case["hidden"]]

        self._data_type_keys_widget = DataTypeKeysWidget(self._key_definitions)
        self._data_type_keys_widget.dataTypeKeySelected.connect(
            self.keySelected)
        self.addDock("Data types", self._data_type_keys_widget)
        self._case_selection_widget = CaseSelectionWidget(case_names)
        self._case_selection_widget.caseSelectionChanged.connect(
            self.keySelected)
        self.addDock("Plot case", self._case_selection_widget)

        current_plot_widget = self._plot_widgets[
            self._central_tab.currentIndex()]
        self._data_type_keys_widget.selectDefault()
        self._updateCustomizer(current_plot_widget)
Example #2
0
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__central_tab = QTabWidget()
        self.setCentralWidget(self.__central_tab)


        self.__plot_panels = []
        """:type: list of PlotPanel"""

        self.__selected_plot_for_type = {}

        self.addPlotPanel("Ensemble plot", "gui/plots/simple_plot.html", short_name="Plot")
        self.addPlotPanel("Ensemble overview plot", "gui/plots/simple_overview_plot.html", short_name="oPlot")
        self.addPlotPanel("Histogram", "gui/plots/histogram.html", short_name="Histogram")
        self.addPlotPanel("Distribution", "gui/plots/gen_kw.html", short_name="Distribution")
        self.addPlotPanel("RFT plot", "gui/plots/rft.html", short_name="RFT")
        self.addPlotPanel("RFT overview plot", "gui/plots/rft_overview.html", short_name="oRFT")

        self.__data_type_keys_widget = DataTypeKeysWidget()
        self.__data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(self.caseSelectionChanged)
        plot_case_dock = self.addDock("Plot case", self.__case_selection_widget)

        self.__plot_metrics_widget = PlotMetricsWidget()
        self.__plot_metrics_widget.plotSettingsChanged.connect(self.plotSettingsChanged)
        plot_metrics_dock = self.addDock("Plot metrics", self.__plot_metrics_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(self.plotSettingsChanged)
        customize_plot_dock = self.addDock("Customize", self.__customize_plot_widget)

        self.__export_plot_widget = ExportPlotWidget()
        self.__export_plot_widget.exportButtonPressed.connect(self.exportActivePlot)
        export_dock = self.addDock("Export Plot", self.__export_plot_widget)

        self.__exporter = None


        self.tabifyDockWidget(plot_case_dock, plot_metrics_dock)
        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)
        self.tabifyDockWidget(plot_case_dock, export_dock)
        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()
Example #3
0
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__central_tab = QTabWidget()
        self.setCentralWidget(self.__central_tab)


        self.__plot_panels = []

        self.addPlotPanel("Ensemble plot", "gui/plots/simple_plot.html", short_name="Plot")
        self.addPlotPanel("Ensemble overview plot", "gui/plots/simple_overview_plot.html", short_name="oPlot")
        self.addPlotPanel("Histogram", "gui/plots/histogram.html", short_name="Histogram")
        self.addPlotPanel("RFT plot", "gui/plots/rft.html", short_name="RFT")
        self.addPlotPanel("RFT overview plot", "gui/plots/rft_overview.html", short_name="oRFT")

        self.__data_type_keys_widget = DataTypeKeysWidget()
        self.__data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(self.caseSelectionChanged)
        self.addDock("Plot case", self.__case_selection_widget)

        self.__plot_metrics_widget = PlotMetricsWidget()
        self.__plot_metrics_widget.plotScalesChanged.connect(self.scalesChanged)
        self.__plot_metrics_widget.reportStepTimeChanged.connect(self.reportStepTimeChanged)
        self.addDock("Plot metrics", self.__plot_metrics_widget)

        self.__data_type_key = None
        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()
        self.__value_scale_tracker = ScaleTracker("Value")
        self.__time_scale_tracker = ScaleTracker("Time")
        self.__depth_scale_tracker = ScaleTracker("Depth")
Example #4
0
class PlotWindow(QMainWindow):
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__plot_data = None

        self.__plot_metrics_tracker = PlotMetricsTracker()
        self.__plot_metrics_tracker.addScaleType("value", float)
        self.__plot_metrics_tracker.addScaleType("depth", float)
        self.__plot_metrics_tracker.addScaleType("pca", float)
        self.__plot_metrics_tracker.addScaleType("index", int)
        self.__plot_metrics_tracker.addScaleType("count", int)
        self.__plot_metrics_tracker.addScaleType("time", CTime)

        self.__central_tab = QTabWidget()
        self.__central_tab.currentChanged.connect(self.currentPlotChanged)

        self.__plot_panel_tracker = PlotPanelTracker(self.__central_tab)
        self.__plot_panel_tracker.addKeyTypeTester("summary", PlotDataFetcher.isSummaryKey)
        self.__plot_panel_tracker.addKeyTypeTester("block", PlotDataFetcher.isBlockObservationKey)
        self.__plot_panel_tracker.addKeyTypeTester("gen_kw", PlotDataFetcher.isGenKWKey)
        self.__plot_panel_tracker.addKeyTypeTester("gen_data", PlotDataFetcher.isGenDataKey)
        self.__plot_panel_tracker.addKeyTypeTester("custom_pca", PlotDataFetcher.isCustomPcaDataKey)


        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        self.__toolbar = PlotToolBar()
        self.__toolbar.resetScalesClicked.connect(self.resetCurrentScales)

        central_layout.addWidget(self.__toolbar)
        central_layout.addWidget(self.__central_tab)

        self.setCentralWidget(central_widget)


        self.__plot_panels = []
        """:type: list of PlotPanel"""

        self.addPlotPanel("Ensemble plot", "gui/plots/simple_plot.html", short_name="EP")
        self.addPlotPanel("Ensemble overview plot", "gui/plots/simple_overview_plot.html", short_name="EOP")
        self.addPlotPanel("Ensemble statistics", "gui/plots/ensemble_statistics_plot.html", short_name="ES")
        self.addPlotPanel("Histogram", "gui/plots/histogram.html", short_name="Histogram")
        self.addPlotPanel("Distribution", "gui/plots/gen_kw.html", short_name="Distribution")
        self.addPlotPanel("RFT plot", "gui/plots/rft.html", short_name="RFT")
        self.addPlotPanel("RFT overview plot", "gui/plots/rft_overview.html", short_name="oRFT")
        self.addPlotPanel("Ensemble plot", "gui/plots/gen_data.html", short_name="epGenData")
        self.addPlotPanel("Ensemble overview plot", "gui/plots/gen_data_overview.html", short_name="eopGenData")
        self.addPlotPanel("Ensemble statistics", "gui/plots/gen_data_statistics_plot.html", short_name="esGenData")
        self.addPlotPanel("PCA plot", "gui/plots/pca.html", short_name="PCA")

        self.__data_type_keys_widget = DataTypeKeysWidget()
        self.__data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(self.caseSelectionChanged)
        plot_case_dock = self.addDock("Plot case", self.__case_selection_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(self.plotSettingsChanged)
        customize_plot_dock = self.addDock("Customize", self.__customize_plot_widget)

        self.__toolbar.exportClicked.connect(self.exportActivePlot)
        self.__toolbar.plotScalesChanged.connect(self.plotSettingsChanged)
        self.__toolbar.reportStepChanged.connect(self.plotSettingsChanged)

        self.__exporter = None
        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)

        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()


    def fetchDefaultXScales(self):
        if self.__plot_data is not None:
            active_plot = self.getActivePlot()
            x_axis_type_name = active_plot.xAxisType()

            x_axis_type = self.__plot_metrics_tracker.getType(x_axis_type_name)

            if x_axis_type is not None:
                x_min, x_max = active_plot.getXScales(self.__plot_data)

                if x_axis_type is CTime and x_min is not None and x_max is not None:
                    x_min = int(x_min)
                    x_max = int(x_max)

                self.__plot_metrics_tracker.setScalesForType(x_axis_type_name, x_min, x_max)



    def fetchDefaultYScales(self):
            if self.__plot_data is not None:
                active_plot = self.getActivePlot()
                y_axis_type_name = active_plot.yAxisType()

                y_axis_type = self.__plot_metrics_tracker.getType(y_axis_type_name)

                if y_axis_type is not None:
                    y_min, y_max = active_plot.getYScales(self.__plot_data)

                    if y_axis_type is CTime and y_min is not None and y_max is not None:
                        y_min = int(y_min)
                        y_max = int(y_max)

                    self.__plot_metrics_tracker.setScalesForType(y_axis_type_name, y_min, y_max)


    def resetCurrentScales(self):
        active_plot = self.getActivePlot()
        x_axis_type_name = active_plot.xAxisType()
        y_axis_type_name = active_plot.yAxisType()

        self.__plot_metrics_tracker.resetScaleType(x_axis_type_name)
        self.__plot_metrics_tracker.resetScaleType(y_axis_type_name)

        self.currentPlotChanged()
        self.plotSettingsChanged()


    def getActivePlot(self):
        """ @rtype: PlotPanel """
        if not self.__central_tab.currentIndex() > -1:
            raise AssertionError("No plot selected!")

        active_plot =  self.__central_tab.currentWidget()
        assert isinstance(active_plot, PlotPanel)

        return active_plot


    def currentPlotChanged(self):
        active_plot = self.getActivePlot()

        if active_plot.isReady():
            x_axis_type_name = active_plot.xAxisType()
            x_axis_type = self.__plot_metrics_tracker.getType(x_axis_type_name)

            y_axis_type_name = active_plot.yAxisType()
            y_axis_type = self.__plot_metrics_tracker.getType(y_axis_type_name)

            if not self.__plot_metrics_tracker.hasScale(x_axis_type_name):
                self.fetchDefaultXScales()

            if not self.__plot_metrics_tracker.hasScale(y_axis_type_name):
                self.fetchDefaultYScales()

            x_min, x_max = self.__plot_metrics_tracker.getScalesForType(x_axis_type_name)
            y_min, y_max = self.__plot_metrics_tracker.getScalesForType(y_axis_type_name)

            self.__toolbar.setToolBarOptions(x_axis_type, y_axis_type, active_plot.isReportStepCapable() and self.__plot_metrics_tracker.dataTypeSupportsReportStep())
            self.__toolbar.setScales(x_min, x_max, y_min, y_max)


    def plotSettingsChanged(self):
        x_min, x_max = self.__toolbar.getXScales()
        y_min, y_max = self.__toolbar.getYScales()

        active_plot = self.getActivePlot()

        x_axis_type_name = active_plot.xAxisType()
        y_axis_type_name = active_plot.yAxisType()

        self.__plot_metrics_tracker.setScalesForType(x_axis_type_name, x_min, x_max)
        self.__plot_metrics_tracker.setScalesForType(y_axis_type_name, y_min, y_max)

        self.updatePlots()


    def updatePlots(self):
        report_step = self.__toolbar.getReportStep()

        for plot_panel in self.__plot_panels:
            if plot_panel.isPlotVisible():
                model = plot_panel.getPlotBridge()
                model.setPlotData(self.__plot_data)
                model.setCustomSettings(self.__customize_plot_widget.getCustomSettings())
                model.setReportStepTime(report_step)

                x_axis_type_name = plot_panel.xAxisType()
                y_axis_type_name = plot_panel.yAxisType()

                x_min, x_max = self.__plot_metrics_tracker.getScalesForType(x_axis_type_name)
                y_min, y_max = self.__plot_metrics_tracker.getScalesForType(y_axis_type_name)

                model.setScales(x_min, x_max, y_min, y_max)

                plot_panel.renderNow()


    def exportActivePlot(self):
        active_plot = self.getActivePlot()

        if self.__exporter is None:
            path = None
        else:
            path = self.__exporter.getCurrentPath()


        report_step = self.__toolbar.getReportStep()

        x_axis_type_name = active_plot.xAxisType()
        y_axis_type_name = active_plot.yAxisType()

        x_min, x_max = self.__plot_metrics_tracker.getScalesForType(x_axis_type_name)
        y_min, y_max = self.__plot_metrics_tracker.getScalesForType(y_axis_type_name)

        settings = {"x_min": x_min,
                    "x_max": x_max,
                    "y_min": y_min,
                    "y_max": y_max,
                    "report_step": report_step}

        self.__exporter = ExportPlot(active_plot, settings, self.__customize_plot_widget.getCustomSettings(), path)

        self.__exporter.export()


    def addPlotPanel(self, name, path, short_name=None):
        if short_name is None:
            short_name = name

        plot_panel = PlotPanel(name, short_name, path)
        plot_panel.plotReady.connect(self.plotReady)
        self.__plot_panels.append(plot_panel)
        self.__central_tab.addTab(plot_panel, name)


    def addDock(self, name, widget, area=Qt.LeftDockWidgetArea, allowed_areas=Qt.AllDockWidgetAreas):
        dock_widget = QDockWidget(name)
        dock_widget.setObjectName("%sDock" % name)
        dock_widget.setWidget(widget)
        dock_widget.setAllowedAreas(allowed_areas)
        dock_widget.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable)

        self.addDockWidget(area, dock_widget)
        return dock_widget


    def checkPlotStatus(self):
        for plot_panel in self.__plot_panels:
            if not plot_panel.isReady():
                return False

        if len(self.__plot_cases) == 0:
            return False

        return True

    def plotReady(self):
        if self.checkPlotStatus():
            self.__data_type_keys_widget.selectDefault()
            self.currentPlotChanged()
            self.__customize_plot_widget.emitChange()


    def caseSelectionChanged(self):
        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()
        self.keySelected(self.__plot_metrics_tracker.getDataTypeKey())


    def showOrHidePlotTab(self, plot_panel, is_visible, show_plot):
        plot_panel.setPlotIsVisible(show_plot)
        if show_plot and not is_visible:
            index = self.__plot_panels.index(plot_panel)
            self.__central_tab.insertTab(index, plot_panel, plot_panel.getName())
        elif not show_plot and is_visible:
            index = self.__central_tab.indexOf(plot_panel)
            self.__central_tab.removeTab(index)


    @may_take_a_long_time
    def keySelected(self, key):
        key = str(key)
        old_data_type_key = self.__plot_metrics_tracker.getDataTypeKey()
        self.__plot_metrics_tracker.setDataTypeKey(key)

        plot_data_fetcher = PlotDataFetcher()
        self.__plot_data = plot_data_fetcher.getPlotDataForKeyAndCases(key, self.__plot_cases)
        self.__plot_data.setParent(self)

        self.__central_tab.blockSignals(True)

        self.__plot_panel_tracker.storePlotType(plot_data_fetcher, old_data_type_key)

        for plot_panel in self.__plot_panels:
            self.showOrHidePlotTab(plot_panel, False, True)

        self.__plot_metrics_tracker.setDataTypeKeySupportsReportSteps(plot_data_fetcher.dataTypeKeySupportsReportSteps(key))
        show_pca = plot_data_fetcher.isPcaDataKey(key)
        for plot_panel in self.__plot_panels:
            visible = self.__central_tab.indexOf(plot_panel) > -1

            if plot_data_fetcher.isSummaryKey(key):
                show_plot = plot_panel.supportsPlotProperties(time=True, value=True, histogram=True, pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isBlockObservationKey(key):
                show_plot = plot_panel.supportsPlotProperties(depth=True, value=True, pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isGenKWKey(key):
                show_plot = plot_panel.supportsPlotProperties(value=True, histogram=True, pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isGenDataKey(key):
                show_plot = plot_panel.supportsPlotProperties(index=True, pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isPcaDataKey(key):
                show_plot = plot_panel.supportsPlotProperties(pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            else:
                raise NotImplementedError("Key %s not supported." % key)

        self.__plot_panel_tracker.restorePlotType(plot_data_fetcher, key)

        self.__central_tab.blockSignals(False)
        self.currentPlotChanged()

        if self.checkPlotStatus():
            self.plotSettingsChanged()
Example #5
0
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__plot_data = None

        self.__plot_metrics_tracker = PlotMetricsTracker()
        self.__plot_metrics_tracker.addScaleType("value", float)
        self.__plot_metrics_tracker.addScaleType("depth", float)
        self.__plot_metrics_tracker.addScaleType("pca", float)
        self.__plot_metrics_tracker.addScaleType("index", int)
        self.__plot_metrics_tracker.addScaleType("count", int)
        self.__plot_metrics_tracker.addScaleType("time", CTime)

        self.__central_tab = QTabWidget()
        self.__central_tab.currentChanged.connect(self.currentPlotChanged)

        self.__plot_panel_tracker = PlotPanelTracker(self.__central_tab)
        self.__plot_panel_tracker.addKeyTypeTester("summary", PlotDataFetcher.isSummaryKey)
        self.__plot_panel_tracker.addKeyTypeTester("block", PlotDataFetcher.isBlockObservationKey)
        self.__plot_panel_tracker.addKeyTypeTester("gen_kw", PlotDataFetcher.isGenKWKey)
        self.__plot_panel_tracker.addKeyTypeTester("gen_data", PlotDataFetcher.isGenDataKey)
        self.__plot_panel_tracker.addKeyTypeTester("custom_pca", PlotDataFetcher.isCustomPcaDataKey)


        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        self.__toolbar = PlotToolBar()
        self.__toolbar.resetScalesClicked.connect(self.resetCurrentScales)

        central_layout.addWidget(self.__toolbar)
        central_layout.addWidget(self.__central_tab)

        self.setCentralWidget(central_widget)


        self.__plot_panels = []
        """:type: list of PlotPanel"""

        self.addPlotPanel("Ensemble plot", "gui/plots/simple_plot.html", short_name="EP")
        self.addPlotPanel("Ensemble overview plot", "gui/plots/simple_overview_plot.html", short_name="EOP")
        self.addPlotPanel("Ensemble statistics", "gui/plots/ensemble_statistics_plot.html", short_name="ES")
        self.addPlotPanel("Histogram", "gui/plots/histogram.html", short_name="Histogram")
        self.addPlotPanel("Distribution", "gui/plots/gen_kw.html", short_name="Distribution")
        self.addPlotPanel("RFT plot", "gui/plots/rft.html", short_name="RFT")
        self.addPlotPanel("RFT overview plot", "gui/plots/rft_overview.html", short_name="oRFT")
        self.addPlotPanel("Ensemble plot", "gui/plots/gen_data.html", short_name="epGenData")
        self.addPlotPanel("Ensemble overview plot", "gui/plots/gen_data_overview.html", short_name="eopGenData")
        self.addPlotPanel("Ensemble statistics", "gui/plots/gen_data_statistics_plot.html", short_name="esGenData")
        self.addPlotPanel("PCA plot", "gui/plots/pca.html", short_name="PCA")

        self.__data_type_keys_widget = DataTypeKeysWidget()
        self.__data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(self.caseSelectionChanged)
        plot_case_dock = self.addDock("Plot case", self.__case_selection_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(self.plotSettingsChanged)
        customize_plot_dock = self.addDock("Customize", self.__customize_plot_widget)

        self.__toolbar.exportClicked.connect(self.exportActivePlot)
        self.__toolbar.plotScalesChanged.connect(self.plotSettingsChanged)
        self.__toolbar.reportStepChanged.connect(self.plotSettingsChanged)

        self.__exporter = None
        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)

        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()
Example #6
0
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self._ert = ERT.ert
        """:type: res.enkf.enkf_main.EnKFMain"""

        key_manager = self._ert.getKeyManager()
        """:type: res.enkf.key_manager.KeyManager """

        self.setMinimumWidth(850)
        self.setMinimumHeight(650)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self._plot_customizer = PlotCustomizer(self)

        def plotConfigCreator(key):
            return PlotConfigFactory.createPlotConfigForKey(self._ert, key)

        self._plot_customizer.setPlotConfigCreator(plotConfigCreator)
        self._plot_customizer.settingsChanged.connect(self.keySelected)

        self._central_tab = QTabWidget()
        self._central_tab.currentChanged.connect(self.currentPlotChanged)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self._central_tab)

        self.setCentralWidget(central_widget)

        self._plot_widgets = []
        """:type: list of PlotWidget"""

        self._data_gatherers = []
        """:type: list of PlotDataGatherer """

        summary_gatherer = self.createDataGatherer(
            PDG.gatherSummaryData,
            key_manager.isSummaryKey,
            refcaseGatherFunc=PDG.gatherSummaryRefcaseData,
            observationGatherFunc=PDG.gatherSummaryObservationData,
            historyGatherFunc=PDG.gatherSummaryHistoryData)
        gen_data_gatherer = self.createDataGatherer(
            PDG.gatherGenDataData,
            key_manager.isGenDataKey,
            observationGatherFunc=PDG.gatherGenDataObservationData)
        gen_kw_gatherer = self.createDataGatherer(PDG.gatherGenKwData,
                                                  key_manager.isGenKwKey)
        custom_kw_gatherer = self.createDataGatherer(PDG.gatherCustomKwData,
                                                     key_manager.isCustomKwKey)

        self.addPlotWidget(ENSEMBLE, plots.plotEnsemble,
                           [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget(STATISTICS, plots.plotStatistics,
                           [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget(HISTOGRAM, plots.plotHistogram,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(GAUSSIAN_KDE, plots.plotGaussianKDE,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(DISTRIBUTION, plots.plotDistribution,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(CROSS_CASE_STATISTICS,
                           plots.plotCrossCaseStatistics,
                           [gen_kw_gatherer, custom_kw_gatherer])

        data_types_key_model = DataTypeKeysListModel(self._ert)

        self._data_type_keys_widget = DataTypeKeysWidget(data_types_key_model)
        self._data_type_keys_widget.dataTypeKeySelected.connect(
            self.keySelected)
        self.addDock("Data types", self._data_type_keys_widget)

        current_case = getCurrentCaseName()
        self._case_selection_widget = CaseSelectionWidget(current_case)
        self._case_selection_widget.caseSelectionChanged.connect(
            self.keySelected)
        self.addDock("Plot case", self._case_selection_widget)

        current_plot_widget = self._plot_widgets[
            self._central_tab.currentIndex()]
        current_plot_widget.setActive()
        self._data_type_keys_widget.selectDefault()
        self._updateCustomizer(current_plot_widget)
Example #7
0
class PlotWindow(QMainWindow):
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self._ert = ERT.ert
        """:type: res.enkf.enkf_main.EnKFMain"""

        key_manager = self._ert.getKeyManager()
        """:type: res.enkf.key_manager.KeyManager """

        self.setMinimumWidth(850)
        self.setMinimumHeight(650)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self._plot_customizer = PlotCustomizer(self)

        def plotConfigCreator(key):
            return PlotConfigFactory.createPlotConfigForKey(self._ert, key)

        self._plot_customizer.setPlotConfigCreator(plotConfigCreator)
        self._plot_customizer.settingsChanged.connect(self.keySelected)

        self._central_tab = QTabWidget()
        self._central_tab.currentChanged.connect(self.currentPlotChanged)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self._central_tab)

        self.setCentralWidget(central_widget)

        self._plot_widgets = []
        """:type: list of PlotWidget"""

        self._data_gatherers = []
        """:type: list of PlotDataGatherer """

        summary_gatherer = self.createDataGatherer(
            PDG.gatherSummaryData,
            key_manager.isSummaryKey,
            refcaseGatherFunc=PDG.gatherSummaryRefcaseData,
            observationGatherFunc=PDG.gatherSummaryObservationData,
            historyGatherFunc=PDG.gatherSummaryHistoryData)
        gen_data_gatherer = self.createDataGatherer(
            PDG.gatherGenDataData,
            key_manager.isGenDataKey,
            observationGatherFunc=PDG.gatherGenDataObservationData)
        gen_kw_gatherer = self.createDataGatherer(PDG.gatherGenKwData,
                                                  key_manager.isGenKwKey)
        custom_kw_gatherer = self.createDataGatherer(PDG.gatherCustomKwData,
                                                     key_manager.isCustomKwKey)

        self.addPlotWidget(ENSEMBLE, plots.plotEnsemble,
                           [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget(STATISTICS, plots.plotStatistics,
                           [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget(HISTOGRAM, plots.plotHistogram,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(GAUSSIAN_KDE, plots.plotGaussianKDE,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(DISTRIBUTION, plots.plotDistribution,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(CROSS_CASE_STATISTICS,
                           plots.plotCrossCaseStatistics,
                           [gen_kw_gatherer, custom_kw_gatherer])

        data_types_key_model = DataTypeKeysListModel(self._ert)

        self._data_type_keys_widget = DataTypeKeysWidget(data_types_key_model)
        self._data_type_keys_widget.dataTypeKeySelected.connect(
            self.keySelected)
        self.addDock("Data types", self._data_type_keys_widget)

        current_case = getCurrentCaseName()
        self._case_selection_widget = CaseSelectionWidget(current_case)
        self._case_selection_widget.caseSelectionChanged.connect(
            self.keySelected)
        self.addDock("Plot case", self._case_selection_widget)

        current_plot_widget = self._plot_widgets[
            self._central_tab.currentIndex()]
        current_plot_widget.setActive()
        self._data_type_keys_widget.selectDefault()
        self._updateCustomizer(current_plot_widget)

    def createDataGatherer(self,
                           dataGatherFunc,
                           gatherConditionFunc,
                           refcaseGatherFunc=None,
                           observationGatherFunc=None,
                           historyGatherFunc=None):
        data_gatherer = PDG(dataGatherFunc,
                            gatherConditionFunc,
                            refcaseGatherFunc=refcaseGatherFunc,
                            observationGatherFunc=observationGatherFunc,
                            historyGatherFunc=historyGatherFunc)
        self._data_gatherers.append(data_gatherer)
        return data_gatherer

    def currentPlotChanged(self):
        for plot_widget in self._plot_widgets:
            plot_widget.setActive(False)
            index = self._central_tab.indexOf(plot_widget)

            if index == self._central_tab.currentIndex(
            ) and plot_widget.canPlotKey(self.getSelectedKey()):
                plot_widget.setActive()
                self._updateCustomizer(plot_widget)
                plot_widget.updatePlot()

    def _updateCustomizer(self, plot_widget):
        """ @type plot_widget: PlotWidget """
        key = self.getSelectedKey()
        key_manager = self._ert.getKeyManager()

        index_type = PlotContext.UNKNOWN_AXIS

        if key_manager.isGenDataKey(key):
            index_type = PlotContext.INDEX_AXIS
        elif key_manager.isSummaryKey(key):
            index_type = PlotContext.DATE_AXIS

        x_axis_type = PlotContext.UNKNOWN_AXIS
        y_axis_type = PlotContext.UNKNOWN_AXIS

        if plot_widget.name == ENSEMBLE:
            x_axis_type = index_type
            y_axis_type = PlotContext.VALUE_AXIS
        elif plot_widget.name == STATISTICS:
            x_axis_type = index_type
            y_axis_type = PlotContext.VALUE_AXIS
        elif plot_widget.name == DISTRIBUTION:
            y_axis_type = PlotContext.VALUE_AXIS
        elif plot_widget.name == CROSS_CASE_STATISTICS:
            y_axis_type = PlotContext.VALUE_AXIS
        elif plot_widget.name == HISTOGRAM:
            x_axis_type = PlotContext.VALUE_AXIS
            y_axis_type = PlotContext.COUNT_AXIS
        elif plot_widget.name == GAUSSIAN_KDE:
            x_axis_type = PlotContext.VALUE_AXIS
            y_axis_type = PlotContext.DENSITY_AXIS

        self._plot_customizer.setAxisTypes(x_axis_type, y_axis_type)

    def createPlotContext(self, figure):
        key = self.getSelectedKey()
        cases = self._case_selection_widget.getPlotCaseNames()
        data_gatherer = self.getDataGathererForKey(key)
        plot_config = PlotConfig.createCopy(
            self._plot_customizer.getPlotConfig())
        plot_config.setTitle(key)
        return PlotContext(self._ert, figure, plot_config, cases, key,
                           data_gatherer)

    def getDataGathererForKey(self, key):
        """ @rtype: PlotDataGatherer """
        return next((data_gatherer for data_gatherer in self._data_gatherers
                     if data_gatherer.canGatherDataForKey(key)), None)

    def getSelectedKey(self):
        return str(self._data_type_keys_widget.getSelectedItem())

    def addPlotWidget(self, name, plotFunction, data_gatherers, enabled=True):
        plot_condition_function_list = [
            data_gatherer.canGatherDataForKey
            for data_gatherer in data_gatherers
        ]
        plot_widget = PlotWidget(name, plotFunction,
                                 plot_condition_function_list,
                                 self.createPlotContext)
        plot_widget.customizationTriggered.connect(self.toggleCustomizeDialog)

        index = self._central_tab.addTab(plot_widget, name)
        self._plot_widgets.append(plot_widget)
        self._central_tab.setTabEnabled(index, enabled)

    def addDock(self,
                name,
                widget,
                area=Qt.LeftDockWidgetArea,
                allowed_areas=Qt.AllDockWidgetAreas):
        dock_widget = QDockWidget(name)
        dock_widget.setObjectName("%sDock" % name)
        dock_widget.setWidget(widget)
        dock_widget.setAllowedAreas(allowed_areas)
        dock_widget.setFeatures(QDockWidget.DockWidgetFloatable
                                | QDockWidget.DockWidgetMovable)

        self.addDockWidget(area, dock_widget)
        return dock_widget

    @showWaitCursorWhileWaiting
    def keySelected(self):
        key = self.getSelectedKey()
        self._plot_customizer.switchPlotConfigHistory(key)

        for plot_widget in self._plot_widgets:
            plot_widget.setDirty()
            index = self._central_tab.indexOf(plot_widget)
            self._central_tab.setTabEnabled(index, plot_widget.canPlotKey(key))

        for plot_widget in self._plot_widgets:
            if plot_widget.canPlotKey(key):
                plot_widget.updatePlot()

    def toggleCustomizeDialog(self):
        self._plot_customizer.toggleCustomizationDialog()
Example #8
0
class PlotWindow(QMainWindow):


    def __init__(self, config_file, parent):
        QMainWindow.__init__(self, parent)

        self._api = PlotApi(ERT.enkf_facade)

        self.setMinimumWidth(850)
        self.setMinimumHeight(650)

        self.setWindowTitle("Plotting - {}".format(config_file))
        self.activateWindow()
        self._key_definitions = self._api.all_data_type_keys()
        self._plot_customizer = PlotCustomizer(self, self._key_definitions)

        self._plot_customizer.settingsChanged.connect(self.keySelected)

        self._central_tab = QTabWidget()

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self._central_tab)

        self.setCentralWidget(central_widget)

        self._plot_widgets = []
        """:type: list of PlotWidget"""

        self.addPlotWidget(ENSEMBLE, EnsemblePlot())
        self.addPlotWidget(STATISTICS, StatisticsPlot())
        self.addPlotWidget(HISTOGRAM, HistogramPlot())
        self.addPlotWidget(GAUSSIAN_KDE, GaussianKDEPlot())
        self.addPlotWidget(DISTRIBUTION, DistributionPlot())
        self.addPlotWidget(CROSS_CASE_STATISTICS, CrossCaseStatisticsPlot())

        self._central_tab.currentChanged.connect(self.currentPlotChanged)


        cases = self._api.get_all_cases_not_running()
        case_names = [case["name"] for case in cases if not case["hidden"]]


        self._data_type_keys_widget = DataTypeKeysWidget(self._key_definitions)
        self._data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self._data_type_keys_widget)
        self._case_selection_widget = CaseSelectionWidget(case_names)
        self._case_selection_widget.caseSelectionChanged.connect(self.keySelected)
        self.addDock("Plot case", self._case_selection_widget)

        current_plot_widget = self._plot_widgets[self._central_tab.currentIndex()]
        self._data_type_keys_widget.selectDefault()
        self._updateCustomizer(current_plot_widget)


    def currentPlotChanged(self):
        key_def = self.getSelectedKey()
        key = key_def["key"]

        for plot_widget in self._plot_widgets:
            index = self._central_tab.indexOf(plot_widget)

            if index == self._central_tab.currentIndex() \
                    and plot_widget._plotter.dimensionality == key_def["dimensionality"]:
                self._updateCustomizer(plot_widget)
                cases = self._case_selection_widget.getPlotCaseNames()
                case_to_data_map = {case: self._api.data_for_key(case, key)[key] for case in cases}
                if len(key_def["observations"]) > 0:
                    observations = self._api.observations_for_obs_keys(cases[0], key_def["observations"])
                else:
                    observations = None

                plot_config = PlotConfig.createCopy(self._plot_customizer.getPlotConfig())
                plot_config.setTitle(key)
                plot_context = PlotContext(plot_config, cases, key)

                if key_def["has_refcase"]:
                    plot_context.refcase_data = self._api.refcase_data(key)

                plot_widget.updatePlot(plot_context, case_to_data_map, observations)
Example #9
0
class PlotWindow(QMainWindow):
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__plot_data = None

        self.__plot_metrics_tracker = PlotMetricsTracker()
        self.__plot_metrics_tracker.addScaleType("value", float)
        self.__plot_metrics_tracker.addScaleType("depth", float)
        self.__plot_metrics_tracker.addScaleType("pca", float)
        self.__plot_metrics_tracker.addScaleType("index", int)
        self.__plot_metrics_tracker.addScaleType("count", int)
        self.__plot_metrics_tracker.addScaleType("time", CTime)

        self.__central_tab = QTabWidget()
        self.__central_tab.currentChanged.connect(self.currentPlotChanged)

        self.__plot_panel_tracker = PlotPanelTracker(self.__central_tab)
        self.__plot_panel_tracker.addKeyTypeTester(
            "summary", PlotDataFetcher.isSummaryKey)
        self.__plot_panel_tracker.addKeyTypeTester(
            "block", PlotDataFetcher.isBlockObservationKey)
        self.__plot_panel_tracker.addKeyTypeTester("gen_kw",
                                                   PlotDataFetcher.isGenKWKey)
        self.__plot_panel_tracker.addKeyTypeTester(
            "gen_data", PlotDataFetcher.isGenDataKey)
        self.__plot_panel_tracker.addKeyTypeTester(
            "custom_pca", PlotDataFetcher.isCustomPcaDataKey)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        self.__toolbar = PlotToolBar()
        self.__toolbar.resetScalesClicked.connect(self.resetCurrentScales)

        central_layout.addWidget(self.__toolbar)
        central_layout.addWidget(self.__central_tab)

        self.setCentralWidget(central_widget)

        self.__plot_panels = []
        """:type: list of PlotPanel"""

        self.addPlotPanel("Ensemble plot",
                          "gui/plots/simple_plot.html",
                          short_name="EP")
        self.addPlotPanel("Ensemble overview plot",
                          "gui/plots/simple_overview_plot.html",
                          short_name="EOP")
        self.addPlotPanel("Ensemble statistics",
                          "gui/plots/ensemble_statistics_plot.html",
                          short_name="ES")
        self.addPlotPanel("Histogram",
                          "gui/plots/histogram.html",
                          short_name="Histogram")
        self.addPlotPanel("Distribution",
                          "gui/plots/gen_kw.html",
                          short_name="Distribution")
        self.addPlotPanel("RFT plot", "gui/plots/rft.html", short_name="RFT")
        self.addPlotPanel("RFT overview plot",
                          "gui/plots/rft_overview.html",
                          short_name="oRFT")
        self.addPlotPanel("Ensemble plot",
                          "gui/plots/gen_data.html",
                          short_name="epGenData")
        self.addPlotPanel("Ensemble overview plot",
                          "gui/plots/gen_data_overview.html",
                          short_name="eopGenData")
        self.addPlotPanel("Ensemble statistics",
                          "gui/plots/gen_data_statistics_plot.html",
                          short_name="esGenData")
        self.addPlotPanel("PCA plot", "gui/plots/pca.html", short_name="PCA")

        self.__data_type_keys_widget = DataTypeKeysWidget()
        self.__data_type_keys_widget.dataTypeKeySelected.connect(
            self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(
            self.caseSelectionChanged)
        plot_case_dock = self.addDock("Plot case",
                                      self.__case_selection_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(
            self.plotSettingsChanged)
        customize_plot_dock = self.addDock("Customize",
                                           self.__customize_plot_widget)

        self.__toolbar.exportClicked.connect(self.exportActivePlot)
        self.__toolbar.plotScalesChanged.connect(self.plotSettingsChanged)
        self.__toolbar.reportStepChanged.connect(self.plotSettingsChanged)

        self.__exporter = None
        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)

        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()

    def fetchDefaultXScales(self):
        if self.__plot_data is not None:
            active_plot = self.getActivePlot()
            x_axis_type_name = active_plot.xAxisType()

            x_axis_type = self.__plot_metrics_tracker.getType(x_axis_type_name)

            if x_axis_type is not None:
                x_min, x_max = active_plot.getXScales(self.__plot_data)

                if x_axis_type is CTime and x_min is not None and x_max is not None:
                    x_min = int(x_min)
                    x_max = int(x_max)

                self.__plot_metrics_tracker.setScalesForType(
                    x_axis_type_name, x_min, x_max)

    def fetchDefaultYScales(self):
        if self.__plot_data is not None:
            active_plot = self.getActivePlot()
            y_axis_type_name = active_plot.yAxisType()

            y_axis_type = self.__plot_metrics_tracker.getType(y_axis_type_name)

            if y_axis_type is not None:
                y_min, y_max = active_plot.getYScales(self.__plot_data)

                if y_axis_type is CTime and y_min is not None and y_max is not None:
                    y_min = int(y_min)
                    y_max = int(y_max)

                self.__plot_metrics_tracker.setScalesForType(
                    y_axis_type_name, y_min, y_max)

    def resetCurrentScales(self):
        active_plot = self.getActivePlot()
        x_axis_type_name = active_plot.xAxisType()
        y_axis_type_name = active_plot.yAxisType()

        self.__plot_metrics_tracker.resetScaleType(x_axis_type_name)
        self.__plot_metrics_tracker.resetScaleType(y_axis_type_name)

        self.currentPlotChanged()
        self.plotSettingsChanged()

    def getActivePlot(self):
        """ @rtype: PlotPanel """
        if not self.__central_tab.currentIndex() > -1:
            raise AssertionError("No plot selected!")

        active_plot = self.__central_tab.currentWidget()
        assert isinstance(active_plot, PlotPanel)

        return active_plot

    def currentPlotChanged(self):
        active_plot = self.getActivePlot()

        if active_plot.isReady():
            x_axis_type_name = active_plot.xAxisType()
            x_axis_type = self.__plot_metrics_tracker.getType(x_axis_type_name)

            y_axis_type_name = active_plot.yAxisType()
            y_axis_type = self.__plot_metrics_tracker.getType(y_axis_type_name)

            if not self.__plot_metrics_tracker.hasScale(x_axis_type_name):
                self.fetchDefaultXScales()

            if not self.__plot_metrics_tracker.hasScale(y_axis_type_name):
                self.fetchDefaultYScales()

            x_min, x_max = self.__plot_metrics_tracker.getScalesForType(
                x_axis_type_name)
            y_min, y_max = self.__plot_metrics_tracker.getScalesForType(
                y_axis_type_name)

            self.__toolbar.setToolBarOptions(
                x_axis_type, y_axis_type,
                active_plot.isReportStepCapable()
                and self.__plot_metrics_tracker.dataTypeSupportsReportStep())
            self.__toolbar.setScales(x_min, x_max, y_min, y_max)

    def plotSettingsChanged(self):
        x_min, x_max = self.__toolbar.getXScales()
        y_min, y_max = self.__toolbar.getYScales()

        active_plot = self.getActivePlot()

        x_axis_type_name = active_plot.xAxisType()
        y_axis_type_name = active_plot.yAxisType()

        self.__plot_metrics_tracker.setScalesForType(x_axis_type_name, x_min,
                                                     x_max)
        self.__plot_metrics_tracker.setScalesForType(y_axis_type_name, y_min,
                                                     y_max)

        self.updatePlots()

    def updatePlots(self):
        report_step = self.__toolbar.getReportStep()

        for plot_panel in self.__plot_panels:
            if plot_panel.isPlotVisible():
                model = plot_panel.getPlotBridge()
                model.setPlotData(self.__plot_data)
                model.setCustomSettings(
                    self.__customize_plot_widget.getCustomSettings())
                model.setReportStepTime(report_step)

                x_axis_type_name = plot_panel.xAxisType()
                y_axis_type_name = plot_panel.yAxisType()

                x_min, x_max = self.__plot_metrics_tracker.getScalesForType(
                    x_axis_type_name)
                y_min, y_max = self.__plot_metrics_tracker.getScalesForType(
                    y_axis_type_name)

                model.setScales(x_min, x_max, y_min, y_max)

                plot_panel.renderNow()

    def exportActivePlot(self):
        active_plot = self.getActivePlot()

        if self.__exporter is None:
            path = None
        else:
            path = self.__exporter.getCurrentPath()

        report_step = self.__toolbar.getReportStep()

        x_axis_type_name = active_plot.xAxisType()
        y_axis_type_name = active_plot.yAxisType()

        x_min, x_max = self.__plot_metrics_tracker.getScalesForType(
            x_axis_type_name)
        y_min, y_max = self.__plot_metrics_tracker.getScalesForType(
            y_axis_type_name)

        settings = {
            "x_min": x_min,
            "x_max": x_max,
            "y_min": y_min,
            "y_max": y_max,
            "report_step": report_step
        }

        self.__exporter = ExportPlot(
            active_plot, settings,
            self.__customize_plot_widget.getCustomSettings(), path)

        self.__exporter.export()

    def addPlotPanel(self, name, path, short_name=None):
        if short_name is None:
            short_name = name

        plot_panel = PlotPanel(name, short_name, path)
        plot_panel.plotReady.connect(self.plotReady)
        self.__plot_panels.append(plot_panel)
        self.__central_tab.addTab(plot_panel, name)

    def addDock(self,
                name,
                widget,
                area=Qt.LeftDockWidgetArea,
                allowed_areas=Qt.AllDockWidgetAreas):
        dock_widget = QDockWidget(name)
        dock_widget.setObjectName("%sDock" % name)
        dock_widget.setWidget(widget)
        dock_widget.setAllowedAreas(allowed_areas)
        dock_widget.setFeatures(QDockWidget.DockWidgetFloatable
                                | QDockWidget.DockWidgetMovable)

        self.addDockWidget(area, dock_widget)
        return dock_widget

    def checkPlotStatus(self):
        for plot_panel in self.__plot_panels:
            if not plot_panel.isReady():
                return False

        if len(self.__plot_cases) == 0:
            return False

        return True

    def plotReady(self):
        if self.checkPlotStatus():
            self.__data_type_keys_widget.selectDefault()
            self.currentPlotChanged()
            self.__customize_plot_widget.emitChange()

    def caseSelectionChanged(self):
        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()
        self.keySelected(self.__plot_metrics_tracker.getDataTypeKey())

    def showOrHidePlotTab(self, plot_panel, is_visible, show_plot):
        plot_panel.setPlotIsVisible(show_plot)
        if show_plot and not is_visible:
            index = self.__plot_panels.index(plot_panel)
            self.__central_tab.insertTab(index, plot_panel,
                                         plot_panel.getName())
        elif not show_plot and is_visible:
            index = self.__central_tab.indexOf(plot_panel)
            self.__central_tab.removeTab(index)

    @may_take_a_long_time
    def keySelected(self, key):
        key = str(key)
        old_data_type_key = self.__plot_metrics_tracker.getDataTypeKey()
        self.__plot_metrics_tracker.setDataTypeKey(key)

        plot_data_fetcher = PlotDataFetcher()
        self.__plot_data = plot_data_fetcher.getPlotDataForKeyAndCases(
            key, self.__plot_cases)
        self.__plot_data.setParent(self)

        self.__central_tab.blockSignals(True)

        self.__plot_panel_tracker.storePlotType(plot_data_fetcher,
                                                old_data_type_key)

        for plot_panel in self.__plot_panels:
            self.showOrHidePlotTab(plot_panel, False, True)

        self.__plot_metrics_tracker.setDataTypeKeySupportsReportSteps(
            plot_data_fetcher.dataTypeKeySupportsReportSteps(key))
        show_pca = plot_data_fetcher.isPcaDataKey(key)
        for plot_panel in self.__plot_panels:
            visible = self.__central_tab.indexOf(plot_panel) > -1

            if plot_data_fetcher.isSummaryKey(key):
                show_plot = plot_panel.supportsPlotProperties(time=True,
                                                              value=True,
                                                              histogram=True,
                                                              pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isBlockObservationKey(key):
                show_plot = plot_panel.supportsPlotProperties(depth=True,
                                                              value=True,
                                                              pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isGenKWKey(key):
                show_plot = plot_panel.supportsPlotProperties(value=True,
                                                              histogram=True,
                                                              pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isGenDataKey(key):
                show_plot = plot_panel.supportsPlotProperties(index=True,
                                                              pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isPcaDataKey(key):
                show_plot = plot_panel.supportsPlotProperties(pca=show_pca)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            else:
                raise NotImplementedError("Key %s not supported." % key)

        self.__plot_panel_tracker.restorePlotType(plot_data_fetcher, key)

        self.__central_tab.blockSignals(False)
        self.currentPlotChanged()

        if self.checkPlotStatus():
            self.plotSettingsChanged()
Example #10
0
    def __init__(self, ert, parent):
        QMainWindow.__init__(self, parent)

        self.__ert = ert
        """:type: ert.enkf.enkf_main.EnKFMain"""

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__central_tab = QTabWidget()
        self.__central_tab.currentChanged.connect(self.currentPlotChanged)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self.__central_tab)

        self.setCentralWidget(central_widget)

        key_manager = ert.getKeyManager()
        """:type: ert.enkf.key_manager.KeyManager """

        self.__plot_widgets = []
        """:type: list of PlotWidget"""

        self.__data_gatherers = []
        """:type: list of PlotDataGatherer """

        summary_gatherer = self.createDataGatherer(PDG.gatherSummaryData, key_manager.isSummaryKey, refcaseGatherFunc=PDG.gatherSummaryRefcaseData, observationGatherFunc=PDG.gatherSummaryObservationData)
        gen_data_gatherer = self.createDataGatherer(PDG.gatherGenDataData, key_manager.isGenDataKey, observationGatherFunc=PDG.gatherGenDataObservationData)
        gen_kw_gatherer = self.createDataGatherer(PDG.gatherGenKwData, key_manager.isGenKwKey)
        custom_kw_gatherer = self.createDataGatherer(PDG.gatherCustomKwData, key_manager.isCustomKwKey)


        self.addPlotWidget("Ensemble", plots.plotEnsemble, [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget("Statistics", plots.plotStatistics, [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget("Histogram", plots.plotHistogram, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget("Gaussian KDE", plots.plotGaussianKDE, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget("Distribution", plots.plotDistribution, [gen_kw_gatherer, custom_kw_gatherer])


        self.__data_types_key_model = DataTypeKeysListModel(ert)

        self.__data_type_keys_widget = DataTypeKeysWidget(self.__data_types_key_model)
        self.__data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(self.keySelected)
        plot_case_dock = self.addDock("Plot case", self.__case_selection_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(self.keySelected)
        customize_plot_dock = self.addDock("Customize", self.__customize_plot_widget)


        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)

        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_widgets[self.__central_tab.currentIndex()].setActive()
        self.__data_type_keys_widget.selectDefault()
Example #11
0
class PlotWindow(QMainWindow):
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__central_tab = QTabWidget()
        self.setCentralWidget(self.__central_tab)


        self.__plot_panels = []

        self.addPlotPanel("Ensemble plot", "gui/plots/simple_plot.html", short_name="Plot")
        self.addPlotPanel("Ensemble overview plot", "gui/plots/simple_overview_plot.html", short_name="oPlot")
        self.addPlotPanel("Histogram", "gui/plots/histogram.html", short_name="Histogram")
        self.addPlotPanel("RFT plot", "gui/plots/rft.html", short_name="RFT")
        self.addPlotPanel("RFT overview plot", "gui/plots/rft_overview.html", short_name="oRFT")

        self.__data_type_keys_widget = DataTypeKeysWidget()
        self.__data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(self.caseSelectionChanged)
        self.addDock("Plot case", self.__case_selection_widget)

        self.__plot_metrics_widget = PlotMetricsWidget()
        self.__plot_metrics_widget.plotScalesChanged.connect(self.scalesChanged)
        self.__plot_metrics_widget.reportStepTimeChanged.connect(self.reportStepTimeChanged)
        self.addDock("Plot metrics", self.__plot_metrics_widget)

        self.__data_type_key = None
        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()
        self.__value_scale_tracker = ScaleTracker("Value")
        self.__time_scale_tracker = ScaleTracker("Time")
        self.__depth_scale_tracker = ScaleTracker("Depth")


    def addPlotPanel(self, name, path, short_name=None):
        if short_name is None:
            short_name = name

        plot_panel = PlotPanel(name, short_name, path)
        plot_panel.plotReady.connect(self.plotReady)
        self.__plot_panels.append(plot_panel)
        self.__central_tab.addTab(plot_panel, name)


    def addDock(self, name, widget, area=Qt.LeftDockWidgetArea, allowed_areas=Qt.AllDockWidgetAreas):
        dock_widget = QDockWidget(name)
        dock_widget.setObjectName("%sDock" % name)
        dock_widget.setWidget(widget)
        dock_widget.setAllowedAreas(allowed_areas)
        dock_widget.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable)

        self.addDockWidget(area, dock_widget)
        return dock_widget


    def checkPlotStatus(self):
        for plot_panel in self.__plot_panels:
            if not plot_panel.isReady():
                return False

        if len(self.__plot_cases) == 0:
            return False

        return True

    def plotReady(self):
        if self.checkPlotStatus():
            self.__data_type_keys_widget.selectDefault()


    def caseSelectionChanged(self):
        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()
        self.keySelected(self.__data_type_key)

    def scalesChanged(self):
        value_min = self.__plot_metrics_widget.getValueMin()
        value_max = self.__plot_metrics_widget.getValueMax()
        time_min = self.__plot_metrics_widget.getTimeMin()
        time_max = self.__plot_metrics_widget.getTimeMax()
        depth_min = self.__plot_metrics_widget.getDepthMin()
        depth_max = self.__plot_metrics_widget.getDepthMax()

        self.__value_scale_tracker.setScaleValues(self.__data_type_key, value_min, value_max)
        self.__time_scale_tracker.setScaleValues(self.__data_type_key, time_min, time_max)
        self.__depth_scale_tracker.setScaleValues(self.__data_type_key, depth_min, depth_max)


        for plot_panel in self.__plot_panels:
            plot_panel.setScales(time_min, time_max, value_min, value_max, depth_min, depth_max)


    def reportStepTimeChanged(self):
        t = self.__plot_metrics_widget.getSelectedReportStepTime()

        for plot_panel in self.__plot_panels:
            plot_panel.setReportStepTime(t)


    def showOrHidePlotTab(self, plot_panel, is_visible, show_plot):
        plot_panel.setPlotIsVisible(show_plot)
        if show_plot and not is_visible:
            index = self.__plot_panels.index(plot_panel)
            self.__central_tab.insertTab(index, plot_panel, plot_panel.getName())
        elif not show_plot and is_visible:
            index = self.__central_tab.indexOf(plot_panel)
            self.__central_tab.removeTab(index)

    @may_take_a_long_time
    def keySelected(self, key):
        self.__data_type_key = str(key)

        for plot_panel in self.__plot_panels:
            visible = self.__central_tab.indexOf(plot_panel) > -1

            if PlotDataFetcher().isSummaryKey(self.__data_type_key):
                show_plot = plot_panel.supportsPlotProperties(time=True, value=True)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif PlotDataFetcher().isBlockObservationKey(self.__data_type_key):
                show_plot = plot_panel.supportsPlotProperties(depth=True, value=True)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            else:
                raise NotImplementedError("Key %s not supported." % self.__data_type_key)

        value_min = self.__value_scale_tracker.getMinimumScaleValue(self.__data_type_key)
        value_max = self.__value_scale_tracker.getMaximumScaleValue(self.__data_type_key)
        time_min = self.__time_scale_tracker.getMinimumScaleValue(self.__data_type_key)
        time_max = self.__time_scale_tracker.getMaximumScaleValue(self.__data_type_key)
        depth_min = self.__depth_scale_tracker.getMinimumScaleValue(self.__data_type_key)
        depth_max = self.__depth_scale_tracker.getMaximumScaleValue(self.__data_type_key)

        self.__plot_metrics_widget.updateScales(time_min, time_max, value_min, value_max, depth_min, depth_max)


        if self.checkPlotStatus():
            data = PlotDataFetcher().getPlotDataForKeyAndCases(self.__data_type_key, self.__plot_cases)
            data.setParent(self)

            for plot_panel in self.__plot_panels:
                plot_panel.setPlotData(data)
Example #12
0
class PlotWindow(QMainWindow):
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__central_tab = QTabWidget()
        self.setCentralWidget(self.__central_tab)


        self.__plot_panels = []
        """:type: list of PlotPanel"""

        self.__selected_plot_for_type = {}

        self.addPlotPanel("Ensemble plot", "gui/plots/simple_plot.html", short_name="Plot")
        self.addPlotPanel("Ensemble overview plot", "gui/plots/simple_overview_plot.html", short_name="oPlot")
        self.addPlotPanel("Histogram", "gui/plots/histogram.html", short_name="Histogram")
        self.addPlotPanel("Distribution", "gui/plots/gen_kw.html", short_name="Distribution")
        self.addPlotPanel("RFT plot", "gui/plots/rft.html", short_name="RFT")
        self.addPlotPanel("RFT overview plot", "gui/plots/rft_overview.html", short_name="oRFT")

        self.__data_type_keys_widget = DataTypeKeysWidget()
        self.__data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(self.caseSelectionChanged)
        plot_case_dock = self.addDock("Plot case", self.__case_selection_widget)

        self.__plot_metrics_widget = PlotMetricsWidget()
        self.__plot_metrics_widget.plotSettingsChanged.connect(self.plotSettingsChanged)
        plot_metrics_dock = self.addDock("Plot metrics", self.__plot_metrics_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(self.plotSettingsChanged)
        customize_plot_dock = self.addDock("Customize", self.__customize_plot_widget)

        self.__export_plot_widget = ExportPlotWidget()
        self.__export_plot_widget.exportButtonPressed.connect(self.exportActivePlot)
        export_dock = self.addDock("Export Plot", self.__export_plot_widget)

        self.__exporter = None


        self.tabifyDockWidget(plot_case_dock, plot_metrics_dock)
        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)
        self.tabifyDockWidget(plot_case_dock, export_dock)
        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()

    def plotSettingsChanged(self):
        plot_data_fetcher = PlotDataFetcher()
        data_key = self.__plot_metrics_widget.getDataKeyType()
        plot_data = plot_data_fetcher.getPlotDataForKeyAndCases(data_key, self.__plot_cases)

        for plot_panel in self.__plot_panels:
            if plot_panel.isPlotVisible():
                model = plot_panel.getPlotBridge()
                model.setPlotData(plot_data)
                model.setCustomSettings(self.__customize_plot_widget.getCustomSettings())
                model.setPlotSettings(self.__plot_metrics_widget.getSettings())
                plot_panel.renderNow()

    def exportActivePlot(self):
        if self.__central_tab.currentIndex() > -1:
            active_plot =  self.__central_tab.currentWidget()
            assert isinstance(active_plot, PlotPanel)
            self.__exporter = ExportPlot(active_plot, self.__plot_metrics_widget.getSettings(), self.__customize_plot_widget.getCustomSettings())
            self.__exporter.export()


    def addPlotPanel(self, name, path, short_name=None):
        if short_name is None:
            short_name = name

        plot_panel = PlotPanel(name, short_name, path)
        plot_panel.plotReady.connect(self.plotReady)
        self.__plot_panels.append(plot_panel)
        self.__central_tab.addTab(plot_panel, name)


    def addDock(self, name, widget, area=Qt.LeftDockWidgetArea, allowed_areas=Qt.AllDockWidgetAreas):
        dock_widget = QDockWidget(name)
        dock_widget.setObjectName("%sDock" % name)
        dock_widget.setWidget(widget)
        dock_widget.setAllowedAreas(allowed_areas)
        dock_widget.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable)

        self.addDockWidget(area, dock_widget)
        return dock_widget


    def checkPlotStatus(self):
        for plot_panel in self.__plot_panels:
            if not plot_panel.isReady():
                return False

        if len(self.__plot_cases) == 0:
            return False

        return True

    def plotReady(self):
        if self.checkPlotStatus():
            self.__data_type_keys_widget.selectDefault()
            self.__customize_plot_widget.emitChange()


    def caseSelectionChanged(self):
        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()
        self.keySelected(self.__plot_metrics_widget.getDataKeyType())


    def showOrHidePlotTab(self, plot_panel, is_visible, show_plot):
        plot_panel.setPlotIsVisible(show_plot)
        if show_plot and not is_visible:
            index = self.__plot_panels.index(plot_panel)
            self.__central_tab.insertTab(index, plot_panel, plot_panel.getName())
        elif not show_plot and is_visible:
            index = self.__central_tab.indexOf(plot_panel)
            self.__central_tab.removeTab(index)


    def storePlotType(self, fetcher, key):
        if key is not None:
            if fetcher.isSummaryKey(key):
                self.__selected_plot_for_type["summary"] = self.__central_tab.currentWidget()
            elif fetcher.isBlockObservationKey(key):
                self.__selected_plot_for_type["block"] = self.__central_tab.currentWidget()
            elif fetcher.isGenKWKey(key):
                self.__selected_plot_for_type["gen_kw"] = self.__central_tab.currentWidget()
            elif fetcher.isGenDataKey(key):
                self.__selected_plot_for_type["gen_data"] = self.__central_tab.currentWidget()
            else:
                raise NotImplementedError("Key %s not supported." % key)

    def restorePlotType(self, fetcher, key):
        if key is not None:
            if fetcher.isSummaryKey(key):
                if "summary" in self.__selected_plot_for_type:
                    self.__central_tab.setCurrentWidget(self.__selected_plot_for_type["summary"])
                else:
                    if self.__central_tab.count() > 0:
                        self.__central_tab.setCurrentIndex(0)
            elif fetcher.isBlockObservationKey(key):
                if "block" in self.__selected_plot_for_type:
                    self.__central_tab.setCurrentWidget(self.__selected_plot_for_type["block"])
                else:
                    if self.__central_tab.count() > 0:
                        self.__central_tab.setCurrentIndex(0)
            elif fetcher.isGenKWKey(key):
                if "gen_kw" in self.__selected_plot_for_type:
                    self.__central_tab.setCurrentWidget(self.__selected_plot_for_type["gen_kw"])
                else:
                    if self.__central_tab.count() > 0:
                        self.__central_tab.setCurrentIndex(0)
            elif fetcher.isGenDataKey(key):
                if "gen_data" in self.__selected_plot_for_type:
                    self.__central_tab.setCurrentWidget(self.__selected_plot_for_type["gen_data"])
                else:
                    if self.__central_tab.count() > 0:
                        self.__central_tab.setCurrentIndex(0)
            else:
                raise NotImplementedError("Key %s not supported." % key)


    @may_take_a_long_time
    def keySelected(self, key):
        key = str(key)
        plot_data_fetcher = PlotDataFetcher()
        self.storePlotType(plot_data_fetcher, self.__plot_metrics_widget.getDataKeyType())

        for plot_panel in self.__plot_panels:
            visible = self.__central_tab.indexOf(plot_panel) > -1

            if plot_data_fetcher.isSummaryKey(key):
                show_plot = plot_panel.supportsPlotProperties(time=True, value=True, histogram=True)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isBlockObservationKey(key):
                show_plot = plot_panel.supportsPlotProperties(depth=True, value=True)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isGenKWKey(key):
                show_plot = plot_panel.supportsPlotProperties(value=True, histogram=True)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            elif plot_data_fetcher.isGenDataKey(key):
                show_plot = plot_panel.supportsPlotProperties(time=True, value=True)
                self.showOrHidePlotTab(plot_panel, visible, show_plot)

            else:
                raise NotImplementedError("Key %s not supported." % key)

        self.restorePlotType(plot_data_fetcher, key)
        self.__plot_metrics_widget.setDataKeyType(key)

        if self.checkPlotStatus():
            self.plotSettingsChanged()
Example #13
0
    def __init__(self, ert, parent):
        QMainWindow.__init__(self, parent)

        self.__ert = ert
        """:type: ert.enkf.enkf_main.EnKFMain"""

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__central_tab = QTabWidget()
        self.__central_tab.currentChanged.connect(self.currentPlotChanged)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self.__central_tab)

        self.setCentralWidget(central_widget)

        key_manager = ert.getKeyManager()
        """:type: ert.enkf.key_manager.KeyManager """

        self.__plot_widgets = []
        """:type: list of PlotWidget"""

        self.__data_gatherers = []
        """:type: list of PlotDataGatherer """

        summary_gatherer = self.createDataGatherer(
            PDG.gatherSummaryData,
            key_manager.isSummaryKey,
            refcaseGatherFunc=PDG.gatherSummaryRefcaseData,
            observationGatherFunc=PDG.gatherSummaryObservationData)
        gen_data_gatherer = self.createDataGatherer(
            PDG.gatherGenDataData,
            key_manager.isGenDataKey,
            observationGatherFunc=PDG.gatherGenDataObservationData)
        gen_kw_gatherer = self.createDataGatherer(PDG.gatherGenKwData,
                                                  key_manager.isGenKwKey)
        custom_kw_gatherer = self.createDataGatherer(PDG.gatherCustomKwData,
                                                     key_manager.isCustomKwKey)

        self.addPlotWidget("Ensemble", plots.plotEnsemble,
                           [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget("Statistics", plots.plotStatistics,
                           [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget("Histogram", plots.plotHistogram,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget("Gaussian KDE", plots.plotGaussianKDE,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget("Distribution", plots.plotDistribution,
                           [gen_kw_gatherer, custom_kw_gatherer])

        self.__data_types_key_model = DataTypeKeysListModel(ert)

        self.__data_type_keys_widget = DataTypeKeysWidget(
            self.__data_types_key_model)
        self.__data_type_keys_widget.dataTypeKeySelected.connect(
            self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(
            self.keySelected)
        plot_case_dock = self.addDock("Plot case",
                                      self.__case_selection_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(
            self.keySelected)
        customize_plot_dock = self.addDock("Customize",
                                           self.__customize_plot_widget)

        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)

        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_widgets[self.__central_tab.currentIndex()].setActive()
        self.__data_type_keys_widget.selectDefault()
Example #14
0
class PlotWindow(QMainWindow):
    def __init__(self, ert, parent):
        QMainWindow.__init__(self, parent)

        self.__ert = ert
        """:type: ert.enkf.enkf_main.EnKFMain"""

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__central_tab = QTabWidget()
        self.__central_tab.currentChanged.connect(self.currentPlotChanged)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self.__central_tab)

        self.setCentralWidget(central_widget)

        key_manager = ert.getKeyManager()
        """:type: ert.enkf.key_manager.KeyManager """

        self.__plot_widgets = []
        """:type: list of PlotWidget"""

        self.__data_gatherers = []
        """:type: list of PlotDataGatherer """

        summary_gatherer = self.createDataGatherer(
            PDG.gatherSummaryData,
            key_manager.isSummaryKey,
            refcaseGatherFunc=PDG.gatherSummaryRefcaseData,
            observationGatherFunc=PDG.gatherSummaryObservationData)
        gen_data_gatherer = self.createDataGatherer(
            PDG.gatherGenDataData,
            key_manager.isGenDataKey,
            observationGatherFunc=PDG.gatherGenDataObservationData)
        gen_kw_gatherer = self.createDataGatherer(PDG.gatherGenKwData,
                                                  key_manager.isGenKwKey)
        custom_kw_gatherer = self.createDataGatherer(PDG.gatherCustomKwData,
                                                     key_manager.isCustomKwKey)

        self.addPlotWidget("Ensemble", plots.plotEnsemble,
                           [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget("Statistics", plots.plotStatistics,
                           [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget("Histogram", plots.plotHistogram,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget("Gaussian KDE", plots.plotGaussianKDE,
                           [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget("Distribution", plots.plotDistribution,
                           [gen_kw_gatherer, custom_kw_gatherer])

        self.__data_types_key_model = DataTypeKeysListModel(ert)

        self.__data_type_keys_widget = DataTypeKeysWidget(
            self.__data_types_key_model)
        self.__data_type_keys_widget.dataTypeKeySelected.connect(
            self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(
            self.keySelected)
        plot_case_dock = self.addDock("Plot case",
                                      self.__case_selection_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(
            self.keySelected)
        customize_plot_dock = self.addDock("Customize",
                                           self.__customize_plot_widget)

        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)

        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_widgets[self.__central_tab.currentIndex()].setActive()
        self.__data_type_keys_widget.selectDefault()

    def createDataGatherer(self,
                           dataGatherFunc,
                           gatherConditionFunc,
                           refcaseGatherFunc=None,
                           observationGatherFunc=None):
        data_gatherer = PDG(dataGatherFunc,
                            gatherConditionFunc,
                            refcaseGatherFunc=refcaseGatherFunc,
                            observationGatherFunc=observationGatherFunc)
        self.__data_gatherers.append(data_gatherer)
        return data_gatherer

    def currentPlotChanged(self):
        for plot_widget in self.__plot_widgets:
            plot_widget.setActive(False)
            index = self.__central_tab.indexOf(plot_widget)

            if index == self.__central_tab.currentIndex(
            ) and plot_widget.canPlotKey(self.getSelectedKey()):
                plot_widget.setActive()
                plot_widget.updatePlot()

    def createPlotContext(self, figure):
        key = self.getSelectedKey()
        cases = self.__case_selection_widget.getPlotCaseNames()
        data_gatherer = next((data_gatherer
                              for data_gatherer in self.__data_gatherers
                              if data_gatherer.canGatherDataForKey(key)), None)
        plot_config = PlotConfig(key)
        self.applyCustomization(plot_config)
        return PlotContext(self.__ert, figure, plot_config, cases, key,
                           data_gatherer)

    def getSelectedKey(self):
        key = str(self.__data_type_keys_widget.getSelectedItem())
        return key

    def addPlotWidget(self, name, plotFunction, data_gatherers, enabled=True):
        plot_condition_function_list = [
            data_gatherer.canGatherDataForKey
            for data_gatherer in data_gatherers
        ]
        plot_widget = PlotWidget(name, plotFunction,
                                 plot_condition_function_list,
                                 self.createPlotContext)

        index = self.__central_tab.addTab(plot_widget, name)
        self.__plot_widgets.append(plot_widget)
        self.__central_tab.setTabEnabled(index, enabled)

    def addDock(self,
                name,
                widget,
                area=Qt.LeftDockWidgetArea,
                allowed_areas=Qt.AllDockWidgetAreas):
        dock_widget = QDockWidget(name)
        dock_widget.setObjectName("%sDock" % name)
        dock_widget.setWidget(widget)
        dock_widget.setAllowedAreas(allowed_areas)
        dock_widget.setFeatures(QDockWidget.DockWidgetFloatable
                                | QDockWidget.DockWidgetMovable)

        self.addDockWidget(area, dock_widget)
        return dock_widget

    def applyCustomization(self, plot_config):
        custom = self.__customize_plot_widget.getCustomSettings()

        plot_config.setObservationsEnabled(custom["show_observations"])
        # plot_config.setRefcaseEnabled(custom["show_refcase"])
        plot_config.setLegendEnabled(custom["show_legend"])
        plot_config.setGridEnabled(custom["show_grid"])
        plot_config.setDistributionLineEnabled(
            custom["show_distribution_lines"])

        plot_config.setDefaultStyle(*custom["default_style"])
        plot_config.setRefcaseStyle(*custom["refcase_style"])

        plot_config.setStatisticsStyle("mean", *custom["mean_style"])
        plot_config.setStatisticsStyle("p50", *custom["p50_style"])
        plot_config.setStatisticsStyle("min-max", *custom["min-max_style"])
        plot_config.setStatisticsStyle("p10-p90", *custom["p10-p90_style"])
        plot_config.setStatisticsStyle("p33-p67", *custom["p33-p67_style"])

    @may_take_a_long_time
    def keySelected(self):
        key = self.getSelectedKey()

        for plot_widget in self.__plot_widgets:
            plot_widget.setDirty()
            index = self.__central_tab.indexOf(plot_widget)
            self.__central_tab.setTabEnabled(index,
                                             plot_widget.canPlotKey(key))

        for plot_widget in self.__plot_widgets:
            if plot_widget.canPlotKey(key):
                plot_widget.updatePlot()
Example #15
0
class PlotWindow(QMainWindow):


    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self._ert = ERT.ert
        """:type: ert.enkf.enkf_main.EnKFMain"""

        key_manager = self._ert.getKeyManager()
        """:type: ert.enkf.key_manager.KeyManager """

        self.setMinimumWidth(850)
        self.setMinimumHeight(650)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self._plot_customizer = PlotCustomizer(self, self._ert.plotConfig())

        def plotConfigCreator(key):
            return PlotConfigFactory.createPlotConfigForKey(self._ert, key)

        self._plot_customizer.setPlotConfigCreator(plotConfigCreator)
        self._plot_customizer.settingsChanged.connect(self.keySelected)

        self._central_tab = QTabWidget()
        self._central_tab.currentChanged.connect(self.currentPlotChanged)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self._central_tab)

        self.setCentralWidget(central_widget)

        self._plot_widgets = []
        """:type: list of PlotWidget"""

        self._data_gatherers = []
        """:type: list of PlotDataGatherer """

        summary_gatherer = self.createDataGatherer(PDG.gatherSummaryData, key_manager.isSummaryKey, refcaseGatherFunc=PDG.gatherSummaryRefcaseData, observationGatherFunc=PDG.gatherSummaryObservationData, historyGatherFunc=PDG.gatherSummaryHistoryData)
        gen_data_gatherer = self.createDataGatherer(PDG.gatherGenDataData, key_manager.isGenDataKey, observationGatherFunc=PDG.gatherGenDataObservationData)
        gen_kw_gatherer = self.createDataGatherer(PDG.gatherGenKwData, key_manager.isGenKwKey)
        custom_kw_gatherer = self.createDataGatherer(PDG.gatherCustomKwData, key_manager.isCustomKwKey)


        self.addPlotWidget(ENSEMBLE, plots.plotEnsemble, [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget(STATISTICS, plots.plotStatistics, [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget(HISTOGRAM, plots.plotHistogram, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(GAUSSIAN_KDE, plots.plotGaussianKDE, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(DISTRIBUTION, plots.plotDistribution, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(CROSS_CASE_STATISTICS, plots.plotCrossCaseStatistics, [gen_kw_gatherer, custom_kw_gatherer])


        data_types_key_model = DataTypeKeysListModel(self._ert)

        self._data_type_keys_widget = DataTypeKeysWidget(data_types_key_model)
        self._data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self._data_type_keys_widget)

        current_case = getCurrentCaseName()
        self._case_selection_widget = CaseSelectionWidget(current_case)
        self._case_selection_widget.caseSelectionChanged.connect(self.keySelected)
        self.addDock("Plot case", self._case_selection_widget)

        current_plot_widget = self._plot_widgets[self._central_tab.currentIndex()]
        current_plot_widget.setActive()
        self._data_type_keys_widget.selectDefault()
        self._updateCustomizer(current_plot_widget)




    def createDataGatherer(self, dataGatherFunc, gatherConditionFunc, refcaseGatherFunc=None, observationGatherFunc=None, historyGatherFunc=None):
        data_gatherer = PDG(dataGatherFunc, gatherConditionFunc, refcaseGatherFunc=refcaseGatherFunc, observationGatherFunc=observationGatherFunc, historyGatherFunc=historyGatherFunc)
        self._data_gatherers.append(data_gatherer)
        return data_gatherer


    def currentPlotChanged(self):
        for plot_widget in self._plot_widgets:
            plot_widget.setActive(False)
            index = self._central_tab.indexOf(plot_widget)

            if index == self._central_tab.currentIndex() and plot_widget.canPlotKey(self.getSelectedKey()):
                plot_widget.setActive()
                self._updateCustomizer(plot_widget)
                plot_widget.updatePlot()

    def _updateCustomizer(self, plot_widget):
        """ @type plot_widget: PlotWidget """
        key = self.getSelectedKey()
        key_manager = self._ert.getKeyManager()

        index_type = PlotContext.UNKNOWN_AXIS

        if key_manager.isGenDataKey(key):
            index_type = PlotContext.INDEX_AXIS
        elif key_manager.isSummaryKey(key):
            index_type = PlotContext.DATE_AXIS

        x_axis_type = PlotContext.UNKNOWN_AXIS
        y_axis_type = PlotContext.UNKNOWN_AXIS

        if plot_widget.name == ENSEMBLE:
            x_axis_type = index_type
            y_axis_type = PlotContext.VALUE_AXIS
        elif plot_widget.name == STATISTICS:
            x_axis_type = index_type
            y_axis_type = PlotContext.VALUE_AXIS
        elif plot_widget.name == DISTRIBUTION:
            y_axis_type = PlotContext.VALUE_AXIS
        elif plot_widget.name == CROSS_CASE_STATISTICS:
            y_axis_type = PlotContext.VALUE_AXIS
        elif plot_widget.name == HISTOGRAM:
            x_axis_type = PlotContext.VALUE_AXIS
            y_axis_type = PlotContext.COUNT_AXIS
        elif plot_widget.name == GAUSSIAN_KDE:
            x_axis_type = PlotContext.VALUE_AXIS
            y_axis_type = PlotContext.DENSITY_AXIS

        self._plot_customizer.setAxisTypes(x_axis_type, y_axis_type)


    def createPlotContext(self, figure):
        key = self.getSelectedKey()
        cases = self._case_selection_widget.getPlotCaseNames()
        data_gatherer = self.getDataGathererForKey(key)
        plot_config = PlotConfig.createCopy(self._plot_customizer.getPlotConfig())
        plot_config.setTitle(key)
        return PlotContext(self._ert, figure, plot_config, cases, key, data_gatherer)

    def getDataGathererForKey(self, key):
        """ @rtype: PlotDataGatherer """
        return next((data_gatherer for data_gatherer in self._data_gatherers if data_gatherer.canGatherDataForKey(key)), None)

    def getSelectedKey(self):
        return str(self._data_type_keys_widget.getSelectedItem())

    def addPlotWidget(self, name, plotFunction, data_gatherers, enabled=True):
        plot_condition_function_list = [data_gatherer.canGatherDataForKey for data_gatherer in data_gatherers]
        plot_widget = PlotWidget(name, plotFunction, plot_condition_function_list, self.createPlotContext)
        plot_widget.customizationTriggered.connect(self.toggleCustomizeDialog)

        index = self._central_tab.addTab(plot_widget, name)
        self._plot_widgets.append(plot_widget)
        self._central_tab.setTabEnabled(index, enabled)


    def addDock(self, name, widget, area=Qt.LeftDockWidgetArea, allowed_areas=Qt.AllDockWidgetAreas):
        dock_widget = QDockWidget(name)
        dock_widget.setObjectName("%sDock" % name)
        dock_widget.setWidget(widget)
        dock_widget.setAllowedAreas(allowed_areas)
        dock_widget.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable)

        self.addDockWidget(area, dock_widget)
        return dock_widget


    @showWaitCursorWhileWaiting
    def keySelected(self):
        key = self.getSelectedKey()
        self._plot_customizer.switchPlotConfigHistory(key)

        for plot_widget in self._plot_widgets:
            plot_widget.setDirty()
            index = self._central_tab.indexOf(plot_widget)
            self._central_tab.setTabEnabled(index, plot_widget.canPlotKey(key))

        for plot_widget in self._plot_widgets:
            if plot_widget.canPlotKey(key):
                plot_widget.updatePlot()


    def toggleCustomizeDialog(self):
        self._plot_customizer.toggleCustomizationDialog()
Example #16
0
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__plot_data = None

        self.__plot_metrics_tracker = PlotMetricsTracker()
        self.__plot_metrics_tracker.addScaleType("value", float)
        self.__plot_metrics_tracker.addScaleType("depth", float)
        self.__plot_metrics_tracker.addScaleType("pca", float)
        self.__plot_metrics_tracker.addScaleType("index", int)
        self.__plot_metrics_tracker.addScaleType("count", int)
        self.__plot_metrics_tracker.addScaleType("time", CTime)

        self.__central_tab = QTabWidget()
        self.__central_tab.currentChanged.connect(self.currentPlotChanged)

        self.__plot_panel_tracker = PlotPanelTracker(self.__central_tab)
        self.__plot_panel_tracker.addKeyTypeTester(
            "summary", PlotDataFetcher.isSummaryKey)
        self.__plot_panel_tracker.addKeyTypeTester(
            "block", PlotDataFetcher.isBlockObservationKey)
        self.__plot_panel_tracker.addKeyTypeTester("gen_kw",
                                                   PlotDataFetcher.isGenKWKey)
        self.__plot_panel_tracker.addKeyTypeTester(
            "gen_data", PlotDataFetcher.isGenDataKey)
        self.__plot_panel_tracker.addKeyTypeTester(
            "custom_pca", PlotDataFetcher.isCustomPcaDataKey)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        self.__toolbar = PlotToolBar()
        self.__toolbar.resetScalesClicked.connect(self.resetCurrentScales)

        central_layout.addWidget(self.__toolbar)
        central_layout.addWidget(self.__central_tab)

        self.setCentralWidget(central_widget)

        self.__plot_panels = []
        """:type: list of PlotPanel"""

        self.addPlotPanel("Ensemble plot",
                          "gui/plots/simple_plot.html",
                          short_name="EP")
        self.addPlotPanel("Ensemble overview plot",
                          "gui/plots/simple_overview_plot.html",
                          short_name="EOP")
        self.addPlotPanel("Ensemble statistics",
                          "gui/plots/ensemble_statistics_plot.html",
                          short_name="ES")
        self.addPlotPanel("Histogram",
                          "gui/plots/histogram.html",
                          short_name="Histogram")
        self.addPlotPanel("Distribution",
                          "gui/plots/gen_kw.html",
                          short_name="Distribution")
        self.addPlotPanel("RFT plot", "gui/plots/rft.html", short_name="RFT")
        self.addPlotPanel("RFT overview plot",
                          "gui/plots/rft_overview.html",
                          short_name="oRFT")
        self.addPlotPanel("Ensemble plot",
                          "gui/plots/gen_data.html",
                          short_name="epGenData")
        self.addPlotPanel("Ensemble overview plot",
                          "gui/plots/gen_data_overview.html",
                          short_name="eopGenData")
        self.addPlotPanel("Ensemble statistics",
                          "gui/plots/gen_data_statistics_plot.html",
                          short_name="esGenData")
        self.addPlotPanel("PCA plot", "gui/plots/pca.html", short_name="PCA")

        self.__data_type_keys_widget = DataTypeKeysWidget()
        self.__data_type_keys_widget.dataTypeKeySelected.connect(
            self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(
            self.caseSelectionChanged)
        plot_case_dock = self.addDock("Plot case",
                                      self.__case_selection_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(
            self.plotSettingsChanged)
        customize_plot_dock = self.addDock("Customize",
                                           self.__customize_plot_widget)

        self.__toolbar.exportClicked.connect(self.exportActivePlot)
        self.__toolbar.plotScalesChanged.connect(self.plotSettingsChanged)
        self.__toolbar.reportStepChanged.connect(self.plotSettingsChanged)

        self.__exporter = None
        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)

        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_cases = self.__case_selection_widget.getPlotCaseNames()
Example #17
0
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)

        self._ert = ERT.ert
        """:type: ert.enkf.enkf_main.EnKFMain"""

        key_manager = self._ert.getKeyManager()
        """:type: ert.enkf.key_manager.KeyManager """

        self.setMinimumWidth(850)
        self.setMinimumHeight(650)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self._plot_customizer = PlotCustomizer(self, self._ert.plotConfig())

        def plotConfigCreator(key):
            return PlotConfigFactory.createPlotConfigForKey(self._ert, key)

        self._plot_customizer.setPlotConfigCreator(plotConfigCreator)
        self._plot_customizer.settingsChanged.connect(self.keySelected)

        self._central_tab = QTabWidget()
        self._central_tab.currentChanged.connect(self.currentPlotChanged)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self._central_tab)

        self.setCentralWidget(central_widget)

        self._plot_widgets = []
        """:type: list of PlotWidget"""

        self._data_gatherers = []
        """:type: list of PlotDataGatherer """

        summary_gatherer = self.createDataGatherer(PDG.gatherSummaryData, key_manager.isSummaryKey, refcaseGatherFunc=PDG.gatherSummaryRefcaseData, observationGatherFunc=PDG.gatherSummaryObservationData, historyGatherFunc=PDG.gatherSummaryHistoryData)
        gen_data_gatherer = self.createDataGatherer(PDG.gatherGenDataData, key_manager.isGenDataKey, observationGatherFunc=PDG.gatherGenDataObservationData)
        gen_kw_gatherer = self.createDataGatherer(PDG.gatherGenKwData, key_manager.isGenKwKey)
        custom_kw_gatherer = self.createDataGatherer(PDG.gatherCustomKwData, key_manager.isCustomKwKey)


        self.addPlotWidget(ENSEMBLE, plots.plotEnsemble, [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget(STATISTICS, plots.plotStatistics, [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget(HISTOGRAM, plots.plotHistogram, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(GAUSSIAN_KDE, plots.plotGaussianKDE, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(DISTRIBUTION, plots.plotDistribution, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget(CROSS_CASE_STATISTICS, plots.plotCrossCaseStatistics, [gen_kw_gatherer, custom_kw_gatherer])


        data_types_key_model = DataTypeKeysListModel(self._ert)

        self._data_type_keys_widget = DataTypeKeysWidget(data_types_key_model)
        self._data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self._data_type_keys_widget)

        current_case = getCurrentCaseName()
        self._case_selection_widget = CaseSelectionWidget(current_case)
        self._case_selection_widget.caseSelectionChanged.connect(self.keySelected)
        self.addDock("Plot case", self._case_selection_widget)

        current_plot_widget = self._plot_widgets[self._central_tab.currentIndex()]
        current_plot_widget.setActive()
        self._data_type_keys_widget.selectDefault()
        self._updateCustomizer(current_plot_widget)
Example #18
0
class PlotWindow(QMainWindow):
    def __init__(self, ert, parent):
        QMainWindow.__init__(self, parent)

        self.__ert = ert
        """:type: ert.enkf.enkf_main.EnKFMain"""

        self.setMinimumWidth(750)
        self.setMinimumHeight(500)

        self.setWindowTitle("Plotting")
        self.activateWindow()

        self.__central_tab = QTabWidget()
        self.__central_tab.currentChanged.connect(self.currentPlotChanged)

        central_widget = QWidget()
        central_layout = QVBoxLayout()
        central_layout.setContentsMargins(0, 0, 0, 0)
        central_widget.setLayout(central_layout)

        central_layout.addWidget(self.__central_tab)

        self.setCentralWidget(central_widget)

        key_manager = ert.getKeyManager()
        """:type: ert.enkf.key_manager.KeyManager """

        self.__plot_widgets = []
        """:type: list of PlotWidget"""

        self.__data_gatherers = []
        """:type: list of PlotDataGatherer """

        summary_gatherer = self.createDataGatherer(PDG.gatherSummaryData, key_manager.isSummaryKey, refcaseGatherFunc=PDG.gatherSummaryRefcaseData, observationGatherFunc=PDG.gatherSummaryObservationData)
        gen_data_gatherer = self.createDataGatherer(PDG.gatherGenDataData, key_manager.isGenDataKey, observationGatherFunc=PDG.gatherGenDataObservationData)
        gen_kw_gatherer = self.createDataGatherer(PDG.gatherGenKwData, key_manager.isGenKwKey)
        custom_kw_gatherer = self.createDataGatherer(PDG.gatherCustomKwData, key_manager.isCustomKwKey)


        self.addPlotWidget("Ensemble", plots.plotEnsemble, [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget("Statistics", plots.plotStatistics, [summary_gatherer, gen_data_gatherer])
        self.addPlotWidget("Histogram", plots.plotHistogram, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget("Gaussian KDE", plots.plotGaussianKDE, [gen_kw_gatherer, custom_kw_gatherer])
        self.addPlotWidget("Distribution", plots.plotDistribution, [gen_kw_gatherer, custom_kw_gatherer])


        self.__data_types_key_model = DataTypeKeysListModel(ert)

        self.__data_type_keys_widget = DataTypeKeysWidget(self.__data_types_key_model)
        self.__data_type_keys_widget.dataTypeKeySelected.connect(self.keySelected)
        self.addDock("Data types", self.__data_type_keys_widget)

        current_case = CaseSelectorModel().getCurrentChoice()
        self.__case_selection_widget = CaseSelectionWidget(current_case)
        self.__case_selection_widget.caseSelectionChanged.connect(self.keySelected)
        plot_case_dock = self.addDock("Plot case", self.__case_selection_widget)

        self.__customize_plot_widget = CustomizePlotWidget()
        self.__customize_plot_widget.customPlotSettingsChanged.connect(self.keySelected)
        customize_plot_dock = self.addDock("Customize", self.__customize_plot_widget)


        self.tabifyDockWidget(plot_case_dock, customize_plot_dock)

        plot_case_dock.show()
        plot_case_dock.raise_()

        self.__plot_widgets[self.__central_tab.currentIndex()].setActive()
        self.__data_type_keys_widget.selectDefault()


    def createDataGatherer(self, dataGatherFunc, gatherConditionFunc, refcaseGatherFunc=None, observationGatherFunc=None):
        data_gatherer = PDG(dataGatherFunc, gatherConditionFunc, refcaseGatherFunc=refcaseGatherFunc, observationGatherFunc=observationGatherFunc)
        self.__data_gatherers.append(data_gatherer)
        return data_gatherer


    def currentPlotChanged(self):
        for plot_widget in self.__plot_widgets:
            plot_widget.setActive(False)
            index = self.__central_tab.indexOf(plot_widget)

            if index == self.__central_tab.currentIndex() and plot_widget.canPlotKey(self.getSelectedKey()):
                plot_widget.setActive()
                plot_widget.updatePlot()


    def createPlotContext(self, figure):
        key = self.getSelectedKey()
        cases = self.__case_selection_widget.getPlotCaseNames()
        data_gatherer = next((data_gatherer for data_gatherer in self.__data_gatherers if data_gatherer.canGatherDataForKey(key)), None)
        plot_config = PlotConfig(key)
        self.applyCustomization(plot_config)
        return PlotContext(self.__ert, figure, plot_config, cases, key, data_gatherer)

    def getSelectedKey(self):
        key = str(self.__data_type_keys_widget.getSelectedItem())
        return key

    def addPlotWidget(self, name, plotFunction, data_gatherers, enabled=True):
        plot_condition_function_list = [data_gatherer.canGatherDataForKey for data_gatherer in data_gatherers]
        plot_widget = PlotWidget(name, plotFunction, plot_condition_function_list, self.createPlotContext)

        index = self.__central_tab.addTab(plot_widget, name)
        self.__plot_widgets.append(plot_widget)
        self.__central_tab.setTabEnabled(index, enabled)


    def addDock(self, name, widget, area=Qt.LeftDockWidgetArea, allowed_areas=Qt.AllDockWidgetAreas):
        dock_widget = QDockWidget(name)
        dock_widget.setObjectName("%sDock" % name)
        dock_widget.setWidget(widget)
        dock_widget.setAllowedAreas(allowed_areas)
        dock_widget.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable)

        self.addDockWidget(area, dock_widget)
        return dock_widget


    def applyCustomization(self, plot_config):
        custom = self.__customize_plot_widget.getCustomSettings()

        plot_config.setObservationsEnabled(custom["show_observations"])
        # plot_config.setRefcaseEnabled(custom["show_refcase"])
        plot_config.setLegendEnabled(custom["show_legend"])
        plot_config.setGridEnabled(custom["show_grid"])
        plot_config.setDistributionLineEnabled(custom["show_distribution_lines"])

        plot_config.setDefaultStyle(*custom["default_style"])
        plot_config.setRefcaseStyle(*custom["refcase_style"])

        plot_config.setStatisticsStyle("mean", *custom["mean_style"])
        plot_config.setStatisticsStyle("p50", *custom["p50_style"])
        plot_config.setStatisticsStyle("min-max", *custom["min-max_style"])
        plot_config.setStatisticsStyle("p10-p90", *custom["p10-p90_style"])
        plot_config.setStatisticsStyle("p33-p67", *custom["p33-p67_style"])


    @may_take_a_long_time
    def keySelected(self):
        key = self.getSelectedKey()

        for plot_widget in self.__plot_widgets:
            plot_widget.setDirty()
            index = self.__central_tab.indexOf(plot_widget)
            self.__central_tab.setTabEnabled(index, plot_widget.canPlotKey(key))

        for plot_widget in self.__plot_widgets:
            if plot_widget.canPlotKey(key):
                plot_widget.updatePlot()