Skip to content

Commit

Permalink
Use resfo instead of eclsum for run_ecl
Browse files Browse the repository at this point in the history
This avoids critical failures from resdata propagating to the user.
  • Loading branch information
eivindjahren committed Jan 12, 2024
1 parent 0f93287 commit 1742690
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/ert/shared/share/ert/forward-models/res/script/ecl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from collections import namedtuple
from contextlib import contextmanager, suppress

import resfo
from ecl_config import EclrunConfig
from packaging import version
from resdata.summary import Summary


def await_process_tee(process, *out_files):
Expand Down Expand Up @@ -148,6 +148,27 @@ def pushd(run_path):
os.chdir(starting_directory)


def _find_unsmry(case: str) -> str:
def _is_unsmry(base: str, path: str) -> bool:
if "." not in path:
return False
splitted = path.split(".")
return splitted[-2].endswith(base) and splitted[-1].lower() in [
"unsmry",
"funsmry",
]

dir, base = os.path.split(case)
candidates = list(filter(lambda x: _is_unsmry(base, x), os.listdir(dir or ".")))
if not candidates:
raise ValueError(f"Could not find any unsmry matching case path {case}")
if len(candidates) > 1:
raise ValueError(
f"Ambiguous reference to unsmry in {case}, could be any of {candidates}"
)
return os.path.join(dir, candidates[0])


class EclRun:
"""Wrapper class to run Eclipse simulations.
Expand Down Expand Up @@ -386,8 +407,8 @@ def summary_block(self):
time.sleep(1)

try:
ecl_sum = Summary(case)
except (OSError, ValueError):
ecl_sum = list(resfo.lazy_read(_find_unsmry(case)))
except Exception:
continue

this_len = len(ecl_sum)
Expand Down

0 comments on commit 1742690

Please sign in to comment.