@@ -104,12 +104,8 @@ def __init__(self, dtype, arr_mask, cell_shape):
104104
105105 # slice for a simple padding (allow stencil calculation on boundary)
106106 self .simple_pad = (slice (1 , - 1 ), slice (1 , - 1 ))
107- # Fill values for input arrays
108- self .input_fill_values = {
109- arr_def .key : arr_def .fill_value
110- for arr_def in ARRAY_DEFINITIONS
111- if ArrayCategory .INPUT in arr_def .category
112- }
107+ # Fill values
108+ self .fill_values = {arr_def .key : arr_def .fill_value for arr_def in ARRAY_DEFINITIONS }
113109
114110 # all keys that will be used for the arrays
115111 self .k_input = [
@@ -130,14 +126,7 @@ def __init__(self, dtype, arr_mask, cell_shape):
130126 # Instantiate arrays and padded arrays filled with zeros
131127 self .arr = dict .fromkeys (self .k_all )
132128 self .arrp = dict .fromkeys (self .k_all )
133- self .create_arrays ()
134-
135- def zeros_array (self ):
136- """return a np array of the domain dimension, filled with zeros.
137- dtype is set to object's dtype.
138- Intended to be used as default for the input model maps.
139- """
140- return np .zeros (shape = self .shape , dtype = self .dtype )
129+ self ._create_arrays ()
141130
142131 def pad_array (self , arr ):
143132 """Return the original input array
@@ -147,12 +136,13 @@ def pad_array(self, arr):
147136 arr = arr_p [self .simple_pad ]
148137 return arr , arr_p
149138
150- def create_arrays (self ):
139+ def _create_arrays (self ):
151140 """Instantiate masked arrays and padded arrays
152141 the unpadded arrays are a slice of the padded ones
153142 """
154143 for k in self .arr .keys ():
155- self .arr [k ], self .arrp [k ] = self .pad_array (self .zeros_array ())
144+ arr = np .full (fill_value = self .fill_values [k ], shape = self .shape , dtype = self .dtype )
145+ self .arr [k ], self .arrp [k ] = self .pad_array (arr )
156146 return self
157147
158148 def update_mask (self , arr ):
@@ -196,14 +186,13 @@ def swap_arrays(self, k1, k2):
196186
197187 def update_array (self , arr_key , arr ):
198188 """Update the values of an array with those of a given array."""
199- fill_value = self .input_fill_values [arr_key ]
200189 if arr .shape != self .shape :
201- return ValueError
190+ return ValueError ( f"Updated values for array ' { arr_key } ' do not match domain size." )
202191 if arr_key == "water_surface_elevation" :
203192 # Calculate actual depth and update the internal depth array
204193 arr = rastermetrics .calculate_h_from_wse (arr_wse = arr , arr_dem = self .get_array ("dem" ))
205194 arr_key = "water_depth"
206- self .mask_array (arr , fill_value )
195+ self .mask_array (arr , self . fill_values [ arr_key ] )
207196 self .arr [arr_key ][:], self .arrp [arr_key ][:] = self .pad_array (arr )
208197 return self
209198
0 commit comments