Skip to content

XYZ

Zerlegung einer klimatologischen Größe nach Himmelsrichtungen:

  • ost-west (dx)
  • nord-süd (dy)
  • höhe (dz)
  • dx+dy+dz

zeitliche Änderung der räumlichen Zerlegung nach Himmelsrichtungen.


Jahresniederschlag

  • Im Osten fällt deutlich weniger Regen als im Westen
  • Im Norden fällt mehr Regen als im Süden

OBS-DWD: 1961-2018

GCM-RCM: 1971-2090

MPI-CLM HAD-CLM
CNR-CLM ECE-CLM
MPI-RCA HAD-RCA
CNR-RCA ECE-RCA

Code

Importing

import matplotlib
matplotlib.use('Agg')

import numpy as N
import matplotlib.pyplot as P
from scipy import stats as S
from mpl_toolkits.basemap import Basemap
import statsmodels.api as sm
from netCDF4 import Dataset,num2date
import shapefile as shp
import matplotlib.path as mpath
import matplotlib.patches as mpatches
from sklearn.preprocessing import scale
from matplotlib.offsetbox import AnchoredText

P.rcParams["font.family"] = "serif"

Setting

#rcm = 'ececlm'
rcm = 'obsdwd'

def norm(inp):

    out = (inp-N.min(inp))/(N.max(inp)-N.min(inp)) 

    return out

Reading

#jo = N.arange(1971,2090,1); nj = len(jo)
jo = N.arange(1961,2019,1); nj = len(jo)

orte = N.genfromtxt('../data/csv/stations.tab',names=True,dtype=None)

no = len(orte)

xyz = N.zeros((nj,no,7),float)
dat = N.zeros((nj,no),float)
jjj = N.linspace(0,1,nj)

o = -1

for ort in orte:

    o = o+1

    #file = '../data/csv/rcp85/niedja/%05ibasz.dat'%ort['station_id']
    file = '../data/csv/obs/%05ibasz.dat'%ort['station_id']

    tmp = N.genfromtxt(file,names=True,delimiter=';',dtype=None)

    dat[:,o] = tmp[rcm][0:nj]

    xyz[:,o,0] = orte['lon'][o]
    xyz[:,o,1] = orte['lat'][o]
    xyz[:,o,2] = orte['height'][o]
    xyz[:,o,3] = jjj*orte['lon'][o]    
    xyz[:,o,4] = jjj*orte['lat'][o]
    xyz[:,o,5] = jjj*orte['height'][o]

Fitting

xyz = N.reshape(xyz,(nj*no,7))
dat = N.reshape(dat,(nj*no))

model = sm.OLS(dat,xyz,'xyz',['avg','lon','lat','lev','lontim','lattim','levtim'])
results = model.fit()
print(results.summary())

co = results.params

Processing

nc = Dataset('../data/csv/elev.0.25-deg.nc','r')

lo = N.array(nc.variables['lon'][:])
la = N.array(nc.variables['lat'][:])
le = N.array(nc.variables['data'][:])

nc.close()

ix = N.where((lo>= 5)&(lo<=16))[0]
iy = N.where((la>=47)&(la<=56))[0] 

lo = lo[ix]
la = la[iy]
le = le[0,iy,:]
le = le[:,ix]

nx = len(ix)
ny = len(iy)  

xxx = N.zeros((ny,nx),float)
yyy = N.zeros((ny,nx),float)
zzz = N.zeros((ny,nx),float)

xxt = N.zeros((ny,nx),float)
yyt = N.zeros((ny,nx),float)
zzt = N.zeros((ny,nx),float)

for y in range(ny):

    xxx[y,:] = lo*co[0]
    xxt[y,:] = lo*co[3]

for x in range(nx):

    yyy[:,x] = la*co[1]
    yyt[:,x] = la*co[4]

for y in range(ny):
    for x in range(nx):

       zzz[y,x] = le[y,x]*co[2]
       zzt[y,x] = le[y,x]*co[5]

Plotting

P.figure(figsize=(10,6))

for i in range(8):

    ax = P.subplot(2,4,1+i)

    m = Basemap(projection='merc',llcrnrlat=47.,urcrnrlat=55.,llcrnrlon=5.5,urcrnrlon=15.5,resolution='h')
    #m.drawcoastlines(color='k')
    #m.drawcountries(linewidth=1,color='k')

    x,y = m(*N.meshgrid(lo,la))    

    if(i==0): tmp = xxx-xxx.min(); lev = N.arange(0,700,50)
    if(i==1): tmp = yyy-yyy.min(); lev = N.arange(0,700,50)
    if(i==2): tmp = zzz-zzz.min(); lev = N.arange(0,700,50)
    if(i==3): tmp  = (xxx+yyy+zzz); lev = N.arange(400,1000,50)

    if(i==4): tmp = xxt; lev = N.arange(-140,160,20)
    if(i==5): tmp = yyt; lev = N.arange(-140,160,20)
    if(i==6): tmp = zzt; lev = N.arange(-140,160,20)
    if(i==7): tmp  = (xxt+yyt+zzt); lev = N.arange(-140,160,20)

    CM = m.contourf(x,y,tmp,levels=lev,cmap=P.get_cmap('PuOr'),extend='both')

    sfile = shp.Reader("../data/shp/DEU_adm0.shp")

    Path = mpath.Path

    for shape_rec in sfile.shapeRecords():
        vertices = []
        codes = []
        pts = shape_rec.shape.points
        prt = list(shape_rec.shape.parts) + [len(pts)]
        for i in range(len(prt) - 1):
            for j in range(prt[i], prt[i+1]):
                vertices.append(m(pts[j][0], pts[j][1]))
            codes += [Path.MOVETO]
            codes += [Path.LINETO] * (prt[i+1] - prt[i] -2)
            codes += [Path.CLOSEPOLY]
        clip = mpath.Path(vertices, codes)
        clip = mpatches.PathPatch(clip, edgecolor='k',facecolor='None')

    ax.add_patch(clip)

    #m.colorbar(CM)

    for c in CM.collections:
        c.set_clip_path(clip) 

    at = AnchoredText('[%.1f...%.1f]'%(tmp.min(),tmp.max()),prop=dict(size=8),frameon=True,loc='lower left')
    at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
    at.zorder = 25
    ax.add_artist(at)

    #at = AnchoredText(tit,prop=dict(size=8),frameon=True,loc='upper left')
    #at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
    #at.zorder = 25
    #ax.add_artist(at)

    P.axis('off')

P.tight_layout()

P.savefig('./img/xyz_%s.png'%rcm,dpi=240,bbox_inches='tight')