pars = {'tmit50':['Jahresmitteltemperatur','[$^\circ$C]'],
'nied20':['Anzahl Starkregentage','[Tage]'],
'nied99':['Regenintensität','[mm/d]'],
'pr20jz':['Anzahl Starkregentage','[Tage]'],
'pr20jj':['',''],
'pr20an':['Andauer Starkregentage',''],
}
mods = ['obs-dwd','cnr-clm','ece-clm','had-clm','mpi-clm','mpi-rca','cnr-rca','nor-rca','ips-rca','ece-rca','had-rca','cnr-hir','had-hir','ece-hir','nor-hir','cnr-rac','had-rac','ece-rac']
nm = len(mods)
nd = 365
f = open('./include/starkregen_steckbrief.md','w')
f.write('Langname|Kurzname|1971-2010|1971-2010|2011-2050|2051-2090\n')
f.write('---|---|---|---|---|---\n')
for par in pars:
print (par)
tmp = N.zeros((nj,nm),float);tmp[:,:] = N.nan
bas = N.zeros((nj,nm),float);bas[:,:] = N.nan
doy = N.zeros((nj,nm,nd),float)
day = N.zeros((nj,nm,40),float)
m = -1
for mod in mods:
m = m+1
dat = N.genfromtxt('../../data/csv/rcp85/%s/%s'%(mod,basz),names=True,dtype=None)
for j in range(nj):
id = N.where(dat['jahr']==jo[j])[0]
if(len(id)>0):
if(par=='tmit50'): tmp[j,m] = tmit50(dat['tas'][id]);bas[j,m] = tmit50(dat['tas'][id])
if(par=='nied20'): tmp[j,m] = nied20(dat['pr'][id]);bas[j,m] = tmit50(dat['tas'][id])
if(par=='nied99'): tmp[j,m] = nied99(dat['pr'][id]);bas[j,m] = tmit50(dat['tas'][id])
if(par=='pr20jz'): doy[j,m,:] = pr20jz(dat['pr'][id])
if(par=='pr20jj'): tmp[j,m] = nied20(dat['pr'][id])
if(par=='pr20an'): day[j,m,:] = pr20an(dat['pr'][id])
if((par=='tmit50')|(par=='nied20')|(par=='nied99')):
tmp0 = N.mean(tmp[0:40,0])
tmp1 = N.mean(tmp[0:40,1:])
tmp2 = N.mean(tmp[41:80,1:])
tmp3 = N.mean(tmp[81:120,1:])
f.write('%s|%s|%.1f|%.1f|%.1f|%.1f\n'%(pars[par][0],par,tmp0,tmp1,tmp2,tmp3))
P.figure(figsize=(8,3))
zx = []
tt = 30.*N.ones(nj,float)
tt[30:] = tt[30:]+N.linspace(1,10,nj-30)
for m in range(nm):
zz = N.cumsum(tmp[:,m]-N.mean(tmp[:30,m]))/tt
aa = tmp[:,m]-N.mean(tmp[:30,m])
P.subplot(121)
if(m==0): P.plot(jo,zz,'k',alpha=1.0,lw=0.5,zorder=10)
else:
for j in range(nj-1):
zx.append(aa[j])
P.scatter(jo,aa,c='None',s=10,ec='gray',lw=0.5,alpha=0.5,zorder=5)
P.plot(jo,zz,'r',lw=0.5,zorder=6)
P.subplot(122)
yy = N.cumsum(bas[:,m]-N.mean(bas[:30,m]))/30.
co = ['y','orange','r']
i = -1
for j in [2020,2050,2080]:
i = i+1
id = N.where(jo==j)[0]
P.scatter(yy[id],zz[id],color='None',ec=co[i],s=50)
zx = N.array(zx)
P.subplot(121)
P.plot([2020,2020],[N.nanmin(zx),N.nanmax(zx)],'y')
P.plot([2050,2050],[N.nanmin(zx),N.nanmax(zx)],'orange')
P.plot([2080,2080],[N.nanmin(zx),N.nanmax(zx)],'r')
P.xlim(1970,2100)
P.ylim(zx.min(),zx.max())
P.tick_params(direction='out')
P.xlabel('Jahre',fontsize=8,weight='bold')
P.ylabel('Änderung: '+pars[par][0],fontsize=8,weight='bold')
P.subplot(122)
P.xlim(0,6)
P.ylim(zx.min(),zx.max())
P.tick_params(direction='out')
P.xlabel('Temperaturänderung [K]',fontsize=8,weight='bold')
P.ylabel('Änderung: '+pars[par][0],fontsize=8,weight='bold')
P.tight_layout()
P.savefig('./img/%s.png'%par,dpi=240,transparent=False,bbox_inches='tight',pad_inches=0)
if(par=='pr20jz'):
P.figure(figsize=(8,3))
P.subplot(111)
do = N.arange(1,nd+1,1)
P.plot(movave(do,5),movave(N.mean(N.sum(doy[80:120:,1:,:],0),0),5),color='r',zorder=2,label='RCM:2051-2090')
P.plot(movave(do,5),movave(N.mean(N.sum(doy[40:80:,1:,:],0),0),5),color='orange',zorder=3,label='RCM:2011-2050')
P.plot(movave(do,5),movave(N.mean(N.sum(doy[0:40:,1:,:],0),0),5),color='y',zorder=4,label='RCM:1971-2010')
#P.bar(movave(do,5),movave(N.sum(doy[0:40,0,:],0),5),color='gray',zorder=5,label='OBS:1971-2010')
P.xticks([1,30,60,90,120,150,180,210,240,270,300,330,360],['1.Jan','1.Feb','1.Mar','1.Apr','1.May','1.Jun','1.Jul','1.Aug','1.Sep','1.Oct','1.Nov','1.Dec','1.Jan'])
P.xlim(0,361)
P.ylabel(pars[par][0],fontsize=12,weight='bold')
P.legend(loc=2,shadow=True)
P.tick_params(direction='out')
P.savefig('./img/%s.png'%par,dpi=240,transparent=False,bbox_inches='tight',pad_inches=0)
if(par=='pr20jj'):
P.figure(figsize=(8,3))
P.subplot(111)
mx = N.nanmax(tmp[:,0])
for m in range(nm):
for j in range(nj):
if(tmp[j,m]>=mx):
P.plot([jo[j],jo[j]],[0.1+m,0.9+m],'m')
P.xlim(1970,2100)
P.yticks(N.arange(nm)+0.5,mods)
P.tick_params(direction='out')
P.savefig('./img/%s.png'%par,dpi=240,transparent=False,bbox_inches='tight',pad_inches=0)
if(par=='pr20an'):
f.write('%s|%s|'%(pars[par][0],par))
P.figure(figsize=(10,4))
for k in [1,2,3]:
P.subplot(1,3,k)
if(k==1): zz = N.mean(N.sum(day[0:40,1:,:],0),0);title = '1971-2010'
if(k==2): zz = N.mean(N.sum(day[40:80,1:,:],0),0);title ='1911-2050'
if(k==3): zz = N.mean(N.sum(day[80:120,1:,:],0),0);title = '2051-2090'
ratio = N.sum(zz[2:])#/N.sum(zz)
f.write('|%.1f'%ratio)
P.bar(N.arange(40),zz,0.8,color='m',ec='k',label='%i'%ratio)
P.title(title,fontsize=12,weight='bold')
P.xlim(0,10)
P.ylim(0,25)
P.legend(loc=2,shadow=True)
P.xlabel(pars[par][0],fontsize=12,weight='bold')
P.ylabel('Häufigkeit',fontsize=12,weight='bold')
P.tick_params(direction='out')
f.write('\n')
P.tight_layout()
P.savefig('./img/%s.png'%par,dpi=240,transparent=False,bbox_inches='tight',pad_inches=0)
f.close()