Skip to content

Commit

Permalink
Add alias NAMES for WGNAMES and fix network vars
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Feb 5, 2024
1 parent db56a48 commit c250f1d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/ert/config/_read_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ def make_summary_key(
(lgr_name,) = _check_if_missing("local completion", "LGRS", lgr_name)
return f"{keyword}:{lgr_name}:{name}:{li},{lj},{lk}"
if sum_type == _SummaryType.NETWORK:
# This is consistent with resinsight but
# has a bug in resdata
# https://github.com/equinor/resdata/issues/943
return keyword
(name,) = _check_if_missing("local completion", "WGNAMES", name)
return f"{keyword}:{name}"
raise ValueError(f"Unexpected keyword type: {sum_type}")


Expand Down Expand Up @@ -258,6 +256,7 @@ def _read_spec(
kw: None
for kw in [
"WGNAMES ",
"NAMES ",
"NUMS ",
"KEYWORDS",
"NUMLX ",
Expand All @@ -267,6 +266,9 @@ def _read_spec(
"UNITS ",
]
}
array_kws = list(arrays.keys())
array_kws.remove("WGNAMES ")
array_kws.remove("NAMES ")

if spec.lower().endswith("fsmspec"):
mode = "rt"
Expand All @@ -286,9 +288,9 @@ def _read_spec(
nx,
ny,
]
+ list(arrays.values())
+ array_kws
)
):
) and (arrays["WGNAMES "] is not None or arrays["NAMES "] is not None):
break
kw = entry.read_keyword()
if kw in arrays:
Expand Down Expand Up @@ -326,7 +328,7 @@ def _read_spec(
f"SMSPEC {spec} contains invalid STARTDAT: {err}"
) from err
keywords = arrays["KEYWORDS"]
wgnames = arrays["WGNAMES "]
wgnames = arrays["WGNAMES "] or arrays["NAMES "]
nums = arrays["NUMS "]
numlx = arrays["NUMLX "]
numly = arrays["NUMLY "]
Expand Down
8 changes: 7 additions & 1 deletion tests/unit_tests/config/summary_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class Smspec:
numlx: Optional[List[PositiveInt]] = None
numly: Optional[List[PositiveInt]] = None
numlz: Optional[List[PositiveInt]] = None
use_names: bool = False # whether to use the alias NAMES for WGNAMES

def to_ecl(self) -> List[Tuple[str, Any]]:
# The restart field contains 9 strings of length 8 which
Expand Down Expand Up @@ -273,7 +274,11 @@ def to_ecl(self) -> List[Tuple[str, Any]]:
),
),
("KEYWORDS", [kw.ljust(8) for kw in self.keywords]),
("WGNAMES ", self.well_names),
(
("NAMES ", self.well_names)
if self.use_names
else ("WGNAMES ", self.well_names)
),
("NUMS ", np.array(self.region_numbers, dtype=np.int32)),
("UNITS ", self.units),
("STARTDAT", np.array(self.start_date.to_ecl(), dtype=np.int32)),
Expand Down Expand Up @@ -355,6 +360,7 @@ def smspecs(draw, sum_keys, start_date, use_days=None):
region_numbers=st.just(region_numbers),
units=st.just(units),
start_date=start_date,
use_names=st.booleans(),
)
)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/config/test_read_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_summary_key_format_of_field_and_misc_is_identity(

@given(st.integers(), st.text(), st.integers(), st.integers())
def test_network_variable_keys_has_keyword_as_summary_key(number, name, nx, ny):
assert make_summary_key("NOPR", number, name, nx, ny) == "NOPR"
assert make_summary_key("NOPR", number, name, nx, ny) == f"NOPR:{name}"


@given(st.integers(), st.text(), st.integers(), st.integers())
Expand Down

0 comments on commit c250f1d

Please sign in to comment.