@@ -56,8 +56,7 @@ def forecast(
56
56
R : array-like
57
57
Array of shape (ar_order+1,m,n) containing the input precipitation fields
58
58
ordered by timestamp from oldest to newest. The time steps between
59
- the inputs are assumed to be regular, and the inputs are required to have
60
- finite values.
59
+ the inputs are assumed to be regular.
61
60
V : array-like
62
61
Array of shape (2,m,n) containing the x- and y-components of the
63
62
advection field.
@@ -141,9 +140,6 @@ def forecast(
141
140
if filter_kwargs is None :
142
141
filter_kwargs = dict ()
143
142
144
- if np .any (~ np .isfinite (R )):
145
- raise ValueError ("R contains non-finite values" )
146
-
147
143
if np .any (~ np .isfinite (V )):
148
144
raise ValueError ("V contains non-finite values" )
149
145
@@ -191,8 +187,14 @@ def forecast(
191
187
extrapolator_method = extrapolation .get_method (extrap_method )
192
188
193
189
R = R [- (ar_order + 1 ) :, :, :].copy ()
194
- R_min = R .min ()
190
+ R_min = np .nanmin (R )
191
+
192
+ # determine the domain mask from non-finite values
193
+ domain_mask = np .logical_or .reduce (
194
+ [~ np .isfinite (R [i , :]) for i in range (R .shape [0 ])]
195
+ )
195
196
197
+ # determine the precipitation threshold mask
196
198
if conditional :
197
199
MASK_thr = np .logical_and .reduce (
198
200
[R [i , :, :] >= R_thr for i in range (R .shape [0 ])]
@@ -207,15 +209,14 @@ def forecast(
207
209
208
210
extrap_kwargs = extrap_kwargs .copy ()
209
211
extrap_kwargs ["xy_coords" ] = xy_coords
212
+ extrap_kwargs ["allow_nonfinite_values" ] = True
210
213
211
214
# advect the previous precipitation fields to the same position with the
212
215
# most recent one (i.e. transform them into the Lagrangian coordinates)
213
216
res = list ()
214
217
215
218
def f (R , i ):
216
- return extrapolator_method (R [i , :, :], V , ar_order - i , "min" , ** extrap_kwargs )[
217
- - 1
218
- ]
219
+ return extrapolator_method (R [i , :], V , ar_order - i , "min" , ** extrap_kwargs )[- 1 ]
219
220
220
221
for i in range (ar_order ):
221
222
if not DASK_IMPORTED :
@@ -227,6 +228,11 @@ def f(R, i):
227
228
num_workers_ = len (res ) if num_workers > len (res ) else num_workers
228
229
R = np .stack (list (dask .compute (* res , num_workers = num_workers_ )) + [R [- 1 , :, :]])
229
230
231
+ # replace non-finite values with the minimum value
232
+ R = R .copy ()
233
+ for i in range (R .shape [0 ]):
234
+ R [i , ~ np .isfinite (R [i , :])] = np .nanmin (R [i , :])
235
+
230
236
# compute the cascade decompositions of the input precipitation fields
231
237
R_d = []
232
238
for i in range (ar_order + 1 ):
@@ -334,6 +340,8 @@ def f(R, i):
334
340
mu_fct = np .mean (R_c_ [MASK ])
335
341
R_c_ [MASK ] = R_c_ [MASK ] - mu_fct + mu_0
336
342
343
+ R_c_ [domain_mask ] = np .nan
344
+
337
345
# advect the recomposed precipitation field to obtain the forecast for
338
346
# time step t
339
347
extrap_kwargs .update ({"D_prev" : D , "return_displacement" : True })
0 commit comments