Page2
CMIP6/Germany¶
Klimaprojektionen
Code¶
Writing JSON¶
import numpy as N
for p in ['tas','pr']:
file = '../data/icmip6_'+p+'_mon_onemean_ssp126_Germany_5lan_su_100p.dat'
ssp126 = N.genfromtxt(file,comments='#',dtype=float)
ssp126 = ssp126[:,1:]
file = '../data/icmip6_'+p+'_mon_onemean_ssp585_Germany_5lan_su_100p.dat'
ssp585 = N.genfromtxt(file,comments='#',dtype=float)
jo = N.array(ssp585[:,0],int)
ssp585 = ssp585[:,1:]
nj = len(jo)
f = open('includes/cmip6_'+p+'.json','w')
f.write('[\n')
for j in range(nj):
if((jo[j]>=1961)&(jo[j]<=2099)):
tmp = N.mean(ssp126[j,:])-N.mean(ssp126[0:30,:])
f.write('\t{\n')
f.write('\t\t"budgetYear": %i,\n'%jo[j])
f.write('\t\t"forecastYear": %i,\n'%(jo[j]))
f.write('\t\t"value": %.3f\n'%tmp)
f.write('\t},\n')
tmp = N.mean(ssp585[j,:])-N.mean(ssp585[0:30,:])
f.write('\t{\n')
f.write('\t\t"budgetYear": %i,\n'%jo[j])
f.write('\t\t"forecastYear": %i,\n'%(jo[j]))
f.write('\t\t"value": %.3f\n'%tmp)
if(jo[j]==2099):
f.write('\t}\n')
else:
f.write('\t},\n')
f.write(']\n')
f.close()
Writing CSV¶
import numpy as N
file = '../data/icmip6_tas_mon_onemean_ssp126_Germany_5lan_su_100p.dat'
tas126 = N.genfromtxt(file,comments='#',dtype=float)
jo = N.array(tas126[:,0],int)
tas126 = tas126[:,1:]
file = '../data/icmip6_tas_mon_onemean_ssp585_Germany_5lan_su_100p.dat'
tas585 = N.genfromtxt(file,comments='#',dtype=float)
tas585 = tas585[:,1:]
file = '../data/icmip6_pr_mon_onemean_ssp126_Germany_5lan_su_100p.dat'
pr126 = N.genfromtxt(file,comments='#',dtype=float)
pr126 = pr126[:,1:]
file = '../data/icmip6_pr_mon_onemean_ssp585_Germany_5lan_su_100p.dat'
pr585 = N.genfromtxt(file,comments='#',dtype=float)
pr585 = pr585[:,1:]
nj = len(jo)
mo = [1,2,3,4,5,6,7,8,9,10,11,12]
nm = len(mo)
print (jo)
f = open('./includes/cmip6.csv','w')
f.write('date,tas126,tas585,pr126,pr585\n')
for j in range(nj):
for m in range(nm):
if((jo[j]>=1961)&(jo[j]<=2099)):
f.write('%04i-%02i-01,%.1f,%.1f,%.1f,%.1f\n'%(jo[j],mo[m],tas126[j,m],tas585[j,m],pr126[j,m],pr585[j,m]))
if((jo[j]==2099)&(mo[m]==12)):
f.write('\t}\n')
else:
f.write('\t},\n')
f.close()
Writing Parallel¶
tas126 = N.cumsum(tas126,1)
tas585 = N.cumsum(tas585,1)
pr126 = N.cumsum(pr126,1)
pr585 = N.cumsum(pr585,1)
f = open('./includes/cmip6_parallel.json','w')
f.write('[\n')
for p in ['tas126','tas585','pr126','pr585']:
for j in range(nj):
if((jo[j]>=1961)&(jo[j]<=2099)):
f.write('\t{')
f.write('"species": "%s",'%p)
f.write('"Year": "%i",'%jo[j])
f.write('"00": %.3f,'%0)
for m in range(nm):
if(p=="tas126"): f.write('"%02i": %.3f'%(mo[m],tas126[j,m]))
if(p=="tas585"): f.write('"%02i": %.3f'%(mo[m],tas585[j,m]))
if(p=="pr126"): f.write('"%02i": %.3f'%(mo[m],pr126[j,m]))
if(p=="pr585"): f.write('"%02i": %.3f'%(mo[m],pr585[j,m]))
if(mo[m]!=12):
f.write(',')
if((jo[j]==2099)&(p=='pr585')):
f.write('}\n')
else:
f.write('},\n')
f.write(']\n')
f.close()