Skip to content

Commit d1300c2

Browse files
authored
misc (#219)
* update xattree and modify the array field decorator wrappers to accommodate a new dtype arg, this gives us more control over dtype than the type hint. the actual arg overrides the type hint, but the type hint is used if no arg is passed * make `boundname` arrays on various components a fixed length string of length 40 (`LENBOUNDNAME`) * devtools sorts blocks so no need to move options to top in converter * switch oc arrays from object -> str dtype * turn type checking off for now in vscode settings * add pytest-cov as a test dependency * leave some todo comments
1 parent f6c304d commit d1300c2

File tree

20 files changed

+316
-244
lines changed

20 files changed

+316
-244
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ venv/
88
.pixi
99
*.egg-info
1010
temp/
11+
.coverage

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"source.fixAll": "explicit"
1313
}
1414
},
15-
"mypy-type-checker.importStrategy": "fromEnvironment",
15+
"python.analysis.typeCheckingMode": "off",
16+
"debugpy.debugJustMyCode": false,
1617
"files.exclude": {
1718
"**/.git": true,
1819
"**/.svn": true,

flopy4/mf6/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
MF6 = "mf6"
44
FILL_DEFAULT = np.nan
55
FILL_DNODATA = 1e30
6+
LENBOUNDNAME = 40

flopy4/mf6/converter.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def unstructure_component(value: Component) -> dict[str, Any]:
156156
for kper in range(field_value.sizes["nper"])
157157
}
158158
else:
159+
# TODO why not putting in block here but doing below? how does this even work
159160
if np.issubdtype(field_value.dtype, np.str_):
160161
period_data[field_name] = {
161162
kper: field_value[kper] for kper in range(field_value.sizes["nper"])
@@ -187,11 +188,6 @@ def unstructure_component(value: Component) -> dict[str, Any]:
187188
dataset = xr.Dataset(block)
188189
blocks[f"{block_name} {kper + 1}"] = {block_name: dataset}
189190

190-
# make sure options block always comes first
191-
if "options" in blocks:
192-
options_block = blocks.pop("options")
193-
blocks = {"options": options_block, **blocks}
194-
195191
# total temporary hack! manually set solutiongroup 1. still need to support multiple..
196192
if "solutiongroup" in blocks:
197193
sg = blocks["solutiongroup"]

flopy4/mf6/gwf/chd.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from xattree import xattree
88

99
from flopy4.mf6.component import update_maxbound
10+
from flopy4.mf6.constants import LENBOUNDNAME
1011
from flopy4.mf6.converter import dict_to_array
1112
from flopy4.mf6.package import Package
1213
from flopy4.mf6.spec import array, field, path
@@ -51,6 +52,7 @@ class Chd(Package):
5152
on_setattr=update_maxbound,
5253
)
5354
boundname: Optional[NDArray[np.str_]] = array(
55+
dtype=f"<U{LENBOUNDNAME}",
5456
block="period",
5557
dims=(
5658
"nper",

flopy4/mf6/gwf/dis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Dis(Package):
6464
dims=("nlay", "nrow", "ncol"),
6565
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
6666
)
67-
idomain: Optional[NDArray[np.int32]] = array(
67+
idomain: Optional[NDArray[np.int64]] = array(
6868
block="griddata",
6969
default=1,
7070
dims=("nlay", "nrow", "ncol"),

flopy4/mf6/gwf/drn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from xattree import xattree
88

99
from flopy4.mf6.component import update_maxbound
10+
from flopy4.mf6.constants import LENBOUNDNAME
1011
from flopy4.mf6.converter import dict_to_array
1112
from flopy4.mf6.package import Package
1213
from flopy4.mf6.spec import array, field, path
@@ -57,6 +58,7 @@ class Drn(Package):
5758
on_setattr=update_maxbound,
5859
)
5960
boundname: Optional[NDArray[np.str_]] = array(
61+
dtype=f"<U{LENBOUNDNAME}",
6062
block="period",
6163
dims=(
6264
"nper",

flopy4/mf6/gwf/npf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Xt3dOptions:
5050
export_array_netcdf: bool = field(block="options", default=False)
5151
dev_no_newton: bool = field(block="options", default=False)
5252
dev_omega: Optional[float] = field(block="options", default=None)
53-
icelltype: NDArray[np.integer] = array(
53+
icelltype: NDArray[np.int64] = array(
5454
block="griddata",
5555
dims=("nodes",),
5656
default=0,

flopy4/mf6/gwf/oc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,29 @@ class Period:
4646
)
4747
# TODO: needs coverter and then rename?
4848
head: Optional[Format] = field(block="options", default=None)
49-
save_head: Optional[NDArray[np.object_]] = array(
50-
object,
49+
save_head: Optional[NDArray[np.str_]] = array(
50+
dtype=np.dtypes.StringDType(),
5151
block="period",
5252
default="all",
5353
dims=("nper",),
5454
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
5555
)
56-
save_budget: Optional[NDArray[np.object_]] = array(
57-
object,
56+
save_budget: Optional[NDArray[np.str_]] = array(
57+
dtype=np.dtypes.StringDType(),
5858
block="period",
5959
default="all",
6060
dims=("nper",),
6161
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
6262
)
63-
print_head: Optional[NDArray[np.object_]] = array(
64-
object,
63+
print_head: Optional[NDArray[np.str_]] = array(
64+
dtype=np.dtypes.StringDType(),
6565
block="period",
6666
default="all",
6767
dims=("nper",),
6868
converter=Converter(dict_to_array, takes_self=True, takes_field=True),
6969
)
70-
print_budget: Optional[NDArray[np.object_]] = array(
71-
object,
70+
print_budget: Optional[NDArray[np.str_]] = array(
71+
dtype=np.dtypes.StringDType(),
7272
block="period",
7373
default="all",
7474
dims=("nper",),

flopy4/mf6/gwf/rch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from xattree import xattree
88

99
from flopy4.mf6.component import update_maxbound
10+
from flopy4.mf6.constants import LENBOUNDNAME
1011
from flopy4.mf6.converter import dict_to_array
1112
from flopy4.mf6.package import Package
1213
from flopy4.mf6.spec import array, field, path
@@ -51,6 +52,7 @@ class Rch(Package):
5152
on_setattr=update_maxbound,
5253
)
5354
boundname: Optional[NDArray[np.str_]] = array(
55+
dtype=f"<U{LENBOUNDNAME}",
5456
block="period",
5557
dims=(
5658
"nper",

0 commit comments

Comments
 (0)