@@ -280,40 +280,39 @@ def prec(prec: pd.Series, t_min: pd.Series, ts: float, params: dict,
280280 prec:
281281 A sub-daily timeseries of precipitation. [mm]
282282 """
283- #def prec_TRIANGLE(prec: pd.Series, t_min: pd.Series,
284- # month_of_year: int, do_mix: bool, params: dict):
285283 def prec_TRIANGLE (daily_prec , t_min , prec_peak , prec_dur , ts , do_mix ):
286284 '''Triangular disaggregation'''
287285 ts_per_day = int (cnst .HOURS_PER_DAY * cnst .MIN_PER_HOUR )
288286 n_days = len (daily_prec )
289- # Scale to desired timestep
290- #prec_peak /= ts
291- #prec_dur /= ts
292287 disagg_prec = np .zeros (int (n_days * ts_per_day ))
293288
294289 # Loop over days
295290 for i , (t , P ) in enumerate (daily_prec .iteritems ()):
296- times_day = np .arange (ts_per_day )
297- prec_day = np .zeros (ts_per_day )
298-
299- # Look up climatology
300- t_pk = prec_peak [t ]
301- t_dur = prec_dur [t ]
302-
303- # Rising and falling time
304- t_start = t_pk - 0.5 * t_dur
305- t_stop = t_pk + 0.5 * t_dur
306- t_plus = times_day [
307- np .logical_and (times_day <= t_pk , times_day >= t_start )]
308- t_minus = times_day [
309- np .logical_and (times_day >= t_pk , times_day <= t_stop )]
310-
311- # Begin with relative intensity
312- prec_day [t_plus ] = np .linspace (0 , 1.0 , len (t_plus ))
313- prec_day [t_minus ] = np .linspace (1.0 , 0 , len (t_minus ))
314-
315- # Scale to input precipitation
316- prec_day = (P / np .sum (prec_day )) * prec_day
291+
292+ if do_mix and t_min [t ] < 0 :
293+ prec_day = P * np .ones (ts_per_day ) / ts_per_day
294+ else :
295+ times_day = np .arange (ts_per_day )
296+ prec_day = np .zeros (ts_per_day )
297+
298+ # Look up climatology
299+ t_pk = prec_peak [t ]
300+ t_dur = prec_dur [t ]
301+
302+ # Rising and falling time
303+ t_start = t_pk - 0.5 * t_dur
304+ t_stop = t_pk + 0.5 * t_dur
305+ t_plus = times_day [
306+ np .logical_and (times_day <= t_pk , times_day >= t_start )]
307+ t_minus = times_day [
308+ np .logical_and (times_day >= t_pk , times_day <= t_stop )]
309+
310+ # Begin with relative intensity
311+ prec_day [t_plus ] = np .linspace (0 , 1.0 , len (t_plus ))
312+ prec_day [t_minus ] = np .linspace (1.0 , 0 , len (t_minus ))
313+
314+ # Scale to input precipitation
315+ prec_day = (P / np .sum (prec_day )) * prec_day
317316 disagg_prec [i * ts_per_day :(i + 1 )* ts_per_day ] = prec_day
318317 return disagg_prec
319318
0 commit comments