Skip to content

Commit

Permalink
Test that save parameters internalize DataFrame parameters in the sto…
Browse files Browse the repository at this point in the history
…rage
  • Loading branch information
xjules committed Oct 18, 2024
1 parent 457efaa commit 83e9d24
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tests/ert/unit_tests/test_libres_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
from datetime import datetime, timedelta
from textwrap import dedent

import numpy as np
import pytest
from pandas import ExcelWriter
from pandas.core.frame import DataFrame
from resdata.summary import Summary

from ert.config import ErtConfig
from ert.enkf_main import sample_prior
from ert.config.design_matrix import DESIGN_MATRIX_GROUP, DesignMatrix
from ert.enkf_main import sample_prior, save_design_matrix_to_ensemble
from ert.libres_facade import LibresFacade
from ert.storage import open_storage

Expand Down Expand Up @@ -241,3 +244,34 @@ def test_load_gen_kw_not_sorted(storage, tmpdir, snapshot):

data = ensemble.load_all_gen_kw_data()
snapshot.assert_match(data.round(12).to_csv(), "gen_kw_unsorted")


def test_save_parameters_to_storage_from_design_dataframe(tmp_path):
design_path = tmp_path / "design_matrix.xlsx"
a_values = [1, 2, 3]
b_values = [4, 5, 6]
c_values = [7, 8, 9]
design_matrix_df = DataFrame({"a": a_values, "b": b_values, "c": c_values})
with ExcelWriter(design_path) as xl_write:
design_matrix_df.to_excel(xl_write, index=False, sheet_name="DesignSheet01")
DataFrame().to_excel(
xl_write, index=False, sheet_name="DefaultValues", header=False
)
design_matrix = DesignMatrix(design_path, "DesignSheet01", "DefaultValues")
design_matrix.read_design_matrix()
with open_storage(tmp_path / "storage", mode="w") as storage:
experiment_id = storage.create_experiment(
parameters=[design_matrix.parameter_configuration[DESIGN_MATRIX_GROUP]]
)
ensemble_size = 3
ensemble = storage.create_ensemble(
experiment_id, name="default", ensemble_size=ensemble_size
)
save_design_matrix_to_ensemble(
design_matrix.design_matrix_df, ensemble, [0, 1, 2]
)
params = ensemble.load_parameters("DESIGN_MATRIX")["values"]
all(params.names.values == ["a", "b", "c"])
np.testing.assert_array_equal(params[:, 0], a_values)
np.testing.assert_array_equal(params[:, 1], b_values)
np.testing.assert_array_equal(params[:, 2], c_values)

0 comments on commit 83e9d24

Please sign in to comment.