From b1bfd15dc799d7c1ede6ac8100fdc760a00e3e0f Mon Sep 17 00:00:00 2001 From: Feda Curic Date: Thu, 1 Dec 2022 09:46:20 +0100 Subject: [PATCH] Use better variable names --- src/ert/analysis/_es_update.py | 40 +++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/ert/analysis/_es_update.py b/src/ert/analysis/_es_update.py index 9ab3bf83fe2..bd34432d6a4 100644 --- a/src/ert/analysis/_es_update.py +++ b/src/ert/analysis/_es_update.py @@ -150,8 +150,8 @@ def _correlated_parameter_response_pairs( # State-measurement correlation matrix c_AY = np.linalg.inv(Sigma_A) @ C_AY @ np.linalg.inv(Sigma_Y) - _, corr_idx_Y = np.where(np.abs(c_AY) > correlation_threshold) - return corr_idx_Y + _, responses_to_keep = np.where(np.abs(c_AY) > correlation_threshold) + return responses_to_keep def analysis_ES( @@ -192,7 +192,9 @@ def analysis_ES( ] = observation_handle.update_snapshot observation_values = observation_handle.observation_values observation_errors = observation_handle.observation_errors - if len(observation_values) == 0: + + num_obs = len(observation_values) + if num_obs == 0: raise ErtAnalysisError( f"No active observations for update step: {update_step.name}." ) @@ -203,28 +205,28 @@ def analysis_ES( ) if A is not None: - noise = rng.standard_normal(size=(len(observation_values), Y.shape[1])) + ensemble_size = A.shape[1] + num_params = A.shape[0] + noise = rng.standard_normal(size=(num_obs, ensemble_size)) if module.localization(): A_ES_loc = [] - N = A.shape[1] - p = A.shape[0] - for i in range(A.shape[0]): - A_chunk = A[i, :].reshape(-1, N) - corr_idx_Y = _correlated_parameter_response_pairs( + for i in range(num_params): + A_chunk = A[i, :].reshape(1, ensemble_size) + responses_to_keep = _correlated_parameter_response_pairs( A_chunk, Y, module.localization_correlation_threshold(), ) - Y_loc = Y[corr_idx_Y, :] - observation_errors_loc = observation_errors[corr_idx_Y] - observation_values_loc = observation_values[corr_idx_Y] + Y_loc = Y[responses_to_keep, :] + observation_errors_loc = observation_errors[responses_to_keep] + observation_values_loc = observation_values[responses_to_keep] A_loc = ies.ensemble_smoother_update_step( Y_loc, A_chunk, observation_errors_loc, observation_values_loc, - noise[corr_idx_Y], + noise[responses_to_keep], module.get_truncation(), ies.InversionType(module.inversion), projection=False, @@ -291,7 +293,7 @@ def analysis_IES( # Looping over local analysis update_step for update_step in updatestep: - S, observation_handle = update.load_observations_and_responses( + Y, observation_handle = update.load_observations_and_responses( source_fs, obs, alpha, @@ -307,16 +309,18 @@ def analysis_IES( observation_values = observation_handle.observation_values observation_errors = observation_handle.observation_errors observation_mask = observation_handle.obs_mask - if len(observation_values) == 0: + + num_obs = len(observation_values) + if num_obs == 0: raise ErtAnalysisError( f"No active observations for update step: {update_step.name}." ) A = _get_A_matrix(temp_storage, update_step.parameters) - - noise = rng.standard_normal(size=(len(observation_values), S.shape[1])) + ensemble_size = A.shape[1] + noise = rng.standard_normal(size=(num_obs, ensemble_size)) A = iterative_ensemble_smoother.update_step( - S, + Y, A, observation_errors, observation_values,