Skip to content

Commit 5a27fc3

Browse files
committed
Adjust to ert api change
Observations were required only for validation of keys.
1 parent 1e4a992 commit 5a27fc3

File tree

3 files changed

+83
-25
lines changed

3 files changed

+83
-25
lines changed

semeio/workflows/correlated_observations_scaling/obs_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def create_active_lists(enkf_observations, events):
6262
the active list where the scaling factor will be applied.
6363
"""
6464
new_events = []
65-
observation_data = LocalObsdata("some_name", enkf_observations)
65+
observation_data = LocalObsdata("some_name")
6666
for event in events:
67-
observation_data.addObsVector(enkf_observations[event.key])
67+
observation_data.addNode(event.key)
6868

6969
obs_index = _data_index_to_obs_index(enkf_observations, event.key, event.index)
7070
new_active_list = _get_active_list(observation_data, event.key, obs_index)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
],
5151
install_requires=[
5252
"ecl",
53-
"ert >= 2.31.0b0",
53+
"ert >= 2.34.0b0",
5454
"configsuite>=0.6",
5555
"numpy",
5656
"pandas>0.24,<1.4.0",

tests/jobs/correlated_observations_scaling/test_integration.py

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
from unittest.mock import MagicMock
1616

1717

18-
def assert_obs_vector(vector, val_1, index_list=None, val_2=None):
19-
if index_list is None:
20-
index_list = []
18+
def get_std_from_obs_vector(vector):
19+
result = []
2120
for node in vector:
22-
for index in range(len(node)):
23-
if index in index_list:
24-
assert node.getStdScaling(index) == val_2
25-
else:
26-
assert node.getStdScaling(index) == val_1
21+
for i, _ in enumerate(node):
22+
result.append(node.getStdScaling(i))
23+
return result
2724

2825

2926
def test_installed_python_version_of_enkf_scaling_job(setup_ert, monkeypatch):
@@ -41,7 +38,9 @@ def test_installed_python_version_of_enkf_scaling_job(setup_ert, monkeypatch):
4138
obs = ert.getObservations()
4239
obs_vector = obs["WPR_DIFF_1"]
4340

44-
assert_obs_vector(obs_vector, 1.0)
41+
result = get_std_from_obs_vector(obs_vector)
42+
43+
assert result == [1.0, 1.0, 1.0, 1.0]
4544

4645
job_config = {"CALCULATE_KEYS": {"keys": [{"key": "WPR_DIFF_1"}]}}
4746

@@ -56,19 +55,23 @@ def test_installed_python_version_of_enkf_scaling_job(setup_ert, monkeypatch):
5655
job = ert.getWorkflowList().getJob("CORRELATE_OBSERVATIONS_SCALING")
5756
job.run(ert, ["job_config.yml"])
5857

59-
assert_obs_vector(obs_vector, np.sqrt(4.0 / 2.0))
58+
result = get_std_from_obs_vector(obs_vector)
59+
assert result == [np.sqrt(4.0 / 2.0)] * 4
6060

6161
job_config["CALCULATE_KEYS"]["keys"][0].update({"index": [400, 800, 1200]})
6262
with open("job_config.yml", "w") as fout:
6363
yaml.dump(job_config, fout)
6464
job.run(ert, ["job_config.yml"])
6565

66-
assert_obs_vector(
66+
result = get_std_from_obs_vector(
6767
obs_vector,
68-
np.sqrt(4.0 / 2.0),
69-
index_list=[0, 1, 2],
70-
val_2=np.sqrt(3.0 / 2.0),
7168
)
69+
assert result == [
70+
np.sqrt(3.0 / 2.0),
71+
np.sqrt(3.0 / 2.0),
72+
np.sqrt(3.0 / 2.0),
73+
np.sqrt(4.0 / 2.0),
74+
]
7275

7376

7477
def test_main_entry_point_gen_data(setup_ert):
@@ -84,17 +87,19 @@ def test_main_entry_point_gen_data(setup_ert):
8487
obs = ert.getObservations()
8588
obs_vector = obs["WPR_DIFF_1"]
8689

87-
assert_obs_vector(obs_vector, 1.0, [0, 1], np.sqrt(4 / 2))
90+
result = get_std_from_obs_vector(obs_vector)
91+
assert result == [np.sqrt(4 / 2), np.sqrt(4 / 2), 1.0, 1.0], "Only update subset"
8892

8993
cos_config["CALCULATE_KEYS"]["keys"][0].update({"index": [400, 800, 1200]})
9094

9195
CorrelatedObservationsScalingJob(ert).run(cos_config)
92-
assert_obs_vector(
93-
obs_vector,
94-
1.0,
95-
[0, 1],
96+
result = get_std_from_obs_vector(obs_vector)
97+
assert result == [
9698
np.sqrt(3.0 / 2.0),
97-
)
99+
np.sqrt(3.0 / 2.0),
100+
1.0,
101+
1.0,
102+
], "Change basis for update"
98103

99104
svd_file = os.path.join(
100105
"storage", # ens_path == storage/snake_oil/ensemble
@@ -148,16 +153,69 @@ def test_main_entry_point_summary_data_calc(setup_ert, monkeypatch):
148153
obs = ert.getObservations()
149154

150155
obs_vector = obs["WOPR_OP1_108"]
151-
156+
result = []
152157
for index, node in enumerate(obs_vector):
153-
assert node.getStdScaling(index) == 1.0
158+
result.append(node.getStdScaling(index))
159+
assert result == [1]
154160

155161
CorrelatedObservationsScalingJob(ert).run(cos_config)
156162

157163
for index, node in enumerate(obs_vector):
158164
assert node.getStdScaling(index) == 1.0
159165

160166

167+
@pytest.mark.parametrize(
168+
"config, expected_result",
169+
[
170+
pytest.param(
171+
{"CALCULATE_KEYS": {"keys": [{"key": "FOPR"}]}},
172+
np.sqrt(200 / 5),
173+
id="All indecies should update",
174+
),
175+
pytest.param(
176+
{"CALCULATE_KEYS": {"keys": [{"key": "WOPR_OP1_108"}]}},
177+
1.0,
178+
id="No indecies on FOPR should update",
179+
),
180+
],
181+
)
182+
def test_main_entry_point_history_data_calc(
183+
setup_ert, monkeypatch, config, expected_result
184+
):
185+
186+
res_config = setup_ert
187+
188+
ert = EnKFMain(res_config)
189+
obs = ert.getObservations()
190+
CorrelatedObservationsScalingJob(ert).run(config)
191+
obs_vector = obs["FOPR"]
192+
result = []
193+
for index, node in enumerate(obs_vector):
194+
result.append(node.getStdScaling(index))
195+
assert result == [expected_result] * 200
196+
197+
198+
def test_main_entry_point_history_data_calc_subset(setup_ert, monkeypatch):
199+
config = {"CALCULATE_KEYS": {"keys": [{"key": "FOPR", "index": [10, 20]}]}}
200+
res_config = setup_ert
201+
202+
ert = EnKFMain(res_config)
203+
obs = ert.getObservations()
204+
obs_vector = obs["FOPR"]
205+
206+
expected_result = [1.0] * 200
207+
expected_result[10] = np.sqrt(2)
208+
expected_result[20] = np.sqrt(2)
209+
CorrelatedObservationsScalingJob(ert).run(config)
210+
211+
result = []
212+
for index, node in enumerate(obs_vector):
213+
result.append(node.getStdScaling(index))
214+
assert (
215+
result == expected_result
216+
), "Check that only the selected subset of obs have updated scaling"
217+
218+
161219
@pytest.mark.skipif(TEST_DATA_DIR is None, reason="no equinor libres test-data")
162220
@pytest.mark.equinor_test
163221
@pytest.mark.usefixtures("setup_tmpdir")

0 commit comments

Comments
 (0)