Skip to content

Commit

Permalink
Remove duplicates from summary files
Browse files Browse the repository at this point in the history
  • Loading branch information
Øyvind Eide (EDT DSD SD2) authored and oyvindeide committed Sep 21, 2023
1 parent dcf690d commit 8a15332
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/clib/lib/enkf/read_summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ ERT_CLIB_SUBMODULE("_read_summary", m) {
const ecl_smspec_type *smspec = ecl_sum_get_smspec(summary);
std::vector<std::pair<std::string, std::vector<double>>>
summary_vectors{};

std::vector<std::string> seen_keys{};
for (int i = 0; i < ecl_smspec_num_nodes(smspec); i++) {
const ecl::smspec_node &smspec_node =
ecl_smspec_iget_node_w_node_index(smspec, i);
const char *key = smspec_node.get_gen_key1();
if (matches(keys, key)) {
if ((matches(keys, key)) &&
!(std::find(seen_keys.begin(), seen_keys.end(), key) !=
seen_keys.end())) {
seen_keys.push_back(key);
int start = ecl_sum_get_first_report_step(summary);
int end = ecl_sum_get_last_report_step(summary);
std::vector<double> data{};
Expand Down
6 changes: 3 additions & 3 deletions src/ert/config/summary_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def read_from_file(self, run_path: str, iens: int) -> xr.Dataset:
f"{last} from: {run_path}/{filename}.UNSMRY"
)

summary_data = read_summary(summary, self.keys)
summary_data = read_summary(summary, list(set(self.keys)))
summary_data.sort(key=lambda x: x[0])
data = [d for _, d in summary_data]
keys = [k for k, _ in summary_data]

return xr.Dataset(
ds = xr.Dataset(
{"values": (["name", "time"], data)},
coords={"time": time_map, "name": keys},
)
return ds.drop_duplicates("time")
21 changes: 21 additions & 0 deletions tests/unit_tests/scenarios/test_summary_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,24 @@ def run_sim(dates, value, fname="ECLIPSE_CASE"):
)
t_step["FOPR"] = value
ecl_sum.fwrite()


def test_that_duplicate_summary_time_steps_does_not_fail(
setup_configuration,
prior_ensemble,
target_ensemble,
):
ert = setup_configuration
ert.sample_prior(prior_ensemble, list(range(ert.getEnsembleSize())))
response_times = [
[datetime(2014, 9, 9)],
[datetime(2014, 9, 9)],
[datetime(2014, 9, 9), datetime(2014, 9, 9)],
[datetime(2014, 9, 9)],
[datetime(2014, 9, 9), datetime(1988, 9, 9)],
]
create_responses(ert, prior_ensemble, response_times)

es_update = ESUpdate(ert)

es_update.smootherUpdate(prior_ensemble, target_ensemble, "an id")

0 comments on commit 8a15332

Please sign in to comment.