Skip to content

Commit f21930f

Browse files
committed
notes
1 parent 1db20a1 commit f21930f

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

flopy4/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def init_tree(
238238
cls = type(self)
239239
spec = fields_dict(cls)
240240
dimensions = set()
241+
coordinates = {}
241242
array_vars = {}
242243
scalar_vars = {}
243244
array_vals = {}
@@ -281,9 +282,18 @@ def _yield_arrays(spec, vals):
281282

282283
array_vals = dict(list(_yield_arrays(spec=array_vars, vals=self.__dict__)))
283284

285+
# add coordinate arrays to the data tree
286+
for dim in dimensions:
287+
var = spec[dim]
288+
coord = var.metadata.get("coord", None)
289+
if coord:
290+
value = np.arange(array_vals[dim][1].shape[0])
291+
coordinates[coord] = value
292+
284293
self.data = DataTree(
285294
Dataset(
286-
array_vals,
295+
data_vars=array_vals,
296+
coords=coordinates,
287297
attrs={
288298
n: v for n, v in scalar_vals.items() if n not in dimensions
289299
},

flopy4/mf6/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PeriodData:
4343
nstp: int = field(default=1)
4444
tsmult: float = field(default=1.0)
4545

46-
nper: int = field(default=1, metadata={"block": "dimensions"})
46+
nper: int = field(default=1, metadata={"block": "dimensions", "dim": {"coord": "kper"}})
4747
perioddata: list[PeriodData] = field(
4848
default=Factory(list),
4949
metadata={"block": "perioddata", "dims": ("nper",)},

flopy4/mf6/gwf/dis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class Dis(Package):
2222
export_array_netcdf: bool = field(
2323
default=False, metadata={"block": "options"}
2424
)
25-
nlay: int = field(default=1, metadata={"block": "dimensions"})
26-
ncol: int = field(default=2, metadata={"block": "dimensions"})
27-
nrow: int = field(default=2, metadata={"block": "dimensions"})
25+
nlay: int = field(default=1, metadata={"block": "dimensions", "dim": {"coord": "k"}})
26+
ncol: int = field(default=2, metadata={"block": "dimensions", "dim": {"coord": "i"}})
27+
nrow: int = field(default=2, metadata={"block": "dimensions", "dim": {"coord": "j"}})
2828
delr: NDArray[np.floating] = field(
2929
default=1.0,
3030
metadata={"block": "griddata", "dims": ("ncol",)},

flopy4/todo.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
11
# todo
22

3-
## perf
3+
- deduplicate data trees
44

5-
### memory
6-
7-
Need to deduplicate data trees.
85
Each component should get a view into the root (as far as it's aware) tree
96
unless it's the root (i.e. simulation) itself, or it's not attached to any
107
parent context, in which case it's the root of its own tree.
118

12-
### speed
13-
14-
Need faster dimension resolution.
15-
We know the path from simulation to dis and tdis, no reason to search for it.
16-
17-
## api
18-
19-
### components
9+
- subcomponent accessors
2010

2111
I think for access by name we want dict style e.g. `gwf["chd1"]`,
22-
like imod-python does it.
12+
like imod-python does it?
2313

2414
By type, e.g. `gwf.chd`, where it's either a single component,
2515
or a dict by name (or auto-increment index) for multipackages?
2616

27-
## docs
28-
29-
Reproduce flopy3 quickstart.
30-
Keep it minimal, just show an equivalent with the prototype.
17+
- first class dimension support
3118

32-
More detailed demo notebook.
33-
Compare/contrast implementations and different patterns in
34-
more detail.
19+
Right now array variables just declare their expected dimension. And the
20+
dimensions are looked up by unguided search across the data tree's vars,
21+
from the root down. Let variables declare themselves as dimensions? With
22+
optional coordinate arrays autogenerated in the right size and added to
23+
the dataset? And allow local vs global dimensions?

0 commit comments

Comments
 (0)