Skip to content

Commit 2143926

Browse files
committed
working
1 parent f8956cf commit 2143926

File tree

10 files changed

+111
-84
lines changed

10 files changed

+111
-84
lines changed

flopy4/mf6/converters.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import types
2-
from typing import Union, get_args, get_origin
31

42
import numpy as np
53
from numpy.typing import NDArray
@@ -8,7 +6,7 @@
86
from flopy4.mf6.constants import FILL_DNODATA
97

108

11-
def convert_array(value, self_, field):
9+
def convert_array(value, self_, field) -> NDArray:
1210
if not isinstance(value, dict):
1311
# if not a dict, assume it's a numpy array
1412
# and let xarray deal with it if it isn't
@@ -29,20 +27,8 @@ def convert_array(value, self_, field):
2927
if any(unresolved):
3028
raise ValueError(f"Couldn't resolve dims: {unresolved}")
3129

32-
# extract dtype
33-
origin = get_origin(field.type)
34-
args = get_args(field.type)
35-
if origin in (Union, types.UnionType) and args[-1] is types.NoneType:
36-
origin = args[0] # Optional
37-
if origin is NDArray:
38-
dtype = args[1]
39-
elif origin is np.ndarray:
40-
dtype = args[0]
41-
else:
42-
raise ValueError(f"Expected NDArray, got {origin}")
43-
4430
# create array
45-
a = np.full(shape, fill_value=FILL_DNODATA, dtype=dtype)
31+
a = np.full(shape, fill_value=FILL_DNODATA, dtype=field.dtype)
4632

4733
def _get_nn(cellid):
4834
match len(cellid):
@@ -59,13 +45,13 @@ def _get_nn(cellid):
5945

6046
# populate array. TODO: is there a way to do this
6147
# without hardcoding awareness of kper and cellid?
62-
if "kper" in dims:
48+
if "per" in dims:
6349
for kper, period in value.items():
6450
if kper == "*":
6551
kper = 0
6652
match len(shape):
6753
case 1:
68-
a[kper] = v
54+
a[kper] = value
6955
case _:
7056
for cellid, v in period.items():
7157
nn = _get_nn(cellid)
@@ -75,6 +61,6 @@ def _get_nn(cellid):
7561
else:
7662
for cellid, v in value.items():
7763
nn = _get_nn(cellid)
78-
a[kper, nn] = v
64+
a[nn] = v
7965

8066
return a

flopy4/mf6/gwf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from attrs import define
55
from xattree import field, xattree
66

7-
from flopy4.mf6 import Model
87
from flopy4.mf6.gwf.chd import Chd
98
from flopy4.mf6.gwf.dis import Dis
109
from flopy4.mf6.gwf.ic import Ic
1110
from flopy4.mf6.gwf.npf import Npf
1211
from flopy4.mf6.gwf.oc import Oc
12+
from flopy4.mf6.model import Model
1313

1414
__all__ = ["Gwf", "Chd", "Dis", "Ic", "Npf", "Oc"]
1515

flopy4/mf6/gwf/chd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from numpy.typing import NDArray
77
from xattree import array, field, xattree
88

9-
from flopy4.mf6 import Package
109
from flopy4.mf6.converters import convert_array
10+
from flopy4.mf6.package import Package
1111

1212

1313
# TODO get rid of multi, just infer from parent?

flopy4/mf6/gwf/dis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from numpy.typing import NDArray
44
from xattree import array, dim, field, xattree
55

6-
from flopy4.mf6 import Package
76
from flopy4.mf6.converters import convert_array
7+
from flopy4.mf6.package import Package
88

99

1010
@xattree

flopy4/mf6/gwf/ic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from numpy.typing import NDArray
44
from xattree import array, field, xattree
55

6-
from flopy4.mf6 import Package
76
from flopy4.mf6.converters import convert_array
7+
from flopy4.mf6.package import Package
88

99

1010
@xattree

flopy4/mf6/gwf/npf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from numpy.typing import NDArray
77
from xattree import array, field, xattree
88

9-
from flopy4.mf6 import Package
109
from flopy4.mf6.converters import convert_array
10+
from flopy4.mf6.package import Package
1111

1212

1313
@xattree

flopy4/mf6/gwf/oc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from numpy.typing import NDArray
77
from xattree import array, field, xattree
88

9-
from flopy4.mf6 import Package
109
from flopy4.mf6.converters import convert_array
10+
from flopy4.mf6.package import Package
1111
from flopy4.utils import to_path
1212

1313

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dynamic = ["version"]
5151

5252
[project.optional-dependencies]
5353
dev = ["flopy4[lint,test,build]"]
54-
lint = ["ruff", "pre-commit>=4.0.1,<5"]
54+
lint = ["ruff", "pre-commit>=4.0.1,<5", "mypy"]
5555
test = [
5656
"flopy4[lint]",
5757
"coverage",
@@ -139,3 +139,8 @@ test = { cmd = "pytest -v -n auto" }
139139
[tool.pixi.feature.lint.tasks]
140140
lint = { cmd = "ruff check ." }
141141
install = { cmd = "pre-commit install --install-hooks" }
142+
143+
[tool.mypy]
144+
mypy_path = "flopy4"
145+
ignore_missing_imports = true
146+
warn_unreachable = true

test/test_component.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from flopy.discretization.modeltime import ModelTime
44
from xarray import DataTree
55

6-
from flopy4.mf6 import COMPONENTS, Simulation, Tdis
6+
from flopy4.mf6.component import COMPONENTS
77
from flopy4.mf6.gwf import Chd, Dis, Gwf, Ic, Npf, Oc
8+
from flopy4.mf6.simulation import Simulation
9+
from flopy4.mf6.tdis import Tdis
810

911

1012
def test_registry():

uv.lock

Lines changed: 91 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)