From b2a81571b91533007bb02930b9f5589034216286 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Tue, 30 May 2023 13:20:01 +0200 Subject: [PATCH] Use new obs vector interface --- semeio/workflows/ahm_analysis/ahmanalysis.py | 2 +- .../workflows/correlated_observations_scaling/cos.py | 2 +- .../correlated_observations_scaling/obs_utils.py | 6 +++--- .../update_scaling.py | 12 +++++++----- semeio/workflows/localisation/local_config_script.py | 2 +- .../misfit_preprocessor/misfit_preprocessor.py | 2 +- .../spearman_correlation_job/spearman_correlation.py | 2 +- setup.py | 2 +- .../spearman_correlation_job/test_integration.py | 2 +- .../test_scale_observations.py | 2 +- 10 files changed, 18 insertions(+), 16 deletions(-) diff --git a/semeio/workflows/ahm_analysis/ahmanalysis.py b/semeio/workflows/ahm_analysis/ahmanalysis.py index 4c171d147..5e51c79ea 100644 --- a/semeio/workflows/ahm_analysis/ahmanalysis.py +++ b/semeio/workflows/ahm_analysis/ahmanalysis.py @@ -121,7 +121,7 @@ def run( if output_dir is not None: self._reports_dir = output_dir - obs_keys = [o.getKey() for o in self.facade.get_observations()] + obs_keys = list(self.facade.get_observations().obs_vectors.keys()) key_map = _group_observations(self.facade, obs_keys, group_by) prior_name, target_name = check_names( diff --git a/semeio/workflows/correlated_observations_scaling/cos.py b/semeio/workflows/correlated_observations_scaling/cos.py index a88019f20..94480d7bb 100755 --- a/semeio/workflows/correlated_observations_scaling/cos.py +++ b/semeio/workflows/correlated_observations_scaling/cos.py @@ -140,7 +140,7 @@ def run(self, job_configuration): user_config = _insert_default_group(user_config) obs = self.facade.get_observations() - obs_keys = [o.getKey() for o in obs] + obs_keys = list(obs.obs_vectors.keys()) default_values = _get_default_values( self.facade.get_alpha(), self.facade.get_std_cutoff() ) diff --git a/semeio/workflows/correlated_observations_scaling/obs_utils.py b/semeio/workflows/correlated_observations_scaling/obs_utils.py index 81f86a962..bfa0352af 100644 --- a/semeio/workflows/correlated_observations_scaling/obs_utils.py +++ b/semeio/workflows/correlated_observations_scaling/obs_utils.py @@ -106,12 +106,12 @@ def _active_list_from_index_list(index_list): def _data_index_to_obs_index(obs, obs_key, data_index_list): - if obs[obs_key].getImplementationType().name != "GEN_OBS": + if obs[obs_key].observation_type.name != "GEN_OBS": return data_index_list if data_index_list is None: return data_index_list - for timestep in obs[obs_key].getStepList(): - node = obs[obs_key].getNode(timestep) + for timestep, node in obs[obs_key].observations.items(): + node = obs[obs_key].observations[timestep] index_map = {node.indices[nr]: nr for nr in range(len(node))} return [index_map[index] for index in data_index_list] diff --git a/semeio/workflows/correlated_observations_scaling/update_scaling.py b/semeio/workflows/correlated_observations_scaling/update_scaling.py index ee571a07f..63e6b1dc6 100644 --- a/semeio/workflows/correlated_observations_scaling/update_scaling.py +++ b/semeio/workflows/correlated_observations_scaling/update_scaling.py @@ -25,11 +25,13 @@ def _update_scaling(obs, scale_factor, obs_list): """ for event in obs_list: obs_vector = obs[event.key] - step_list = obs_vector.getStepList() # List of steps, 1-indexed - for step in step_list: - obs_node = obs_vector.getNode(step) - if obs_vector.getImplementationType().name == "SUMMARY_OBS": - index_list = event.index if event.index else [x - 1 for x in step_list] + index_list = ( + event.index + if event.index + else [x - 1 for x in obs_vector.observations.keys()] + ) + for step, obs_node in obs_vector.observations.items(): + if obs_vector.observation_type.name == "SUMMARY_OBS": if step - 1 in index_list: obs_node.std_scaling = scale_factor else: diff --git a/semeio/workflows/localisation/local_config_script.py b/semeio/workflows/localisation/local_config_script.py index 24de1a90c..02bcf2028 100644 --- a/semeio/workflows/localisation/local_config_script.py +++ b/semeio/workflows/localisation/local_config_script.py @@ -14,7 +14,7 @@ def run(self, *args): config_dict = local.read_localisation_config(args) # Get all observations from ert instance - obs_keys = [o.getKey() for o in self.facade.get_observations()] + obs_keys = list(self.facade.get_observations().obs_vectors.keys()) ensemble_config = ert.ensembleConfig() ert_parameters = local.get_param_from_ert(ensemble_config) diff --git a/semeio/workflows/misfit_preprocessor/misfit_preprocessor.py b/semeio/workflows/misfit_preprocessor/misfit_preprocessor.py index 125bd0a38..e6132f607 100644 --- a/semeio/workflows/misfit_preprocessor/misfit_preprocessor.py +++ b/semeio/workflows/misfit_preprocessor/misfit_preprocessor.py @@ -18,7 +18,7 @@ class MisfitPreprocessorJob(SemeioScript): # pylint: disable=method-hidden def run(self, *args): config_record = _fetch_config_record(args) - observations = [o.getKey() for o in self.facade.get_observations()] + observations = list(self.facade.get_observations().obs_vectors.keys()) config = assemble_config(config_record, observations) if config.reports_directory: self._reports_dir = config.reports_directory diff --git a/semeio/workflows/spearman_correlation_job/spearman_correlation.py b/semeio/workflows/spearman_correlation_job/spearman_correlation.py index 3bd5508b9..7a96850cb 100755 --- a/semeio/workflows/spearman_correlation_job/spearman_correlation.py +++ b/semeio/workflows/spearman_correlation_job/spearman_correlation.py @@ -17,7 +17,7 @@ def run(self, *args): # pylint: disable=method-hidden # (SemeioScript wraps this run method) - obs_keys = [o.getKey() for o in self.facade.get_observations()] + obs_keys = list(self.facade.get_observations().obs_vectors.keys()) measured_data = self.facade.get_measured_data(obs_keys, ensemble=self.ensemble) diff --git a/setup.py b/setup.py index ce94bbb12..fdebe924e 100755 --- a/setup.py +++ b/setup.py @@ -52,7 +52,7 @@ ], install_requires=[ "ecl", - "ert>=5.0.0rc1", + "ert>=5.0.0rc3", "configsuite>=0.6", "numpy", "pandas>1.3.0", diff --git a/tests/jobs/spearman_correlation_job/test_integration.py b/tests/jobs/spearman_correlation_job/test_integration.py index eb260e52f..93ab9a613 100644 --- a/tests/jobs/spearman_correlation_job/test_integration.py +++ b/tests/jobs/spearman_correlation_job/test_integration.py @@ -104,7 +104,7 @@ def raising_scaling_job(data): @pytest.fixture(name="facade") def fixture_facade(): facade = Mock() - facade.get_observations.return_value = [] + facade.get_observations.return_value.obs_vectors = {} return facade diff --git a/tests/jobs/test_scale_observations/test_scale_observations.py b/tests/jobs/test_scale_observations/test_scale_observations.py index 31715f1ee..fe6ed8971 100644 --- a/tests/jobs/test_scale_observations/test_scale_observations.py +++ b/tests/jobs/test_scale_observations/test_scale_observations.py @@ -33,7 +33,7 @@ def test_scale_summary_obs(snake_oil_obs, index_list): scale_observations(snake_oil_obs, 1.2345, [Config("WOPR_OP1_36", index_list)]) obs_vector = snake_oil_obs["WOPR_OP1_36"] - node = obs_vector.getNode(36) + node = obs_vector.observations[36] assert node.std_scaling == 1.2345, f"index: {36}"