Skip to content

Commit

Permalink
Add filtering for History vectors in plotter
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Sep 11, 2024
1 parent 69eada0 commit 09a4236
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/ert/gui/tools/plot/data_type_proxy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ def filterAcceptsRow(self, source_row: int, source_parent: QModelIndex) -> bool:

for meta_key, values in self._metadata_filters.items():
for value, visible in values.items():
if (
not visible
and meta_key in key.metadata
and key.metadata[meta_key] == value
if not visible and (
(meta_key in key.metadata and key.metadata[meta_key] == value)
or (value == "History Vector" and key.history_vector)
):
show = False
return False

return show

Expand Down
5 changes: 4 additions & 1 deletion src/ert/gui/tools/plot/filter_popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ def __init__(
self.__layout.addWidget(QLabel("Filter by datatype:"))

filters = {k.metadata["data_origin"] for k in key_defs}
for f in filters:
for f in sorted(filters):
self.addFilterItem(f, f)

if any(k.history_vector for k in key_defs):
self.addFilterItem("History Vector", "History Vector")

frame.setLayout(self.__layout)

self.setLayout(layout)
Expand Down
8 changes: 8 additions & 0 deletions src/ert/gui/tools/plot/plot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ class EnsembleObject:
("dimensionality", int),
("metadata", Dict[Any, Any]),
("log_scale", bool),
("history_vector", bool),
],
)


def _is_history_vector(name: str) -> bool:
key = name.split(":")[0]
return key.endswith("H") and len(key) == 5


class PlotApi:
def __init__(self) -> None:
self._all_ensembles: Optional[List[EnsembleObject]] = None
Expand Down Expand Up @@ -130,6 +136,7 @@ def all_data_type_keys(self) -> List[PlotApiKeyDefinition]:
dimensionality=2,
metadata=value["userdata"],
log_scale=key.startswith("LOG10_"),
history_vector=_is_history_vector(key),
)

response = client.get(
Expand All @@ -145,6 +152,7 @@ def all_data_type_keys(self) -> List[PlotApiKeyDefinition]:
dimensionality=e["dimensionality"],
metadata=e["userdata"],
log_scale=key.startswith("LOG10_"),
history_vector=_is_history_vector(key),
)

return list(all_keys.values())
Expand Down
9 changes: 8 additions & 1 deletion tests/unit_tests/gui/plottery/test_plotting_of_snake_oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,21 @@ def test_that_all_plotter_filter_boxes_yield_expected_filter_results(

key_list = plot_window.findChild(DataTypeKeysWidget).data_type_keys_widget
item_count = [3, 10, 45]

assert key_list.model().rowCount() == sum(item_count)

cbs = plot_window.findChildren(QCheckBox, "FilterCheckBox")
history_filter = cbs[3]
cbs = cbs[0:3]

for i in range(len(item_count)):
for u, cb in enumerate(cbs):
cb.setChecked(i == u)

assert key_list.model().rowCount() in item_count

# test history vector filtering
assert key_list.model().rowCount() == 45
history_filter.setChecked(False)
assert key_list.model().rowCount() == 24

plot_window.close()
12 changes: 12 additions & 0 deletions tests/unit_tests/gui/tools/plot/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ def mocked_requests_get(*args, **kwargs):
"userdata": {"data_origin": "GEN_DATA"},
"has_observations": False,
},
"FOPRH": {
"name": "FOPRH",
"id": "id_997",
"userdata": {"data_origin": "Summary"},
"has_observations": True,
},
"FOPRH:1,3,8": {
"name": "FOPRH:1,3,8",
"id": "id_998",
"userdata": {"data_origin": "Summary"},
"has_observations": True,
},
},
"/ensembles/ens_id_3/responses": {
"BPR:1,3,8": {
Expand Down
29 changes: 29 additions & 0 deletions tests/unit_tests/gui/tools/plot/test_plot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def test_key_def_structure(api):
"metadata": {"data_origin": "Summary"},
"observations": True,
"log_scale": False,
"history_vector": False,
}
assert fopr == PlotApiKeyDefinition(**fopr_expected)

Expand All @@ -28,6 +29,7 @@ def test_key_def_structure(api):
"metadata": {"data_origin": "Summary"},
"observations": False,
"log_scale": False,
"history_vector": False,
}
assert bpr == PlotApiKeyDefinition(**bpr_expected)

Expand All @@ -41,9 +43,34 @@ def test_key_def_structure(api):
"metadata": {"data_origin": "GEN_KW"},
"observations": False,
"log_scale": False,
"history_vector": False,
}
assert bpr_parameter == PlotApiKeyDefinition(**bpr_parameter_expected)

foprh = next(x for x in key_defs if x.key == "FOPRH")
foprh_expected = {
"dimensionality": 2,
"index_type": "VALUE",
"key": "FOPRH",
"metadata": {"data_origin": "Summary"},
"observations": True,
"log_scale": False,
"history_vector": True,
}
assert foprh == PlotApiKeyDefinition(**foprh_expected)

foprh = next(x for x in key_defs if x.key == "FOPRH:1,3,8")
foprh_expected = {
"dimensionality": 2,
"index_type": "VALUE",
"key": "FOPRH:1,3,8",
"metadata": {"data_origin": "Summary"},
"observations": True,
"log_scale": False,
"history_vector": True,
}
assert foprh == PlotApiKeyDefinition(**foprh_expected)


def test_case_structure(api):
ensembles = [ensemble.name for ensemble in api.get_all_ensembles()]
Expand Down Expand Up @@ -90,6 +117,8 @@ def test_all_data_type_keys(api):
"BPR:1,3,8",
"FOPR",
"SNAKE_OIL_WPR_DIFF@199",
"FOPRH",
"FOPRH:1,3,8",
"SNAKE_OIL_PARAM:BPR_138_PERSISTENCE",
"SNAKE_OIL_PARAM:OP1_DIVERGENCE_SCALE",
"WOPPER",
Expand Down

0 comments on commit 09a4236

Please sign in to comment.