diff --git a/python/res/enkf/export/summary_observation_collector.py b/python/res/enkf/export/summary_observation_collector.py index e47aea7e8..6e94d9b19 100644 --- a/python/res/enkf/export/summary_observation_collector.py +++ b/python/res/enkf/export/summary_observation_collector.py @@ -34,7 +34,7 @@ def loadObservationData(ert, case_name, keys=None): history_length = ert.getHistoryLength() dates = [ observations.getObservationTime(index).datetime() - for index in range(1, history_length) + for index in range(1, history_length + 1) ] summary_keys = SummaryObservationCollector.getAllObservationKeys(ert) if keys is not None: @@ -48,7 +48,7 @@ def loadObservationData(ert, case_name, keys=None): observation_keys = ert.ensembleConfig().getNode(key).getObservationKeys() for obs_key in observation_keys: observation_data = observations[obs_key] - for index in range(0, history_length): + for index in range(0, history_length + 1): if observation_data.isActive(index): obs_time = observations.getObservationTime(index).datetime() node = observation_data.getNode(index) diff --git a/tests/res/enkf/export/test_summary_observation_collector.py b/tests/res/enkf/export/test_summary_observation_collector.py index 051b8f604..0635c3b5d 100644 --- a/tests/res/enkf/export/test_summary_observation_collector.py +++ b/tests/res/enkf/export/test_summary_observation_collector.py @@ -1,8 +1,14 @@ +from pathlib import Path +import pytest +import shutil + +from res.enkf import ResConfig, EnKFMain +from tests.conftest import source_root import os from tests import ResTest from res.test import ErtTestContext from pytest import MonkeyPatch - +from ecl.summary import EclSum from res.enkf.export import SummaryObservationCollector @@ -57,3 +63,43 @@ def test_summary_observation_collector(self): with self.assertRaises(KeyError): data["FOPR"] + + +test_data_root = Path(source_root()) / "test-data" / "local" + + +@pytest.fixture() +def setup_snake_oil(tmpdir): + with tmpdir.as_cwd(): + test_data_dir = os.path.join(test_data_root, "snake_oil") + + shutil.copytree(test_data_dir, "test_data") + os.chdir("test_data") + + yield ResConfig("snake_oil.ert") + + +def test_summary_obs_last_entry(setup_snake_oil): + + obs_file = Path.cwd() / "observations" / "observations.txt" + with obs_file.open(mode="a") as fin: + fin.write( + """ + \nSUMMARY_OBSERVATION LAST_DATE +{ + VALUE = 0.01961757428944111; + ERROR = 0.1; + DATE = 23/06/2015; + KEY = FOPR; +}; + """ + ) + + ert = EnKFMain(setup_snake_oil) + + summary = EclSum("refcase/SNAKE_OIL_FIELD.UNSMRY") + data = SummaryObservationCollector.loadObservationData(ert, "default_0") + assert ( + data["FOPR"].values.tolist() + == summary.numpy_vector("FOPRH", report_only=True).tolist() + )