Skip to content

Commit

Permalink
Commitin
Browse files Browse the repository at this point in the history
  • Loading branch information
dafeda committed Nov 1, 2024
1 parent f3b9bed commit 0adb160
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/ert/ui_tests/cli/test_field_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import resfo
import xtgeo

from ert.analysis import (
smoother_update,
)
from ert.config import ErtConfig
from ert.config.analysis_config import UpdateSettings
from ert.config.analysis_module import ESSettings
from ert.mode_definitions import ENSEMBLE_SMOOTHER_MODE
from ert.storage import open_storage

Expand Down Expand Up @@ -210,3 +215,61 @@ def test_parameter_update_with_inactive_cells_xtgeo_grdecl(tmpdir):
assert "nan" not in Path(
"simulations/realization-0/iter-1/my_param.grdecl"
).read_text(encoding="utf-8")


def test_field_param_update_using_heat_equation_and_zero_var_params(
heat_equation_storage,
):
config = ErtConfig.from_file("config.ert")
with open_storage(config.ens_path, mode="w") as storage:
experiment = storage.get_experiment_by_name("es-mda")
prior = experiment.get_ensemble_by_name("default_0")
# posterior = experiment.get_ensemble_by_name("default_1")
cond = prior.load_parameters("COND")

new_experiment = storage.create_experiment(name="exp-zero-var")
new_prior = storage.create_ensemble(
new_experiment,
ensemble_size=prior.ensemble_size,
iteration=0,
name="prior-zero-var",
)
# TODO: Set half of the parameters in cond to a constant value.
new_prior.save_parameters("COND", range(prior.ensemble_size), cond)

new_posterior = storage.create_ensemble(
new_prior.experiment_id,
ensemble_size=config.model_config.num_realizations,
iteration=1,
name="new_ensemble",
prior_ensemble=new_prior,
)

smoother_update(
new_prior,
new_posterior,
experiment.observation_keys,
config.ensemble_config.parameters,
UpdateSettings(),
ESSettings(),
)

# param_config = config.ensemble_config.parameter_configs["COND"]
# assert len(prior_result.x) == param_config.nx
# assert len(prior_result.y) == param_config.ny
# assert len(prior_result.z) == param_config.nz

# posterior_result = posterior.load_parameters("COND")["values"]
# prior_covariance = np.cov(
# prior_result.values.reshape(
# prior.ensemble_size, param_config.nx * param_config.ny * param_config.nz
# )
# )
# posterior_covariance = np.cov(
# posterior_result.values.reshape(
# posterior.ensemble_size,
# param_config.nx * param_config.ny * param_config.nz,
# )
# )
# # Check that generalized variance is reduced by update step.
# assert np.trace(prior_covariance) > np.trace(posterior_covariance)

0 comments on commit 0adb160

Please sign in to comment.