Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flopy4/mf6/gwf/chdg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Chdg(Package):
}

observations: ClassVar[dict[str, tuple[tuple[str, ...], ...]]] = {
"chd": (("cellid",), ("string",)),
"chd": (("cellid",),),
}

key_sets: ClassVar[dict[str, str]] = {
Expand Down
4 changes: 2 additions & 2 deletions flopy4/mf6/gwf/drng.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Drng(Package):
}

observations: ClassVar[dict[str, tuple[tuple[str, ...], ...]]] = {
"drn": (("cellid",), ("string",)),
"to-mvr": (("cellid",), ("string",)),
"drn": (("cellid",),),
"to-mvr": (("cellid",),),
}

key_sets: ClassVar[dict[str, str]] = {
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/gwf/evta.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Evta(Package):
}

observations: ClassVar[dict[str, tuple[tuple[str, ...], ...]]] = {
"evt": (("cellid",), ("string",)),
"evt": (("cellid",),),
}

readasarrays: bool = keyword(
Expand Down
4 changes: 2 additions & 2 deletions flopy4/mf6/gwf/ghbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Ghbg(Package):
}

observations: ClassVar[dict[str, tuple[tuple[str, ...], ...]]] = {
"ghb": (("cellid",), ("string",)),
"to-mvr": (("cellid",), ("string",)),
"ghb": (("cellid",),),
"to-mvr": (("cellid",),),
}

key_sets: ClassVar[dict[str, str]] = {
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/gwf/rcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Rcha(Package):
}

observations: ClassVar[dict[str, tuple[tuple[str, ...], ...]]] = {
"rch": (("cellid",), ("string",)),
"rch": (("cellid",),),
}

readasarrays: bool = keyword(
Expand Down
4 changes: 2 additions & 2 deletions flopy4/mf6/gwf/rivg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Rivg(Package):
}

observations: ClassVar[dict[str, tuple[tuple[str, ...], ...]]] = {
"riv": (("cellid",), ("string",)),
"to-mvr": (("cellid",), ("string",)),
"riv": (("cellid",),),
"to-mvr": (("cellid",),),
}

key_sets: ClassVar[dict[str, str]] = {
Expand Down
6 changes: 3 additions & 3 deletions flopy4/mf6/gwf/welg.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Welg(Package):
}

observations: ClassVar[dict[str, tuple[tuple[str, ...], ...]]] = {
"to-mvr": (("cellid",), ("string",)),
"wel": (("cellid",), ("string",)),
"wel-reduction": (("cellid",), ("string",)),
"to-mvr": (("cellid",),),
"wel": (("cellid",),),
"wel-reduction": (("cellid",),),
}

key_sets: ClassVar[dict[str, str]] = {
Expand Down
16 changes: 14 additions & 2 deletions flopy4/mf6/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,21 @@ def solve(i: int, pos: int, form: "tuple[str, ...] | None") -> "tuple[int, list]
for form in forms or (None,):
if (solved := solve(0, 0, form)) is not None:
return {f.name: v for f, v in zip(fields, solved[1]) if v is not None}
if forms: # ids its observation type doesn't take: guess
return _read_unions(fields, full, ncelldim, prefer)
names = ", ".join(f.name for f in fields)
if forms: # ids its observation type doesn't take: guess, but not a boundname
guess = _read_unions(fields, full, ncelldim, prefer)
for i, f in enumerate(fields):
v = guess.get(f.name)
if (
isinstance(v, str)
and not _token_fits(v, float)
and not any(len(form) > i and form[i] == "string" for form in forms)
):
raise ValueError(
f"can't read {names} from {full}: {v!r} is a boundname, "
f"but this observation type takes only {list(forms)}"
)
return guess
raise ValueError(f"can't read {names} from {full}")


Expand Down
56 changes: 31 additions & 25 deletions pixi.lock

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions test/mf6/test_mf6_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5276,6 +5276,25 @@ def test_obs_ids_by_obstype(tmp_path, parent, dims, row, ids):
assert (obs_row.id_, obs_row.id2) == ids


@pytest.mark.parametrize("parent", ["Chdg", "Drng", "Evta", "Ghbg", "Rcha", "Rivg", "Welg"])
def test_obs_boundname_rejected_by_grid_package(tmp_path, parent):
"""A grid package has no boundnames, so its OBS ids are cellids only,
as in MF6: a boundname is an error, not a guess."""
from flopy4.mf6 import gwf
from flopy4.mf6.codec.reader import loads
from flopy4.mf6.converter.ingress.structure import structure_component

cls = getattr(gwf, parent)
obstype = next(iter(cls.observations))
(tmp_path / "p.obs").write_text(
f"BEGIN CONTINUOUS FILEOUT p.csv\n o1 {obstype} well-a\nEND CONTINUOUS\n"
)
raw = loads("BEGIN OPTIONS\n OBS6 FILEIN p.obs\nEND OPTIONS\n")
context = LoadContext(workspace=tmp_path, dims=_DISV)
with pytest.raises(ValueError, match="'well-a' is a boundname"):
structure_component(raw, cls, context=context)


def test_block_end_keeps_only_an_index():
assert writer.filters.block_begin("continuous FILEOUT Heads.csv") == (
"CONTINUOUS FILEOUT Heads.csv"
Expand Down
Loading