|
7 | 7 | import pytest |
8 | 8 | import xarray as xr |
9 | 9 | from lark import Lark |
10 | | -from modflow_devtools.dfn import Dfn, load_flat |
| 10 | +from modflow_devtools.dfn import Dfn, MapV1To2, load_flat |
11 | 11 | from modflow_devtools.models import get_models |
12 | 12 | from packaging.version import Version |
13 | 13 |
|
@@ -417,9 +417,15 @@ def test_transform_gwf_ic_file(model_workspace, dfn_path): |
417 | 417 | assert "griddata" in result # IC has griddata block |
418 | 418 | assert "strt" in result["griddata"] # Starting heads |
419 | 419 |
|
420 | | - # Check strt field exists (array transformation not fully implemented yet) |
421 | | - strt_data = result["griddata"]["strt"] |
422 | | - assert strt_data is not None |
| 420 | + # Check strt array structure |
| 421 | + strt = result["griddata"]["strt"] |
| 422 | + assert "control" in strt |
| 423 | + assert "data" in strt |
| 424 | + assert strt["control"]["type"] in ["constant", "internal", "external"] |
| 425 | + |
| 426 | + # If internal or constant, should have data |
| 427 | + if strt["control"]["type"] in ["constant", "internal"]: |
| 428 | + assert strt["data"] is not None |
423 | 429 |
|
424 | 430 |
|
425 | 431 | @pytest.mark.parametrize("model_workspace", ["mf6/example/ex-gwf-bcf2ss-p01a"], indirect=True) |
@@ -568,3 +574,142 @@ def test_transform_gwf_oc_file(model_workspace, dfn_path): |
568 | 574 | for rec in save_records: |
569 | 575 | assert "ocsetting" in rec |
570 | 576 | assert rec["ocsetting"] == "all" |
| 577 | + |
| 578 | + |
| 579 | +@pytest.mark.parametrize("model_workspace", ["mf6/example/ex-gwf-csub-p01"], indirect=True) |
| 580 | +def test_transform_gwf_dis_file(model_workspace, dfn_path): |
| 581 | + """Test transforming a parsed GWF DIS file into structured data.""" |
| 582 | + |
| 583 | + # Load the DFN for DIS and convert to V2 |
| 584 | + v1_dfns = load_flat(dfn_path) |
| 585 | + mapper = MapV1To2() |
| 586 | + dis_dfn = mapper.map(v1_dfns["gwf-dis"]) |
| 587 | + |
| 588 | + # Find the DIS file |
| 589 | + dis_files = list(model_workspace.rglob("*.dis")) |
| 590 | + assert len(dis_files) > 0 |
| 591 | + |
| 592 | + dis_file = dis_files[0] |
| 593 | + parser = get_typed_parser("gwf-dis") |
| 594 | + transformer = TypedTransformer(dfn=dis_dfn) |
| 595 | + |
| 596 | + # Read, parse, and transform |
| 597 | + with open(dis_file, "r") as f: |
| 598 | + content = f.read() |
| 599 | + |
| 600 | + tree = parser.parse(content) |
| 601 | + result = transformer.transform(tree) |
| 602 | + |
| 603 | + # Check structure |
| 604 | + assert isinstance(result, dict) |
| 605 | + |
| 606 | + # Check dimensions block |
| 607 | + assert "dimensions" in result |
| 608 | + assert "nlay" in result["dimensions"] |
| 609 | + assert "nrow" in result["dimensions"] |
| 610 | + assert "ncol" in result["dimensions"] |
| 611 | + assert result["dimensions"]["nlay"] > 0 |
| 612 | + assert result["dimensions"]["nrow"] > 0 |
| 613 | + assert result["dimensions"]["ncol"] > 0 |
| 614 | + |
| 615 | + # Check griddata block |
| 616 | + assert "griddata" in result |
| 617 | + griddata = result["griddata"] |
| 618 | + assert "delr" in griddata |
| 619 | + assert "delc" in griddata |
| 620 | + assert "top" in griddata |
| 621 | + assert "botm" in griddata |
| 622 | + |
| 623 | + # Each array should have control and data |
| 624 | + assert "control" in griddata["delr"] |
| 625 | + assert "data" in griddata["delr"] |
| 626 | + |
| 627 | + |
| 628 | +@pytest.mark.parametrize("model_workspace", ["mf6/example/ex-gwf-csub-p01"], indirect=True) |
| 629 | +def test_transform_gwf_npf_file(model_workspace, dfn_path): |
| 630 | + """Test transforming a parsed GWF NPF file into structured data.""" |
| 631 | + |
| 632 | + # Load the DFN for NPF and convert to V2 |
| 633 | + v1_dfns = load_flat(dfn_path) |
| 634 | + mapper = MapV1To2() |
| 635 | + npf_dfn = mapper.map(v1_dfns["gwf-npf"]) |
| 636 | + |
| 637 | + # Find the NPF file |
| 638 | + npf_files = list(model_workspace.rglob("*.npf")) |
| 639 | + assert len(npf_files) > 0 |
| 640 | + |
| 641 | + npf_file = npf_files[0] |
| 642 | + parser = get_typed_parser("gwf-npf") |
| 643 | + transformer = TypedTransformer(dfn=npf_dfn) |
| 644 | + |
| 645 | + # Read, parse, and transform |
| 646 | + with open(npf_file, "r") as f: |
| 647 | + content = f.read() |
| 648 | + |
| 649 | + tree = parser.parse(content) |
| 650 | + result = transformer.transform(tree) |
| 651 | + |
| 652 | + # Check structure |
| 653 | + assert isinstance(result, dict) |
| 654 | + |
| 655 | + # Check options block |
| 656 | + assert "options" in result |
| 657 | + options = result["options"] |
| 658 | + |
| 659 | + # Should have save_specific_discharge option |
| 660 | + assert "save_specific_discharge" in options |
| 661 | + assert options["save_specific_discharge"] is True |
| 662 | + |
| 663 | + # Check griddata block |
| 664 | + assert "griddata" in result |
| 665 | + griddata = result["griddata"] |
| 666 | + |
| 667 | + # NPF should have at least icelltype and k |
| 668 | + assert "icelltype" in griddata |
| 669 | + assert "k" in griddata |
| 670 | + |
| 671 | + # Each array should have control and data |
| 672 | + assert "control" in griddata["icelltype"] |
| 673 | + assert "data" in griddata["icelltype"] |
| 674 | + assert "control" in griddata["k"] |
| 675 | + assert "data" in griddata["k"] |
| 676 | + |
| 677 | + |
| 678 | +@pytest.mark.parametrize("model_workspace", ["mf6/example/ex-gwf-csub-p01"], indirect=True) |
| 679 | +def test_transform_gwf_sto_file(model_workspace, dfn_path): |
| 680 | + """Test transforming a parsed GWF STO file into structured data.""" |
| 681 | + |
| 682 | + # Load the DFN for STO and convert to V2 |
| 683 | + v1_dfns = load_flat(dfn_path) |
| 684 | + mapper = MapV1To2() |
| 685 | + sto_dfn = mapper.map(v1_dfns["gwf-sto"]) |
| 686 | + |
| 687 | + # Find the STO file |
| 688 | + sto_files = list(model_workspace.rglob("*.sto")) |
| 689 | + |
| 690 | + # Skip if no STO files (not all models have storage) |
| 691 | + if len(sto_files) == 0: |
| 692 | + pytest.skip("No STO files found in this model") |
| 693 | + |
| 694 | + sto_file = sto_files[0] |
| 695 | + parser = get_typed_parser("gwf-sto") |
| 696 | + transformer = TypedTransformer(dfn=sto_dfn) |
| 697 | + |
| 698 | + # Read, parse, and transform |
| 699 | + with open(sto_file, "r") as f: |
| 700 | + content = f.read() |
| 701 | + |
| 702 | + tree = parser.parse(content) |
| 703 | + result = transformer.transform(tree) |
| 704 | + |
| 705 | + # Check structure |
| 706 | + assert isinstance(result, dict) |
| 707 | + |
| 708 | + # Check griddata block |
| 709 | + assert "griddata" in result |
| 710 | + griddata = result["griddata"] |
| 711 | + |
| 712 | + # STO should have iconvert |
| 713 | + assert "iconvert" in griddata |
| 714 | + assert "control" in griddata["iconvert"] |
| 715 | + assert "data" in griddata["iconvert"] |
0 commit comments