Criticality
Criticality¶
Maps
Code¶
Importing¶
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as P
import numpy as N
from matplotlib.offsetbox import AnchoredText
from scipy import signal,stats
from scipy import stats as S
print (P.style.available)
#P.style.use('bmh')
params = { 'legend.fontsize': 8,\
'font.family': 'serif',\
}
P.rcParams.update(params)
Reading¶
city = 'WadiMusa'
file = './includes/%s.md'%city
date = N.genfromtxt(file,usecols=(0),delimiter='|',skip_header=2,dtype='str')
uera = N.genfromtxt(file,usecols=(1),delimiter='|',skip_header=2,dtype='f')
era5 = N.genfromtxt(file,usecols=(2),delimiter='|',skip_header=2,dtype='f')
chir = N.genfromtxt(file,usecols=(3),delimiter='|',skip_header=2,dtype='f')
inp = chir
file = '../../data/gwl/gwlneudatum.dat'
ta = N.genfromtxt(file,usecols=(0),skip_header=1,dtype='i')
mo = N.genfromtxt(file,usecols=(1),skip_header=1,dtype='i')
ja = N.genfromtxt(file,usecols=(2),skip_header=1,dtype='i')
gw = N.genfromtxt(file,usecols=(3),skip_header=1,dtype='str')
nd = len(gw)
dates = []
for d in range(nd):
tmp = '%4i-%02i-%02i'%(ja[d],mo[d],ta[d])
dates.append(tmp)
dates = N.array(dates)
gg = []
for d in date:
id = N.where(dates==d)[0]
if(len(id)==1):
id = id[0]
gg.append(gw[id])
gg = N.array(gg)
Plotting¶
inp = inp[:len(gg)]
gwls = list(set(gg))
rint = N.arange(0,130,10)
P.figure(figsize=(12,7))
ax = P.subplot(111)
bin = N.digitize(inp,rint,right=True)
bins = list(set(bin))
bin = bin[1:]
gwl = []
for b in bins[1:]:
id = N.where(bin==b)[0]
gx = N.array(list(set(gw[id])))
z = len(gx)
P.bar(rint[b-1],z,8.0,color='dodgerblue',ec='k',lw=1.0)
gg = []
for g in gx:
ik = N.where(gw[id]==g)[0]
gg.append(len(ik))
gg = N.array(gg)
ij = N.argsort(gg)
print (gg[ij])
j = -0.7
for i in ij:
j = j+1
if(gg[i]>1):
P.text(rint[b-1],j,gx[i],fontsize=10,color='r',horizontalalignment='center')
else:
P.text(rint[b-1],j,gx[i],fontsize=10,color='w',horizontalalignment='center')
P.xticks([0,10,20,30,40,50,60,70,80,90,100,110,120,130])
P.xlim(-5,135)
P.yticks([0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30])
P.ylim(0,30)
P.xlabel('Daily Rainfall Intensity (mm/d)',fontsize=14,weight='bold')
P.ylabel('Number of Contributing Weather-Types',fontsize=14,weight='bold')
at = AnchoredText('CHIRPS-%s'%(city),prop=dict(size=14),frameon=True,loc='upper right')
at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(at)
P.savefig('./img/criticality_%s.png'%city,dpi=240,bbox_inches='tight')