-
Notifications
You must be signed in to change notification settings - Fork 139
Add options for statistics to sidebar #14040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,10 @@ | |
|
|
||
| from .plot_color_palettes import TABLEAU_10_COLOR_CYCLE | ||
| from .plot_style import PlotStyle | ||
| from .statistics_style import ( | ||
| BAND_AREA_STYLE, | ||
| STATISTICS, | ||
| ) | ||
|
|
||
|
|
||
| class PlotConfig: | ||
|
|
@@ -63,39 +67,28 @@ def __init__( | |
| self._grid_enabled = True | ||
|
|
||
| self._statistics_style = { | ||
| "mean": PlotStyle("Mean", line_style=""), | ||
| "p50": PlotStyle("P50", line_style=""), | ||
| "min-max": PlotStyle("Min/Max", line_style=""), | ||
| "p10-p90": PlotStyle("P10-P90", line_style=""), | ||
| "p33-p67": PlotStyle("P33-P67", line_style=""), | ||
| "std": PlotStyle("Std dev", line_style=""), | ||
| statistic: PlotStyle(style.label, line_style="") | ||
| for statistic, style in STATISTICS.items() | ||
| } | ||
|
|
||
| self._std_dev_factor = 1 # sigma 1 is default std dev | ||
|
|
||
| self.flip_response_axis = False | ||
| self.flip_observation_axis = False | ||
|
|
||
| def set_statistics_styles_for_dimensionality(self, dimensionality: int) -> None: | ||
| mean_style = self._statistics_style["mean"] | ||
| p10p90_style = self._statistics_style["p10-p90"] | ||
| std_style = self._statistics_style["std"] | ||
|
|
||
| mean_style.line_style = "" | ||
| mean_style.marker = "" | ||
| p10p90_style.line_style = "" | ||
| p10p90_style.marker = "" | ||
| std_style.line_style = "" | ||
| std_style.marker = "" | ||
|
|
||
| if dimensionality == 2: | ||
| mean_style.line_style = "-" | ||
| p10p90_style.line_style = "--" | ||
| elif dimensionality == 1: | ||
| mean_style.line_style = "-" | ||
| mean_style.marker = "o" | ||
| std_style.line_style = "--" | ||
| std_style.marker = "D" | ||
| def set_statistics_options( | ||
| self, | ||
| enabled_statistics: set[str], | ||
| *, | ||
| fill_bands: bool, | ||
| ) -> None: | ||
| for statistic, style in self._statistics_style.items(): | ||
| if statistic not in enabled_statistics: | ||
| style.line_style = "" | ||
| elif fill_bands and STATISTICS[statistic].is_band: | ||
| style.line_style = BAND_AREA_STYLE | ||
| else: | ||
| style.line_style = STATISTICS[statistic].line_style | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the section I meant why we couldn't use |
||
|
|
||
| def get_number_of_colors(self) -> int: | ||
| return len(self._line_color_cycle_colors) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import NamedTuple | ||
|
|
||
|
|
||
| class StatisticStyle(NamedTuple): | ||
| label: str | ||
| line_style: str | ||
| is_band: bool | ||
|
|
||
|
|
||
| STATISTICS = { | ||
| "mean": StatisticStyle("Mean", "-", is_band=False), | ||
| "p50": StatisticStyle("P50", "--", is_band=False), | ||
| "std": StatisticStyle("Std dev", ":", is_band=True), | ||
| "min-max": StatisticStyle("Min/Max", ":", is_band=True), | ||
| "p10-p90": StatisticStyle("P10-P90", "--", is_band=True), | ||
| "p33-p67": StatisticStyle("P33-P67", "-.", is_band=True), | ||
| } | ||
|
|
||
| BAND_AREA_STYLE = "#" | ||
|
|
||
| DEFAULT_ENABLED_STATISTICS = {"mean", "p10-p90"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/ert/gui/plotting/widgets/plot_controls/statistics_options.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from collections.abc import Callable | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from PyQt6.QtWidgets import QGroupBox | ||
|
|
||
| from ert.gui.plotting.utils.qt_creator import ( | ||
| create_checkbox_with_tooltip, | ||
| create_group_box, | ||
| create_group_layout, | ||
| create_labeled_row, | ||
| create_spinbox_with_tooltip, | ||
| ) | ||
| from ert.gui.plotting.utils.statistics_style import ( | ||
| DEFAULT_ENABLED_STATISTICS, | ||
| STATISTICS, | ||
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ert.gui.plotting.utils import PlotConfig | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class StatisticsOptions: | ||
| """Owns the statistics selection, which persists across keys.""" | ||
|
|
||
| def __init__(self, connection_point: Callable[..., object]) -> None: | ||
| self._toggles = { | ||
| statistic: create_checkbox_with_tooltip( | ||
| style.label, | ||
| f"Show or hide the {style.label} " | ||
| + ("band" if style.is_band else "line"), | ||
| connection_point, | ||
| initial_checked=statistic in DEFAULT_ENABLED_STATISTICS, | ||
| logger=logger, | ||
| ) | ||
| for statistic, style in STATISTICS.items() | ||
| } | ||
| self._area_toggle = create_checkbox_with_tooltip( | ||
| "Area", | ||
| "Draw the standard deviation, min/max and percentile ranges as a " | ||
| "filled area instead of a pair of lines", | ||
| connection_point, | ||
| initial_checked=False, | ||
| logger=logger, | ||
| ) | ||
| self._std_dev_factor = create_spinbox_with_tooltip( | ||
| "Std dev multiplier", | ||
| "Choose the number of standard deviations to plot", | ||
| connection_point, | ||
| minimum=1, | ||
| maximum=3, | ||
| initial_value=1, | ||
| logger=logger, | ||
| ) | ||
|
|
||
| self._statistics_options = create_group_box( | ||
| "Statistics options", | ||
| create_group_layout( | ||
| [ | ||
| *self._toggles.values(), | ||
| self._area_toggle, | ||
| create_labeled_row("Std dev multiplier", self._std_dev_factor), | ||
| ] | ||
| ), | ||
| ) | ||
|
|
||
| def apply_to(self, plot_config: PlotConfig) -> None: | ||
| plot_config.set_standard_deviation_factor(self._std_dev_factor.value()) | ||
| plot_config.set_statistics_options( | ||
| self._enabled_statistics(), | ||
| fill_bands=self._area_toggle.isChecked(), | ||
| ) | ||
|
|
||
| def _enabled_statistics(self) -> set[str]: | ||
| return { | ||
| statistic | ||
| for statistic, checkbox in self._toggles.items() | ||
| if checkbox.isChecked() | ||
| } | ||
|
|
||
| def get_widget(self) -> QGroupBox: | ||
| return self._statistics_options |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed? could we not in line 85 just do:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's shorthand for:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant more, why do we need self._statistics_style = {}, could we not just use STATISTICS.items()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
statistics_style are the mutable style elements in the config file which is changed by the options.
STATISTICS.items() are just the defaults styles and the rules.
At least the line styles are changed with the band option. On/off switches as well.