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
10 changes: 5 additions & 5 deletions flopy4/mf6/codec/reader/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import xarray as xr
from lark import Token, Transformer
from modflow_devtools.dfn import _SCALAR_TYPES, Dfn, get_blocks, get_fields
from modflow_devtools.dfn import SCALAR_TYPES, Dfn


class BasicTransformer(Transformer):
Expand Down Expand Up @@ -65,8 +65,8 @@ class TypedTransformer(Transformer):
def __init__(self, visit_tokens=False, dfn: Dfn = None):
super().__init__(visit_tokens)
self.dfn = dfn
self.blocks = get_blocks(dfn) if dfn else None
self.fields = get_fields(dfn) if dfn else None
self.blocks = dfn.blocks if dfn else None
self.fields = dfn.fields if dfn else None

def start(self, items: list[Any]) -> Mapping:
return ChainMap(*items)
Expand Down Expand Up @@ -178,9 +178,9 @@ def __default__(self, data, children, meta):
elif data.endswith("_vars"):
return {item[0].lower(): item[1] for item in children}
elif (field := self.fields.get(data, None)) is not None:
if field["type"] == "keyword":
if field.type == "keyword":
return data, True
elif field["type"] in _SCALAR_TYPES and field.get("shape", None):
elif field.type in SCALAR_TYPES and field.shape is not None:
return data, TypedTransformer.try_create_dataarray(children[0])
else:
return data, children[0]
Expand Down
11 changes: 6 additions & 5 deletions flopy4/mf6/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import numpy as np
from attrs import fields
from modflow_devtools.dfn import Dfn, Field
from packaging.version import Version
from xattree import xattree

from flopy4.mf6.constants import FILL_DNODATA
from flopy4.mf6.spec import field, fields_dict, to_dfn_field
from flopy4.mf6.spec import field, fields_dict, to_field
from flopy4.uio import IO, Loader, Writer


Expand Down Expand Up @@ -162,21 +163,21 @@ def __len__(self):
@classmethod
def get_dfn(cls) -> Dfn:
"""Get the component's definition (i.e. specification)."""
fields = {field_name: to_dfn_field(field) for field_name, field in fields_dict(cls).items()}
fields = {field_name: to_field(field) for field_name, field in fields_dict(cls).items()}
blocks: dict[str, dict[str, Field]] = {}
for field_name, field_ in fields.items():
if (block := field_.get("block", None)) is not None:
if (block := field_.block) is not None:
blocks.setdefault(block, {})[field_name] = field_
else:
blocks[field_name] = field_

return Dfn(
schema_version=Version("2"),
name=cls.__name__.lower(),
advanced=getattr(cls, "advanced_package", False),
multi=getattr(cls, "multi_package", False),
ref=getattr(cls, "sub_package", None),
sln=getattr(cls, "solution_package", None),
**blocks,
blocks=blocks,
)

def _preio(self, format: str) -> None:
Expand Down
5 changes: 3 additions & 2 deletions flopy4/mf6/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import xattree
from attrs import define
from cattrs import Converter
from modflow_devtools.dfn.schema.block import block_sort_key
from numpy.typing import NDArray
from xattree import get_xatspec

Expand All @@ -21,7 +22,7 @@
from flopy4.mf6.model import Model
from flopy4.mf6.package import Package
from flopy4.mf6.solution import Solution
from flopy4.mf6.spec import fields_dict, get_blocks
from flopy4.mf6.spec import fields_dict


@define
Expand Down Expand Up @@ -87,7 +88,7 @@ def _path_to_record(field_name: str, path_value: Path) -> tuple:


def unstructure_component(value: Component) -> dict[str, Any]:
blockspec = get_blocks(value.dfn)
blockspec = dict(sorted(value.dfn.blocks.items(), key=block_sort_key)) # type: ignore
blocks: dict[str, dict[str, Any]] = {}
xatspec = xattree.get_xatspec(type(value))

Expand Down
3 changes: 0 additions & 3 deletions flopy4/mf6/gwf/chd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Chd(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
aux: Optional[NDArray[np.float64]] = array(
Expand All @@ -44,7 +43,6 @@ class Chd(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
boundname: Optional[NDArray[np.str_]] = array(
Expand All @@ -55,6 +53,5 @@ class Chd(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
4 changes: 0 additions & 4 deletions flopy4/mf6/gwf/drn.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ class Drn(Package):
dims=("nper", "nodes"),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
cond: Optional[NDArray[np.float64]] = array(
block="period",
dims=("nper", "nodes"),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
aux: Optional[NDArray[np.float64]] = array(
Expand All @@ -51,7 +49,6 @@ class Drn(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
boundname: Optional[NDArray[np.str_]] = array(
Expand All @@ -62,6 +59,5 @@ class Drn(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
4 changes: 0 additions & 4 deletions flopy4/mf6/gwf/oc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class Period:
default="all",
dims=("nper",),
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
format="keystring",
)
save_budget: Optional[NDArray[np.object_]] = array(
Expand All @@ -67,7 +66,6 @@ class Period:
default="all",
dims=("nper",),
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
format="keystring",
)
print_head: Optional[NDArray[np.object_]] = array(
Expand All @@ -76,7 +74,6 @@ class Period:
default="all",
dims=("nper",),
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
format="keystring",
)
print_budget: Optional[NDArray[np.object_]] = array(
Expand All @@ -85,6 +82,5 @@ class Period:
default="all",
dims=("nper",),
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
format="keystring",
)
3 changes: 0 additions & 3 deletions flopy4/mf6/gwf/rch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Rch(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
aux: Optional[NDArray[np.float64]] = array(
Expand All @@ -44,7 +43,6 @@ class Rch(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
boundname: Optional[NDArray[np.str_]] = array(
Expand All @@ -55,6 +53,5 @@ class Rch(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
2 changes: 0 additions & 2 deletions flopy4/mf6/gwf/sto.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ class Sto(Package):
dims=("nper",),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
)
transient: Optional[NDArray[np.bool_]] = array(
block="period",
dims=("nper",),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
)
3 changes: 0 additions & 3 deletions flopy4/mf6/gwf/wel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Wel(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
aux: Optional[NDArray[np.float64]] = array(
Expand All @@ -46,7 +45,6 @@ class Wel(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
boundname: Optional[NDArray[np.str_]] = array(
Expand All @@ -57,6 +55,5 @@ class Wel(Package):
),
default=None,
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
reader="urword",
on_setattr=update_maxbound,
)
2 changes: 0 additions & 2 deletions flopy4/mf6/ims.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path
from typing import ClassVar, Optional

from modflow_devtools.dfn import Sln
from xattree import xattree

from flopy4.mf6.solution import Solution
Expand All @@ -10,7 +9,6 @@

@xattree
class Ims(Solution):
solution_package: ClassVar[Sln] = Sln(abbr="ims", pattern="*")
slntype: ClassVar[str] = "ims"

print_option: Optional[str] = field(block="options", default=None)
Expand Down
Loading
Loading