From 1aa0069fe8a8b2a3f26e242f6ccb259de252c04d Mon Sep 17 00:00:00 2001 From: Feda Curic Date: Mon, 25 Sep 2023 13:55:20 +0200 Subject: [PATCH 1/2] Get measured data using active realizations This bug caused misfit_preprocessor to fail on cases with failed realizations. (cherry picked from commit 0b8b74aeeff1bab89915126575e7a05325f77d24) --- src/ert/data/_measured_data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ert/data/_measured_data.py b/src/ert/data/_measured_data.py index d4db19ce067..9d80b226609 100644 --- a/src/ert/data/_measured_data.py +++ b/src/ert/data/_measured_data.py @@ -13,6 +13,8 @@ import numpy as np import pandas as pd +from ert.realization_state import RealizationState + if TYPE_CHECKING: import numpy.typing as npt @@ -103,7 +105,7 @@ def _get_data( group, obs = observations.get_dataset(key) try: response = ensemble.load_response( - group, tuple(range(self._facade.get_ensemble_size())) + group, tuple(ensemble.realization_list(RealizationState.HAS_DATA)) ) except KeyError: raise ResponseError(f"No response loaded for observation key: {key}") From e3e6551c4dc0a4370a93cae338f187aeec88399d Mon Sep 17 00:00:00 2001 From: Feda Curic Date: Mon, 25 Sep 2023 14:24:53 +0200 Subject: [PATCH 2/2] Test that measured data work with failed reals This caused the misfit preprocessor to fail when run on cases that have failed realizations. (cherry picked from commit b756ebabc1b4fbdd118f444ba7a17bc42272f974) --- src/ert/data/_measured_data.py | 7 +++++-- tests/unit_tests/gui/test_full_manual_update_workflow.py | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ert/data/_measured_data.py b/src/ert/data/_measured_data.py index 9d80b226609..eb4afdc27c5 100644 --- a/src/ert/data/_measured_data.py +++ b/src/ert/data/_measured_data.py @@ -107,8 +107,11 @@ def _get_data( response = ensemble.load_response( group, tuple(ensemble.realization_list(RealizationState.HAS_DATA)) ) - except KeyError: - raise ResponseError(f"No response loaded for observation key: {key}") + _msg = f"No response loaded for observation key: {key}" + if not response: + raise ResponseError(_msg) + except KeyError as e: + raise ResponseError(_msg) from e ds = obs.merge( response, join="left", diff --git a/tests/unit_tests/gui/test_full_manual_update_workflow.py b/tests/unit_tests/gui/test_full_manual_update_workflow.py index 8ed7c7a470f..1b8e9523e38 100644 --- a/tests/unit_tests/gui/test_full_manual_update_workflow.py +++ b/tests/unit_tests/gui/test_full_manual_update_workflow.py @@ -5,6 +5,7 @@ from qtpy.QtCore import Qt, QTimer from qtpy.QtWidgets import QApplication, QComboBox, QMessageBox, QPushButton, QWidget +from ert.data import MeasuredData from ert.gui.ertwidgets.caselist import CaseList from ert.gui.simulation.ensemble_experiment_panel import EnsembleExperimentPanel from ert.gui.simulation.run_dialog import RunDialog @@ -129,6 +130,9 @@ def handle_dialog(): df_prior = facade.load_all_gen_kw_data(storage.get_ensemble_by_name("iter-0")) df_posterior = facade.load_all_gen_kw_data(storage.get_ensemble_by_name("iter-1")) + # Making sure measured data works with failed realizations + MeasuredData(facade, storage.get_ensemble_by_name("iter-0"), ["POLY_OBS"]) + # We expect that ERT's update step lowers the # generalized variance for the parameters. assert (