Skip to content

Commit 9dbe19d

Browse files
committed
Decouple statistics styling from dimensionality
Statistics styles were derived from the plot dimensionality, but they are only read by the statistics plotter, which is always dimensionality 2. The remaining branches were dead code. Replace the coupling with an explicit selection of which statistics to draw. This also simplifies statistics styling in general: each statistic has a fixed style and is only turned on or off. The default selection reproduces the previous appearance.
1 parent 91d37b4 commit 9dbe19d

4 files changed

Lines changed: 78 additions & 53 deletions

File tree

src/ert/gui/plotting/plot_window.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from .utils.plot_color_palettes import TABLEAU_10_COLOR_CYCLE
5959
from .utils.plot_types import ObservationPlotLocations
6060
from .utils.qt_creator import create_group_box, create_group_layout, create_side_panel
61+
from .utils.statistics_style import DEFAULT_ENABLED_STATISTICS
6162
from .widgets.data_type_keys_widget import DataTypeKeysWidget
6263
from .widgets.everest_control_selection_widget import EverestControlSelectionWidget
6364
from .widgets.plot_controls import (
@@ -538,13 +539,13 @@ def fetch_data(
538539
handle_exception(e)
539540

540541
plot_config = PlotConfig(title=key_def.key)
541-
if selected_tab == STATISTICS:
542-
plot_config.set_statistics_styles_for_dimensionality(
543-
key_def.dimensionality
544-
)
545542
plot_config.set_title(self._titles.get(key_def.key, key_def.key))
546543
plot_config.set_x_label(self._x_labels.get(key_def.key))
547544
plot_config.set_y_label(self._y_labels.get(key_def.key))
545+
if selected_tab == STATISTICS:
546+
plot_config.set_statistics_options(
547+
DEFAULT_ENABLED_STATISTICS, fill_bands=False
548+
)
548549
plot_config.set_legend_enabled(self._general_options.legend_checkbox_state)
549550
plot_config.set_grid_enabled(self._general_options.grid_checkbox_state)
550551
plot_config.set_line_color_cycle(self._general_options.get_color_cycle())

src/ert/gui/plotting/utils/plot_config.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
from .plot_color_palettes import TABLEAU_10_COLOR_CYCLE
77
from .plot_style import PlotStyle
8+
from .statistics_style import (
9+
BAND_AREA_STYLE,
10+
BAND_STATISTICS,
11+
STATISTIC_LABELS,
12+
STATISTICS_LINE_STYLES,
13+
)
814

915

1016
class PlotConfig:
@@ -63,39 +69,28 @@ def __init__(
6369
self._grid_enabled = True
6470

6571
self._statistics_style = {
66-
"mean": PlotStyle("Mean", line_style=""),
67-
"p50": PlotStyle("P50", line_style=""),
68-
"min-max": PlotStyle("Min/Max", line_style=""),
69-
"p10-p90": PlotStyle("P10-P90", line_style=""),
70-
"p33-p67": PlotStyle("P33-P67", line_style=""),
71-
"std": PlotStyle("Std dev", line_style=""),
72+
statistic: PlotStyle(label, line_style="")
73+
for statistic, label in STATISTIC_LABELS.items()
7274
}
7375

7476
self._std_dev_factor = 1 # sigma 1 is default std dev
7577

7678
self.flip_response_axis = False
7779
self.flip_observation_axis = False
7880

79-
def set_statistics_styles_for_dimensionality(self, dimensionality: int) -> None:
80-
mean_style = self._statistics_style["mean"]
81-
p10p90_style = self._statistics_style["p10-p90"]
82-
std_style = self._statistics_style["std"]
83-
84-
mean_style.line_style = ""
85-
mean_style.marker = ""
86-
p10p90_style.line_style = ""
87-
p10p90_style.marker = ""
88-
std_style.line_style = ""
89-
std_style.marker = ""
90-
91-
if dimensionality == 2:
92-
mean_style.line_style = "-"
93-
p10p90_style.line_style = "--"
94-
elif dimensionality == 1:
95-
mean_style.line_style = "-"
96-
mean_style.marker = "o"
97-
std_style.line_style = "--"
98-
std_style.marker = "D"
81+
def set_statistics_options(
82+
self,
83+
enabled_statistics: set[str],
84+
*,
85+
fill_bands: bool,
86+
) -> None:
87+
for statistic, style in self._statistics_style.items():
88+
if statistic not in enabled_statistics:
89+
style.line_style = ""
90+
elif fill_bands and statistic in BAND_STATISTICS:
91+
style.line_style = BAND_AREA_STYLE
92+
else:
93+
style.line_style = STATISTICS_LINE_STYLES[statistic]
9994

10095
def get_number_of_colors(self) -> int:
10196
return len(self._line_color_cycle_colors)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import annotations
2+
3+
STATISTIC_LABELS = {
4+
"mean": "Mean",
5+
"p50": "P50",
6+
"std": "Std dev",
7+
"min-max": "Min/Max",
8+
"p10-p90": "P10-P90",
9+
"p33-p67": "P33-P67",
10+
}
11+
12+
BAND_STATISTICS = {"std", "min-max", "p10-p90", "p33-p67"}
13+
14+
BAND_AREA_STYLE = "#"
15+
16+
# Line style each statistic is drawn with while enabled.
17+
STATISTICS_LINE_STYLES = {
18+
"mean": "-",
19+
"p50": "--",
20+
"std": "--",
21+
"min-max": "--",
22+
"p10-p90": "--",
23+
"p33-p67": "--",
24+
}
25+
26+
DEFAULT_ENABLED_STATISTICS = {"mean", "p10-p90"}

tests/ert/unit_tests/gui/plottery/test_plot_style.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import math
22

3+
import pytest
4+
35
from ert.gui.plotting.utils import PlotConfig, PlotStyle
46
from ert.gui.plotting.utils.plot_tools import ConditionalAxisFormatter
7+
from ert.gui.plotting.utils.statistics_style import STATISTIC_LABELS
58

69

710
def test_conditional_axis_formatter():
@@ -205,39 +208,39 @@ def test_plot_config():
205208
) != copy_of_plot_config.get_statistics_style("std")
206209

207210

208-
def test_that_two_dimensional_keys_draw_mean_and_p10_p90_as_lines():
211+
def test_that_the_mean_is_drawn_solid_and_the_other_statistics_dashed():
212+
plot_config = PlotConfig()
213+
214+
plot_config.set_statistics_options({"mean", "p10-p90"}, fill_bands=False)
215+
216+
assert plot_config.get_statistics_style("mean").line_style == "-"
217+
assert plot_config.get_statistics_style("p10-p90").line_style == "--"
218+
219+
220+
def test_that_a_deselected_statistic_has_neither_line_style_nor_marker():
209221
plot_config = PlotConfig()
210-
plot_config.set_statistics_styles_for_dimensionality(1)
211222

212-
plot_config.set_statistics_styles_for_dimensionality(2)
223+
plot_config.set_statistics_options(set(), fill_bands=False)
213224

214225
mean_style = plot_config.get_statistics_style("mean")
215-
assert mean_style.line_style == "-"
226+
assert not mean_style.line_style
216227
assert not mean_style.marker
228+
assert not mean_style.is_visible()
217229

218-
p10p90_style = plot_config.get_statistics_style("p10-p90")
219-
assert p10p90_style.line_style == "--"
220-
assert not p10p90_style.marker
221230

222-
std_style = plot_config.get_statistics_style("std")
223-
assert not std_style.line_style
224-
assert not std_style.marker
231+
def test_that_filling_bands_draws_selected_band_statistics_as_areas():
232+
plot_config = PlotConfig()
225233

234+
plot_config.set_statistics_options({"mean", "p33-p67"}, fill_bands=True)
226235

227-
def test_that_one_dimensional_keys_draw_mean_and_std_with_markers():
228-
plot_config = PlotConfig()
229-
plot_config.set_statistics_styles_for_dimensionality(2)
236+
assert plot_config.get_statistics_style("p33-p67").line_style == "#"
237+
assert plot_config.get_statistics_style("mean").line_style == "-"
230238

231-
plot_config.set_statistics_styles_for_dimensionality(1)
232239

233-
mean_style = plot_config.get_statistics_style("mean")
234-
assert mean_style.line_style == "-"
235-
assert mean_style.marker == "o"
240+
@pytest.mark.parametrize("statistic", sorted(STATISTIC_LABELS))
241+
def test_that_every_statistic_is_visible_when_enabled(statistic):
242+
plot_config = PlotConfig()
236243

237-
std_style = plot_config.get_statistics_style("std")
238-
assert std_style.line_style == "--"
239-
assert std_style.marker == "D"
244+
plot_config.set_statistics_options({statistic}, fill_bands=False)
240245

241-
p10p90_style = plot_config.get_statistics_style("p10-p90")
242-
assert not p10p90_style.line_style
243-
assert not p10p90_style.marker
246+
assert plot_config.get_statistics_style(statistic).is_visible()

0 commit comments

Comments
 (0)