Skip to content

Commit

Permalink
Sort observations before returning
Browse files Browse the repository at this point in the history
The order of the observations are important when doing updates
as it influences the pertubations. Now this property is used for
updates, which means the order matters.
  • Loading branch information
oyvindeide committed Mar 12, 2024
1 parent e398b22 commit 55b9e3a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ert/storage/local_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def update_parameters(self) -> List[str]:

@cached_property
def observations(self) -> Dict[str, xr.Dataset]:
observations = list(self.mount_point.glob("observations/*"))
observations = sorted(list(self.mount_point.glob("observations/*")))
return {
observation.name: xr.open_dataset(observation, engine="scipy")
for observation in observations
Expand Down
12 changes: 12 additions & 0 deletions tests/unit_tests/analysis/test_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,3 +594,15 @@ def test_temporary_parameter_storage_with_inactive_fields(
ensemble._path / f"realization-{iens}" / f"{param_group}.nc", engine="scipy"
)
np.testing.assert_array_equal(ds["values"].values[0], fields[iens]["values"])


def test_that_observations_keep_sorting(snake_oil_case_storage, snake_oil_storage):
"""
The order of the observations influence the update as it affects the
perturbations, so we make sure we maintain the order throughout.
"""
ert_config = snake_oil_case_storage
prior_ens = snake_oil_storage.get_ensemble_by_name("default_0")
assert list(ert_config.observations.keys()) == list(
prior_ens.experiment.observations.keys()
)

0 comments on commit 55b9e3a

Please sign in to comment.