Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Fix bug where last summary obs was not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide authored and markusdregi committed Jul 2, 2021
1 parent 826dfdf commit a5d0d1e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
4 changes: 2 additions & 2 deletions python/res/enkf/export/summary_observation_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
48 changes: 47 additions & 1 deletion tests/res/enkf/export/test_summary_observation_collector.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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()
)

0 comments on commit a5d0d1e

Please sign in to comment.