22from typing import ClassVar , Optional
33
44import numpy as np
5- from attrs import Converter , define
5+ from attrs import define
66from numpy .typing import NDArray
7- from xattree import xattree
7+ from xattree import dict_to_array_converter , xattree
88
9- from flopy4 .mf6 .codec import structure_array
109from flopy4 .mf6 .constants import FILL_DNODATA
1110from flopy4 .mf6 .package import Package
1211from flopy4 .mf6 .spec import array , field
@@ -34,24 +33,24 @@ class Steps:
3433 obs_filerecord : Optional [Path ] = field (block = "options" , default = None )
3534 dev_no_newton : bool = field (default = False , metadata = {"block" : "options" })
3635 maxbound : Optional [int ] = field (block = "dimensions" , default = None )
37- head : Optional [NDArray [np .floating ]] = array (
36+ head : Optional [NDArray [np .float64 ]] = array (
3837 block = "period" ,
3938 dims = (
4039 "nper" ,
4140 "nnodes" ,
4241 ),
4342 default = None ,
44- converter = Converter ( structure_array , takes_self = True , takes_field = True ) ,
43+ converter = dict_to_array_converter ,
4544 reader = "urword" ,
4645 )
47- aux : Optional [NDArray [np .floating ]] = array (
46+ aux : Optional [NDArray [np .float64 ]] = array (
4847 block = "period" ,
4948 dims = (
5049 "nper" ,
5150 "nnodes" ,
5251 ),
5352 default = None ,
54- converter = Converter ( structure_array , takes_self = True , takes_field = True ) ,
53+ converter = dict_to_array_converter ,
5554 reader = "urword" ,
5655 )
5756 boundname : Optional [NDArray [np .str_ ]] = array (
@@ -61,15 +60,15 @@ class Steps:
6160 "nnodes" ,
6261 ),
6362 default = None ,
64- converter = Converter ( structure_array , takes_self = True , takes_field = True ) ,
63+ converter = dict_to_array_converter ,
6564 reader = "urword" ,
6665 )
6766 steps : Optional [NDArray [np .object_ ]] = array (
6867 Steps ,
6968 block = "period" ,
7069 dims = ("nper" , "nnodes" ),
7170 default = None ,
72- converter = Converter ( structure_array , takes_self = True , takes_field = True ) ,
71+ converter = dict_to_array_converter ,
7372 reader = "urword" ,
7473 )
7574
@@ -79,8 +78,25 @@ def __attrs_post_init__(self):
7978 # in post init. but this only works when values
8079 # are set in the initializer, not when they are
8180 # set later.
82- maxhead = len (np .where (self .head != FILL_DNODATA )) if self .head is not None else 0
83- maxaux = len (np .where (self .aux != FILL_DNODATA )) if self .aux is not None else 0
84- maxboundname = len (np .where (self .boundname != "" )) if self .boundname is not None else 0
81+ if self .head is None :
82+ maxhead = 0
83+ else :
84+ head = self .head if self .head .data .shape == self .head .shape else self .head .todense ()
85+ maxhead = len (np .where (head != FILL_DNODATA ))
86+ if self .aux is None :
87+ maxaux = 0
88+ else :
89+ aux = self .aux if self .aux .data .shape == self .aux .shape else self .aux .todense ()
90+ maxaux = len (np .where (aux != FILL_DNODATA ))
91+ if self .boundname is None :
92+ maxboundname = 0
93+ else :
94+ boundname = (
95+ self .boundname
96+ if self .boundname .data .shape == self .boundname .shape
97+ else self .boundname .todense ()
98+ )
99+ maxboundname = len (np .where (boundname != "" ))
100+
85101 # maxsteps = len(np.where(self.steps != None)) if self.steps is not None else 0
86102 self .maxbound = max (maxhead , maxaux , maxboundname )
0 commit comments