Skip to content
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

Handle empty ensemble in observations view #9554

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/ert/gui/tools/manage_experiments/storage_info_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,17 @@ def _filter_on_observation_label(df: polars.DataFrame) -> polars.DataFrame:
obs = _filter_on_observation_label(obs)

response_key = obs["response_key"].unique().to_list()[0]
response_ds = self._ensemble.load_responses(
response_key,
tuple(self._ensemble.get_realization_list_with_responses()),
reals_with_responses = tuple(
self._ensemble.get_realization_list_with_responses()
)

response_ds = (
self._ensemble.load_responses(
response_key,
reals_with_responses,
)
if reals_with_responses
else None
)

scaling_df = self._ensemble.load_observation_scaling_factors()
Expand Down Expand Up @@ -260,7 +268,7 @@ def _try_render_scaled_obs() -> None:
color="black",
)

if not response_ds.is_empty():
if response_ds is not None and not response_ds.is_empty():
response_ds_for_label = _filter_on_observation_label(response_ds).rename(
{"values": "Responses"}
)[["response_key", "Responses"]]
Expand Down
65 changes: 64 additions & 1 deletion tests/ert/ui_tests/gui/test_manage_experiments_tool.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import datetime
import shutil

import polars
import pytest
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QPushButton, QTextEdit

from ert.config import ErtConfig
from ert.config import ErtConfig, SummaryConfig
from ert.gui.ertnotifier import ErtNotifier
from ert.gui.tools.manage_experiments import ManageExperimentsPanel
from ert.gui.tools.manage_experiments.storage_info_widget import (
Expand Down Expand Up @@ -343,6 +345,67 @@ def _evaluate(coeffs, x):
)


@pytest.mark.usefixtures("copy_poly_case")
def test_ensemble_observations_view_on_empty_ensemble(qtbot):
config = ErtConfig.from_file("poly.ert")
notifier = ErtNotifier(config.config_path)
with open_storage(config.ens_path, mode="w") as storage:
notifier.set_storage(storage)
storage.create_experiment(
responses=[SummaryConfig(keys=["*"])],
observations={
"summary": polars.DataFrame(
polars.DataFrame(
{
"response_key": ["FOPR"],
"observation_key": ["O4"],
"time": polars.Series(
[datetime.datetime(2000, 1, 1)],
dtype=polars.Datetime("ms"),
),
"observations": polars.Series([10.2], dtype=polars.Float32),
"std": polars.Series([0.1], dtype=polars.Float32),
}
)
),
},
).create_ensemble(
name="test", ensemble_size=config.model_config.num_realizations
)

tool = ManageExperimentsPanel(
config, notifier, config.model_config.num_realizations
)

# select the ensemble
storage_widget = tool.findChild(StorageWidget)
storage_widget._tree_view.expandAll()
eivindjahren marked this conversation as resolved.
Show resolved Hide resolved
model_index = storage_widget._tree_view.model().index(
0, 0, storage_widget._tree_view.model().index(0, 0)
)
storage_widget._tree_view.setCurrentIndex(model_index)
assert (
tool._storage_info_widget._content_layout.currentIndex()
== _WidgetType.ENSEMBLE_WIDGET
)

ensemble_widget = tool._storage_info_widget._content_layout.currentWidget()
assert isinstance(ensemble_widget, _EnsembleWidget)
assert ensemble_widget._name_label.text()
assert ensemble_widget._uuid_label.text()
assert not ensemble_widget._state_text_edit.toPlainText()

ensemble_widget._tab_widget.setCurrentIndex(_EnsembleWidgetTabs.STATE_TAB)
assert ensemble_widget._state_text_edit.toPlainText()

ensemble_widget._tab_widget.setCurrentIndex(
_EnsembleWidgetTabs.OBSERVATIONS_TAB
)

# Expect only one figure, the one for the observation
assert len(ensemble_widget._figure.get_axes()) == 1


def test_realization_view(
qtbot, snake_oil_case_storage: ErtConfig, snake_oil_storage: Storage
):
Expand Down
Loading