Skip to content

Commit 71092a2

Browse files
deltamarnixwpbonelli
authored andcommitted
Convert to sparse arrays instead of full np arrays
1 parent df1458c commit 71092a2

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

flopy4/mf6/converters.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import numpy as np
1+
import sparse
22
from numpy.typing import NDArray
33
from xattree import _get_xatspec
44

@@ -28,9 +28,7 @@ def convert_array(value, self_, field) -> NDArray:
2828

2929
# create array
3030
# TDOD: support other fill values, configurable by field?
31-
a = np.full(
32-
shape, fill_value=field.default or FILL_DNODATA
33-
) # , dtype=field.dtype)
31+
a = dict()
3432

3533
def _get_nn(cellid):
3634
match len(cellid):
@@ -53,16 +51,22 @@ def _get_nn(cellid):
5351
kper = 0
5452
match len(shape):
5553
case 1:
56-
a[kper] = period
54+
a[(kper)] = period
5755
case _:
5856
for cellid, v in period.items():
5957
nn = _get_nn(cellid)
60-
a[kper, nn] = v
58+
a[(kper, nn)] = v
6159
if kper == "*":
6260
break
6361
else:
6462
for cellid, v in value.items():
6563
nn = _get_nn(cellid)
66-
a[nn] = v
64+
a[(nn)] = v
6765

68-
return a
66+
coords = list(map(list, zip(*a.keys())))
67+
return sparse.COO(
68+
coords,
69+
list(a.values()),
70+
shape=shape,
71+
fill_value=field.default or FILL_DNODATA,
72+
)

0 commit comments

Comments
 (0)