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
4 changes: 2 additions & 2 deletions flopy4/mf6/codec/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def field_type(value: Any) -> FieldType:
return "double"
if isinstance(value, str):
return "string"
if isinstance(value, tuple):
if isinstance(value, (dict, tuple)):
return "record"
if isinstance(value, xr.DataArray):
if value.dtype == "object":
return "list"
return "array"
if isinstance(value, (list, dict, xr.Dataset)):
if isinstance(value, (list, xr.Dataset)):
return "list"
raise ValueError(f"Unsupported field type: {type(value)}")
3 changes: 2 additions & 1 deletion flopy4/mf6/converter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from flopy4.mf6.component import Component
from flopy4.mf6.context import Context
from flopy4.mf6.converter.structure import structure_array
from flopy4.mf6.converter.structure import structure_array, structure_keyword
from flopy4.mf6.converter.unstructure import (
unstructure_component,
)
Expand All @@ -19,6 +19,7 @@
"unstructure",
"structure_array",
"unstructure_array",
"structure_keyword",
"COMPONENT_CONVERTER",
]

Expand Down
4 changes: 4 additions & 0 deletions flopy4/mf6/converter/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from flopy4.mf6.constants import FILL_DNODATA


def structure_keyword(value, field) -> str | None:
return field.name if value else None


def structure_array(value, self_, field) -> NDArray:
"""
Convert a sparse dictionary representation of an array to a
Expand Down
13 changes: 9 additions & 4 deletions flopy4/mf6/gwf/npf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pathlib import Path
from typing import Optional
from typing import Literal, Optional

import attrs
import numpy as np
from attrs import Converter, define
from numpy.typing import NDArray
from xattree import xattree

from flopy4.mf6.converter import structure_array
from flopy4.mf6.converter import structure_array, structure_keyword
from flopy4.mf6.package import Package
from flopy4.mf6.spec import array, field, path
from flopy4.utils import to_path
Expand All @@ -16,8 +17,12 @@
class Npf(Package):
@define(slots=False)
class CvOptions:
variablecv: bool = field(default=False)
dewatered: bool = field(default=False)
variablecv: Literal["variablecv"] = attrs.field(init=False, default="variablecv")
dewatered: Literal["dewatered"] | None = attrs.field(
default=None,
# TODO: adopt this pattern for all record types in all components?
converter=Converter(structure_keyword, takes_field=True), # type: ignore
)

@define(slots=False)
class RewetRecord:
Expand Down
Loading
Loading