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
22 changes: 22 additions & 0 deletions autotest/dfns/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,28 @@ def test_migrate_ts_shapes(dfn_dir):
assert ts.shape == ["time_series_names"]


@pytest.mark.parametrize("v1_shape", ["(ncon(ifno))", "(:)"])
def test_migrate_sfr_ic_shape(dfn_dir, tmp_path, v1_shape):
for name in ("common", "gwf-sfr"):
text = (dfn_dir / f"{name}.dfn").read_text()
text = text.replace("shape (ncon(ifno))", f"shape {v1_shape}")
(tmp_path / f"{name}.dfn").write_text(text)
component = _migrate_dev3(tmp_path, "gwf-sfr")
conn = component.blocks["connectiondata"].fields["connectiondata"].item
assert conn.fields["ic"].shape == ["packagedata.ncon(ifno)"]


@pytest.mark.parametrize("v1_shape", ["(sum(nlakeconn))", "(nlakeconn)"])
def test_migrate_lak_connectiondata_shape(dfn_dir, tmp_path, v1_shape):
for name in ("common", "gwf-lak"):
text = (dfn_dir / f"{name}.dfn").read_text()
text = text.replace("shape (sum(nlakeconn))", f"shape {v1_shape}")
(tmp_path / f"{name}.dfn").write_text(text)
component = _migrate_dev3(tmp_path, "gwf-lak")
assert component.blocks["connectiondata"].fields["connectiondata"].shape == ["nlakeconn"]
assert component.dims["nlakeconn"].value == "sum(packagedata.nlakeconn)"


def test_migrate_auxiliary_stays_self_sizing(dfn_dir):
component = _migrate_dev3(dfn_dir, "gwf-chd")
assert component.blocks["options"].fields["auxiliary"].shape == []
Expand Down
7 changes: 5 additions & 2 deletions modflow_devtools/dfns/migrate_to_v2_0_0_dev2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# time series name, so the count is exactly `time_series_names`.
_V1_SHAPE_FIXES: dict[tuple[str, str], str] = {
("utl-ts", "sfacval"): "(time_series_names)",
("gwf-sfr", "ic"): "(ncon(ifno))",
("gwf-lak", "connectiondata"): "(sum(nlakeconn))",
}


Expand Down Expand Up @@ -848,6 +850,7 @@ def visit_Call(self, node: ast.Call) -> ast.AST:


def _infer_list_shape_dims(
name: str,
blocks: dict[str, v2.Block],
v1_fields: OMD,
scope: "Literal['component', 'model', 'simulation']",
Expand All @@ -866,7 +869,7 @@ def _infer_list_shape_dims(
v1_shapes: dict[tuple[str, str], str] = {}
for f in v1_fields.values(multi=True):
if (f.get("type") or "").startswith("recarray"):
shape = (f.get("shape") or "").strip()
shape = _V1_SHAPE_FIXES.get((name, f["name"]), f.get("shape") or "").strip()
if shape:
v1_shapes[(f["block"], f["name"])] = shape

Expand Down Expand Up @@ -1949,7 +1952,7 @@ def _lookup(rname: str) -> dict | None:
blocks = _fill_period_list_shapes(blocks, explicit_dims)
blocks = _fill_named_list_shapes(blocks, explicit_dims)
blocks, derived_dims = _infer_list_shape_dims(
blocks, fields, _dims_scope(name, parent), known_dims
name, blocks, fields, _dims_scope(name, parent), known_dims
)
blocks = _fix_list_shapes(name, blocks)
blocks = _fix_ts_sfac(name, blocks)
Expand Down
Loading