Skip to content

Trockenjahre


Trockenjahre

Kumulierte Regensumme


Code

Importing

import sys
import numpy as N
import pylab as P
from scipy import stats as S
import statsmodels.api as sm
from scipy import signal

P.style.use('bmh')

params = {'legend.fontsize': 8,'font.family': 'serif'}
P.rcParams.update(params)

def ma(a,n=3):
    ret=N.cumsum(a,dtype=float)
    ret[n:]=ret[n:]-ret[:-n]
    return ret[n-1:]/n

Setting

ort = sys.argv[1]

basz = '%sbasz.txt'%ort

jo = N.arange(1971,2101,1);nj = len(jo)

def tmit50(inp):

    return N.mean(inp)

def nied50(inp):

    return N.sum(inp)

Running

pars = {
'nied50':'Jahresniederschlag [mm]',
'pr50jj':''}

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

for par in pars:

    print (par)

    tmp = N.zeros((nj,nm),float);tmp[:,:] = N.nan
    bas = N.zeros((nj,nm),float);bas[:,:] = N.nan

    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=='nied50'): tmp[j,m] = nied50(dat['pr'][id]);bas[j,m] = tmit50(dat['tas'][id])
                 if(par=='pr50jj'): tmp[j,m] = nied50(dat['pr'][id])

    if((par=='nied50')):

        P.figure(figsize=(8,3))

        for m in range(nm):

            zz = N.cumsum(tmp[:,m]-N.mean(tmp[:30,m]))/30.

            P.subplot(121)

            if(m==0): P.plot(jo,zz,'k',alpha=1.0,lw=0.5,zorder=10)
            else: P.plot(jo,zz,'r',alpha=0.5,lw=0.5,zorder=10)

            P.plot([2020,2020],[N.nanmin(zz),N.nanmax(zz)],'b')
            P.plot([2050,2050],[N.nanmin(zz),N.nanmax(zz)],'g')
            P.plot([2080,2080],[N.nanmin(zz),N.nanmax(zz)],'r')

            P.subplot(122)

            yy = N.cumsum(bas[:,m]-N.mean(bas[:30,m]))/30.

            co = ['b','g','r']

            i = -1

            for j in [2020,2050,2080]:

                i = i+1

                id = N.where(jo==j)[0]

                P.scatter(yy[id],zz[id],c='None',s=50,ec=co[i],lw=0.5)

        P.subplot(121)
        P.xlim(1970,2100)
        P.tick_params(direction='out')
        P.xlabel('Jahre',fontsize=10,weight='bold')
        P.ylabel(pars[par],fontsize=10,weight='bold')

        P.subplot(122)
        P.xlim(0,6)
        P.tick_params(direction='out')
        P.xlabel('Temperaturänderung [K]',fontsize=10,weight='bold')
        P.ylabel(pars[par],fontsize=10,weight='bold')

        P.tight_layout()
        P.savefig('./img/%s.png'%par,dpi=240,transparent=False,bbox_inches='tight',pad_inches=0)

    if(par=='pr50jj'):

        P.figure(figsize=(8,3))
        P.subplot(111)

        mx = N.nanmin(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],'sandybrown')

        P.xlim(1970,2100)
        P.yticks(N.arange(0,nm,1)+0.5,mods)
        P.tick_params(direction='out')
        P.savefig('./img/%s.png'%par,dpi=240,transparent=False,bbox_inches='tight',pad_inches=0)

cumnied

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
dd = N.arange(1,nd+1,1)

P.figure(figsize=(6,5))
P.subplot(111)

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)>=365):

            id = id[0:nd]

            tmp = dat['pr'][id]

            if(mod=='obs-dwd'): 

                 P.plot(dd,N.cumsum(tmp),'b',lw=0.5,alpha=1,zorder=10)

            else:

                 P.plot(dd,N.cumsum(tmp),'dodgerblue',lw=0.5,alpha=0.5)

P.plot([0,0],[0,0],'k',label='BEO:1971-2010')
P.plot([0,0],[0,0],'dodgerblue',label='MOD:1971-2100')

P.legend(loc=2,shadow=True)

P.xlim(0,365)
P.ylim(0,1500)
P.xlabel('Tag des Jahres',fontsize=12,weight='bold')
P.ylabel('Regensumme [mm]',fontsize=12,weight='bold')
P.tick_params(direction='out')

P.savefig('./img/cumnied.png',dpi=240,transparent=False,bbox_inches='tight',pad_inches=0)