#NEWLINE# def calcDrySpells( model , cid , droughtfun = np . mean , duration = 14 , recovduration = 2 ) : #NEWLINE# #INDENT# 'Calculate maps of number of dry spells during simulation period.' #NEWLINE# p = np . loadtxt ( '{0}/forcings/data_{1:.{3}f}_{2:.{3}f}' . format ( model . model_path , model . gid [ cid ] [ 0 ] , model . gid [ cid ] [ 1 ] , model . grid_decimal ) ) [ : , 0 ] #NEWLINE# drought_thresh = droughtfun ( p ) #NEWLINE# ndroughts = np . zeros ( len ( p ) ) #NEWLINE# days = 0 #NEWLINE# for i in range ( ( recovduration - 1 ) , len ( p ) ) : #NEWLINE# #INDENT# if ( p [ i ] <= drought_thresh ) : #NEWLINE# #INDENT# days += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if all ( ( ( p [ ( i - j ) ] > drought_thresh ) for j in range ( recovduration ) ) ) : #NEWLINE# #INDENT# days = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# days += 1 #NEWLINE# #UNINDENT# #UNINDENT# if ( days == duration ) : #NEWLINE# #INDENT# ndroughts [ model ] = 1 #NEWLINE# #UNINDENT# #UNINDENT# return np . cumsum ( ndroughts )