def test_plot_config_history(self): ps = PlotSettings( ) test_pc = PlotConfig(ps , title = "test_1") history = PlotConfigHistory("test", test_pc) self.assertEqual(history.getPlotConfig().title(), test_pc.title()) self.assertNotEqual(history.getPlotConfig(), test_pc) self.assertFalse(history.isUndoPossible()) self.assertFalse(history.isRedoPossible()) history.applyChanges(PlotConfig(ps, title = "test_2")) self.assertTrue(history.isUndoPossible()) self.assertFalse(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_2") history.undoChanges() self.assertFalse(history.isUndoPossible()) self.assertTrue(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_1") history.redoChanges() self.assertTrue(history.isUndoPossible()) self.assertFalse(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_2") history.resetChanges() self.assertTrue(history.isUndoPossible()) self.assertFalse(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_1") history.undoChanges() self.assertTrue(history.isUndoPossible()) self.assertTrue(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_2")
def __init__(self, name, initial): super(PlotConfigHistory, self).__init__() self._name = name self._initial = PlotConfig.createCopy(initial) self._undo_history = [] self._redo_history = [] self._current = PlotConfig.createCopy(self._initial)
def createPlotContext(self, figure): key = self.getSelectedKey() cases = self._case_selection_widget.getPlotCaseNames() data_gatherer = self.getDataGathererForKey(key) plot_config = PlotConfig(key) plot_config.copyConfigFrom(self._plot_customizer.getPlotConfig()) return PlotContext(self._ert, figure, plot_config, cases, key, data_gatherer)
def test_plot_config_history(self): ps = PlotSettings() test_pc = PlotConfig(ps, title="test_1") history = PlotConfigHistory("test", test_pc) self.assertEqual(history.getPlotConfig().title(), test_pc.title()) self.assertNotEqual(history.getPlotConfig(), test_pc) self.assertFalse(history.isUndoPossible()) self.assertFalse(history.isRedoPossible()) history.applyChanges(PlotConfig(ps, title="test_2")) self.assertTrue(history.isUndoPossible()) self.assertFalse(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_2") history.undoChanges() self.assertFalse(history.isUndoPossible()) self.assertTrue(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_1") history.redoChanges() self.assertTrue(history.isUndoPossible()) self.assertFalse(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_2") history.resetChanges() self.assertTrue(history.isUndoPossible()) self.assertFalse(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_1") history.undoChanges() self.assertTrue(history.isUndoPossible()) self.assertTrue(history.isRedoPossible()) self.assertEqual(history.getPlotConfig().title(), "test_2")
def applyChanges(self, plot_config): """ @type plot_config: PlotConfig """ self._undo_history.append(self._current) copy = PlotConfig.createCopy(self._current) copy.copyConfigFrom(plot_config) self._current = copy del self._redo_history[:]
def applyChanges(self, plot_config): """@type plot_config: PlotConfig""" self._undo_history.append(self._current) copy = PlotConfig.createCopy(self._current) copy.copyConfigFrom(plot_config) self._current = copy del self._redo_history[:]
def __init__(self, parent): super(PlotCustomizer, self).__init__() self._plot_config_key = None self._previous_key = None self._plot_configs = {None: PlotConfigHistory("No_Key_Selected", PlotConfig(None))} self._plotConfigCreator = self._defaultPlotConfigCreator self._customization_dialog = CustomizePlotDialog("Customize", parent) self._customization_dialog.addTab("general", "General", DefaultCustomizationView()) self._customization_dialog.addTab("style", "Style", StyleCustomizationView()) self._customization_dialog.addTab("statistics", "Statistics", StatisticsCustomizationView()) self._customize_limits = LimitsCustomizationView() self._customization_dialog.addTab("limits", "Limits", self._customize_limits) self._customization_dialog.applySettings.connect(self.applyCustomization) self._customization_dialog.undoSettings.connect(self.undoCustomization) self._customization_dialog.redoSettings.connect(self.redoCustomization) self._customization_dialog.resetSettings.connect(self.resetCustomization) self._customization_dialog.copySettings.connect(self.copyCustomization) self._revertCustomization(self.getPlotConfig())
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)
def createPlotConfigForKey(cls, ert, key): """ @type ert: ert.enkf.enkf_main.EnKFMain @param key: str @return: PlotConfig """ plot_config = PlotConfig(key) return PlotConfigFactory.updatePlotConfigForKey(ert, key, plot_config)
def createPlotConfigForKey(cls, ert, key): """ @type ert: res.enkf.enkf_main.EnKFMain @param key: str @return: PlotConfig """ plot_config = PlotConfig(plot_settings=None, title=key) return PlotConfigFactory.updatePlotConfigForKey(ert, key, plot_config)
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 copyCustomizationTo(self, keys): """ copies the plotconfig of the current key, to a set of other keys""" history = self._getPlotConfigHistory() for key in keys: if key not in self._plot_configs: self._plot_configs[key] = PlotConfigHistory("No_Key_Selected", PlotConfig(self.default_plot_settings, title=None)) source_config = history.getPlotConfig() source_config.setTitle(key) self._plot_configs[key].applyChanges(source_config) self._customization_dialog.addCopyableKey(key) self._emitChangedSignal(emit=True)
def __createPlotContext(cls, shell_context, data_gatherer, key): """ :type shell_context: ShellContext :param data_gatherer: PlotDataGatherer :param key: str """ figure = plt.figure() figure.set_tight_layout(True) cases = shell_context["plot_settings"].getCurrentPlotCases() plot_config = PlotConfig(key) plot_config.copyConfigFrom(shell_context["plot_settings"].plotConfig()) if plot_config.isUnnamed(): plot_config.setTitle(key) plot_context = PlotContext(shell_context.ert(), figure, plot_config, cases, key, data_gatherer) return plot_context
def _createPlotContext(cls, shell_context, data_gatherer, key): """ :type shell_context: ShellContext :param data_gatherer: PlotDataGatherer :param key: str """ figure = plt.figure() figure.set_tight_layout(True) cases = shell_context["plot_settings"].getCurrentPlotCases() plot_config = PlotConfig(key) #plot settings should keep of track of single attributes and only apply the changed ones... plot_config.copyConfigFrom(shell_context["plot_settings"].plotConfig()) if plot_config.isUnnamed(): plot_config.setTitle(key) #Apply data type specific changes for statistics... PlotConfigFactory.updatePlotConfigForKey(shell_context.ert(), key, plot_config) plot_context = PlotContext(shell_context.ert(), figure, plot_config, cases, key, data_gatherer) return plot_context
def test_plot_config(self): ps = PlotSettings() plot_config = PlotConfig(ps, "Golden Sample", x_label="x", y_label="y") limits = PlotLimits() limits.count_limits = 1, 2 limits.depth_limits = 3, 4 limits.density_limits = 5, 6 limits.date_limits = datetime.date(2005, 2, 5), datetime.date(2006, 2, 6) limits.index_limits = 7, 8 limits.value_limits = 9.0, 10.0 plot_config.limits = limits self.assertEqual(plot_config.limits, limits) plot_config.setDistributionLineEnabled(True) plot_config.setLegendEnabled(False) plot_config.setGridEnabled(False) plot_config.setRefcaseEnabled(False) plot_config.setObservationsEnabled(False) style = PlotStyle("test_style", line_style=".", marker="g", width=2.5, size=7.5) plot_config.setDefaultStyle(style) plot_config.setRefcaseStyle(style) plot_config.setStatisticsStyle("mean", style) plot_config.setStatisticsStyle("min-max", style) plot_config.setStatisticsStyle("p50", style) plot_config.setStatisticsStyle("p10-p90", style) plot_config.setStatisticsStyle("p33-p67", style) plot_config.setStatisticsStyle("std", style) copy_of_plot_config = PlotConfig(ps, "Copy of Golden Sample") copy_of_plot_config.copyConfigFrom(plot_config) self.assertEqual(plot_config.isLegendEnabled(), copy_of_plot_config.isLegendEnabled()) self.assertEqual(plot_config.isGridEnabled(), copy_of_plot_config.isGridEnabled()) self.assertEqual(plot_config.isObservationsEnabled(), copy_of_plot_config.isObservationsEnabled()) self.assertEqual(plot_config.isDistributionLineEnabled(), copy_of_plot_config.isDistributionLineEnabled()) self.assertEqual(plot_config.refcaseStyle(), copy_of_plot_config.refcaseStyle()) self.assertEqual(plot_config.observationsStyle(), copy_of_plot_config.observationsStyle()) self.assertEqual(plot_config.histogramStyle(), copy_of_plot_config.histogramStyle()) self.assertEqual(plot_config.defaultStyle(), copy_of_plot_config.defaultStyle()) self.assertEqual(plot_config.currentColor(), copy_of_plot_config.currentColor()) self.assertEqual(plot_config.getStatisticsStyle("mean"), copy_of_plot_config.getStatisticsStyle("mean")) self.assertEqual(plot_config.getStatisticsStyle("min-max"), copy_of_plot_config.getStatisticsStyle("min-max")) self.assertEqual(plot_config.getStatisticsStyle("p50"), copy_of_plot_config.getStatisticsStyle("p50")) self.assertEqual(plot_config.getStatisticsStyle("p10-p90"), copy_of_plot_config.getStatisticsStyle("p10-p90")) self.assertEqual(plot_config.getStatisticsStyle("p33-p67"), copy_of_plot_config.getStatisticsStyle("p33-p67")) self.assertEqual(plot_config.getStatisticsStyle("std"), copy_of_plot_config.getStatisticsStyle("std")) self.assertEqual(plot_config.title(), copy_of_plot_config.title()) self.assertEqual(plot_config.limits, copy_of_plot_config.limits) plot_config.currentColor() # cycle state will not be copied plot_config.nextColor() copy_of_plot_config = PlotConfig(ps, "Another Copy of Golden Sample") copy_of_plot_config.copyConfigFrom(plot_config) self.assertEqual(plot_config.refcaseStyle(), copy_of_plot_config.refcaseStyle()) self.assertEqual(plot_config.observationsStyle(), copy_of_plot_config.observationsStyle()) self.assertNotEqual(plot_config.histogramStyle(), copy_of_plot_config.histogramStyle()) self.assertNotEqual(plot_config.defaultStyle(), copy_of_plot_config.defaultStyle()) self.assertNotEqual(plot_config.currentColor(), copy_of_plot_config.currentColor()) self.assertNotEqual(plot_config.getStatisticsStyle("mean"), copy_of_plot_config.getStatisticsStyle("mean")) self.assertNotEqual(plot_config.getStatisticsStyle("min-max"), copy_of_plot_config.getStatisticsStyle("min-max")) self.assertNotEqual(plot_config.getStatisticsStyle("p50"), copy_of_plot_config.getStatisticsStyle("p50")) self.assertNotEqual(plot_config.getStatisticsStyle("p10-p90"), copy_of_plot_config.getStatisticsStyle("p10-p90")) self.assertNotEqual(plot_config.getStatisticsStyle("p33-p67"), copy_of_plot_config.getStatisticsStyle("p33-p67")) self.assertNotEqual(plot_config.getStatisticsStyle("std"), copy_of_plot_config.getStatisticsStyle("std"))
def getPlotConfig(self): """@rtype: PlotConfig""" return PlotConfig.createCopy(self._current)
def test_plot_config(self): ps = PlotSettings( ) plot_config = PlotConfig(ps , "Golden Sample", x_label="x", y_label="y") limits = PlotLimits() limits.count_limits = 1, 2 limits.depth_limits = 3, 4 limits.density_limits = 5, 6 limits.date_limits = datetime.date(2005, 2, 5), datetime.date(2006, 2, 6) limits.index_limits = 7, 8 limits.value_limits = 9.0, 10.0 plot_config.limits = limits self.assertEqual(plot_config.limits, limits) plot_config.setDistributionLineEnabled(True) plot_config.setLegendEnabled(False) plot_config.setGridEnabled(False) plot_config.setRefcaseEnabled(False) plot_config.setObservationsEnabled(False) style = PlotStyle("test_style", line_style=".", marker="g", width=2.5, size=7.5) plot_config.setDefaultStyle(style) plot_config.setRefcaseStyle(style) plot_config.setStatisticsStyle("mean", style) plot_config.setStatisticsStyle("min-max", style) plot_config.setStatisticsStyle("p50", style) plot_config.setStatisticsStyle("p10-p90", style) plot_config.setStatisticsStyle("p33-p67", style) plot_config.setStatisticsStyle("std", style) copy_of_plot_config = PlotConfig(ps , "Copy of Golden Sample") copy_of_plot_config.copyConfigFrom(plot_config) self.assertEqual(plot_config.isLegendEnabled(), copy_of_plot_config.isLegendEnabled()) self.assertEqual(plot_config.isGridEnabled(), copy_of_plot_config.isGridEnabled()) self.assertEqual(plot_config.isObservationsEnabled(), copy_of_plot_config.isObservationsEnabled()) self.assertEqual(plot_config.isDistributionLineEnabled(), copy_of_plot_config.isDistributionLineEnabled()) self.assertEqual(plot_config.refcaseStyle(), copy_of_plot_config.refcaseStyle()) self.assertEqual(plot_config.observationsStyle(), copy_of_plot_config.observationsStyle()) self.assertEqual(plot_config.histogramStyle(), copy_of_plot_config.histogramStyle()) self.assertEqual(plot_config.defaultStyle(), copy_of_plot_config.defaultStyle()) self.assertEqual(plot_config.currentColor(), copy_of_plot_config.currentColor()) self.assertEqual(plot_config.getStatisticsStyle("mean"), copy_of_plot_config.getStatisticsStyle("mean")) self.assertEqual(plot_config.getStatisticsStyle("min-max"), copy_of_plot_config.getStatisticsStyle("min-max")) self.assertEqual(plot_config.getStatisticsStyle("p50"), copy_of_plot_config.getStatisticsStyle("p50")) self.assertEqual(plot_config.getStatisticsStyle("p10-p90"), copy_of_plot_config.getStatisticsStyle("p10-p90")) self.assertEqual(plot_config.getStatisticsStyle("p33-p67"), copy_of_plot_config.getStatisticsStyle("p33-p67")) self.assertEqual(plot_config.getStatisticsStyle("std"), copy_of_plot_config.getStatisticsStyle("std")) self.assertEqual(plot_config.title(), copy_of_plot_config.title()) self.assertEqual(plot_config.limits, copy_of_plot_config.limits) plot_config.currentColor() # cycle state will not be copied plot_config.nextColor() copy_of_plot_config = PlotConfig(ps, "Another Copy of Golden Sample") copy_of_plot_config.copyConfigFrom(plot_config) self.assertEqual(plot_config.refcaseStyle(), copy_of_plot_config.refcaseStyle()) self.assertEqual(plot_config.observationsStyle(), copy_of_plot_config.observationsStyle()) self.assertNotEqual(plot_config.histogramStyle(), copy_of_plot_config.histogramStyle()) self.assertNotEqual(plot_config.defaultStyle(), copy_of_plot_config.defaultStyle()) self.assertNotEqual(plot_config.currentColor(), copy_of_plot_config.currentColor()) self.assertNotEqual(plot_config.getStatisticsStyle("mean"), copy_of_plot_config.getStatisticsStyle("mean")) self.assertNotEqual(plot_config.getStatisticsStyle("min-max"), copy_of_plot_config.getStatisticsStyle("min-max")) self.assertNotEqual(plot_config.getStatisticsStyle("p50"), copy_of_plot_config.getStatisticsStyle("p50")) self.assertNotEqual(plot_config.getStatisticsStyle("p10-p90"), copy_of_plot_config.getStatisticsStyle("p10-p90")) self.assertNotEqual(plot_config.getStatisticsStyle("p33-p67"), copy_of_plot_config.getStatisticsStyle("p33-p67")) self.assertNotEqual(plot_config.getStatisticsStyle("std"), copy_of_plot_config.getStatisticsStyle("std"))
def createPlotConfigForKey(cls, key_def): """ @param key_def: dict with definition of a key @return: PlotConfig """ plot_config = PlotConfig(plot_settings=None, title=key_def["key"]) # The styling of statistics changes based on the nature of the data if key_def["dimensionality"] == 2: mean_style = plot_config.getStatisticsStyle("mean") mean_style.line_style = "-" plot_config.setStatisticsStyle("mean", mean_style) p10p90_style = plot_config.getStatisticsStyle("p10-p90") p10p90_style.line_style = "--" plot_config.setStatisticsStyle("p10-p90", p10p90_style) elif key_def["dimensionality"] == 1: mean_style = plot_config.getStatisticsStyle("mean") mean_style.line_style = "-" mean_style.marker = "o" plot_config.setStatisticsStyle("mean", mean_style) std_style = plot_config.getStatisticsStyle("std") std_style.line_style = "--" std_style.marker = "D" plot_config.setStatisticsStyle("std", std_style) return plot_config
def _defaultPlotConfigCreator(self, title): return PlotConfig(title)
def getPlotConfig(self): """ @rtype: PlotConfig """ return PlotConfig.createCopy(self._current)
def test_plot_config(self): plot_config = PlotConfig("Golden Sample", x_label="x", y_label="y") plot_config.setDistributionLineEnabled(True) plot_config.setLegendEnabled(False) plot_config.setGridEnabled(False) plot_config.setRefcaseEnabled(False) plot_config.setObservationsEnabled(False) plot_config.deactivateDateSupport() plot_config.setDefaultStyle(".", "g") plot_config.setRefcaseStyle(".", "g") plot_config.setStatisticsStyle("mean", ".", "g") plot_config.setStatisticsStyle("min-max", ".", "g") plot_config.setStatisticsStyle("p50", ".", "g") plot_config.setStatisticsStyle("p10-p90", ".", "g") plot_config.setStatisticsStyle("p33-p67", ".", "g") copy_of_plot_config = PlotConfig("Copy of Golden Sample") copy_of_plot_config.copyConfigFrom(plot_config) self.assertEqual(plot_config.isLegendEnabled(), copy_of_plot_config.isLegendEnabled()) self.assertEqual(plot_config.isGridEnabled(), copy_of_plot_config.isGridEnabled()) self.assertEqual(plot_config.isObservationsEnabled(), copy_of_plot_config.isObservationsEnabled()) self.assertEqual(plot_config.isDistributionLineEnabled(), copy_of_plot_config.isDistributionLineEnabled()) self.assertEqual(plot_config.isDateSupportActive(), copy_of_plot_config.isDateSupportActive()) self.assertEqual(plot_config.refcaseStyle(), copy_of_plot_config.refcaseStyle()) self.assertEqual(plot_config.observationsStyle(), copy_of_plot_config.observationsStyle()) self.assertEqual(plot_config.histogramStyle(), copy_of_plot_config.histogramStyle()) self.assertEqual(plot_config.defaultStyle(), copy_of_plot_config.defaultStyle()) self.assertEqual(plot_config.currentColor(), copy_of_plot_config.currentColor()) self.assertEqual(plot_config.getStatisticsStyle("mean"), copy_of_plot_config.getStatisticsStyle("mean")) self.assertEqual(plot_config.getStatisticsStyle("min-max"), copy_of_plot_config.getStatisticsStyle("min-max")) self.assertEqual(plot_config.getStatisticsStyle("p50"), copy_of_plot_config.getStatisticsStyle("p50")) self.assertEqual(plot_config.getStatisticsStyle("p10-p90"), copy_of_plot_config.getStatisticsStyle("p10-p90")) self.assertEqual(plot_config.getStatisticsStyle("p33-p67"), copy_of_plot_config.getStatisticsStyle("p33-p67")) self.assertEqual(plot_config.title(), copy_of_plot_config.title()) plot_config.currentColor() # cycle state will not be copied plot_config.nextColor() copy_of_plot_config = PlotConfig("Another Copy of Golden Sample") copy_of_plot_config.copyConfigFrom(plot_config) self.assertEqual(plot_config.refcaseStyle(), copy_of_plot_config.refcaseStyle()) self.assertEqual(plot_config.observationsStyle(), copy_of_plot_config.observationsStyle()) self.assertNotEqual(plot_config.histogramStyle(), copy_of_plot_config.histogramStyle()) self.assertNotEqual(plot_config.defaultStyle(), copy_of_plot_config.defaultStyle()) self.assertNotEqual(plot_config.currentColor(), copy_of_plot_config.currentColor()) self.assertNotEqual(plot_config.getStatisticsStyle("mean"), copy_of_plot_config.getStatisticsStyle("mean")) self.assertNotEqual(plot_config.getStatisticsStyle("min-max"), copy_of_plot_config.getStatisticsStyle("min-max")) self.assertNotEqual(plot_config.getStatisticsStyle("p50"), copy_of_plot_config.getStatisticsStyle("p50")) self.assertNotEqual(plot_config.getStatisticsStyle("p10-p90"), copy_of_plot_config.getStatisticsStyle("p10-p90")) self.assertNotEqual(plot_config.getStatisticsStyle("p33-p67"), copy_of_plot_config.getStatisticsStyle("p33-p67"))