diff --git a/src/ert/storage/local_experiment.py b/src/ert/storage/local_experiment.py index 4807a7774fd..5e6f877e08b 100644 --- a/src/ert/storage/local_experiment.py +++ b/src/ert/storage/local_experiment.py @@ -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 diff --git a/tests/unit_tests/analysis/test_es_update.py b/tests/unit_tests/analysis/test_es_update.py index 6584801ff20..5b69dfece36 100644 --- a/tests/unit_tests/analysis/test_es_update.py +++ b/tests/unit_tests/analysis/test_es_update.py @@ -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() + )