Skip to content

Commit

Permalink
Use better variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
dafeda committed Dec 13, 2022
1 parent 6fa4f0a commit b1bfd15
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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}."
)
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit b1bfd15

Please sign in to comment.