Patterns
Long-term monthly averaged temperature and daily precipitation per
weather-type for Potsdam.
Potsdam
Fig.: Long-term monthly mean temperature and daily precipitation per
weather-type.
Europe
1981-2010 long-term averaged daily precipitation patterns per month and weather-type
used to translate weather-types into precipitation.
Code
Importing
#!/usr/bin/env python
# coding: utf-8
import os
import datetime
import matplotlib
matplotlib.use('Agg')
import numpy as N
import matplotlib.pyplot as P
from scipy import stats as S
from netCDF4 import Dataset,num2date
from mpl_toolkits.basemap import Basemap,maskoceans
from matplotlib.offsetbox import AnchoredText
P.rcParams["font.family"] = "serif"
Reading
file = '../csv/gwlneudatum.dat'
jj=N.genfromtxt(file,usecols=(2),skip_header=0,dtype="I")
mm=N.genfromtxt(file,usecols=(1),skip_header=0,dtype="I")
dd=N.genfromtxt(file,usecols=(0),skip_header=0,dtype="I")
gw=N.genfromtxt(file,usecols=(3),skip_header=0,dtype='unicode')
id = N.where((jj>=1981)&(jj<=2019))[0]
jj = jj[id]
mm = mm[id]
gw = gw[id]
go = N.array(list(set(gw)));ng = len(go)
mo = N.arange(1,13,1);nm = len(mo)
Processing
go = ['WZ','BM','TRM','TRW']
for g in go:
for m in mo:
print (g,m)
id = N.where((mm==m)&(gw==g))[0]
for i in id:
dates = '%4i-%02i-%02i'%(jj[i],mm[i],dd[i])
#os.system("cdo seldate,%s ../csv/nied_day_19610101-20191231.nc ../csv/tmp/%05i.cdf"%(dates,i))
os.system("cdo seldate,%s ../csv/prc_day_era5_1981-2019.cdf ../csv/tmp/%05i.cdf"%(dates,i))
os.system("cdo timmean -mergetime ../csv/tmp/*.cdf ../csv/cdf/%02i-%s.nc"%(m,g))
#os.system("cdo -O mergetime ../csv/tmp/*.cdf ../csv/tmp.nc")
#os.system("cdo -O timpctl,50 ../csv/tmp.nc -timmin ../csv/tmp.nc -timmax ../csv/tmp.nc ../csv/cdf/%02i-%s.nc"%(m,g))
os.system("rm ../csv/tmp/*.cdf")
Plotting
go = ['WZ','BM','TRM','TRW']
for g in go:
for m in mo:
print (g,m)
file = '../csv/cdf/%02i-%s.nc'%(m,g)
if os.path.isfile(file):
nc = Dataset(file,'r')
lons = N.array(nc.variables['longitude'][:])
lats = N.array(nc.variables['latitude'][:])
dats = N.array(nc.variables['pr'][:])*24*3600
nc.close()
print (dats.shape)
dats = dats[0,:,:]
#dats[dats<-900] = N.nan
P.figure(figsize=(6,8))
ax = P.subplot(111)
map = Basemap(projection='cyl',llcrnrlat=35.,urcrnrlat=70.,llcrnrlon=-20,urcrnrlon=30,resolution='l')
map.drawcoastlines(color='k')
map.drawcountries(linewidth=1,color='k')
map.drawlsmask(land_color = "lightgray",ocean_color="lightgray",resolution = 'h')
lon,lat = map(*N.meshgrid(lons,lats))
dat = maskoceans(lon,lat,dats)
CM = map.contourf(lon,lat,dat,levels=N.arange(5,35,5),cmap=P.get_cmap('YlGnBu'),extend='both')
cbar = map.colorbar(CM,location='right',extend='max',pad="1%",drawedges=True,ticks=N.arange(5,35,5))
cbar.set_label('nied (mm/d)',fontsize=12,weight='bold')
cbar.ax.tick_params(labelsize=8)
at = AnchoredText(r"$\varnothing$ %.1f"%N.nanmean(dat),prop=dict(size=10),frameon=True,loc='upper left')
at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(at)
at = AnchoredText("1981-2010",prop=dict(size=10),frameon=True,loc='lower right')
at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(at)
at = AnchoredText("%02i-%s"%(m,g),prop=dict(size=10),frameon=True,loc='lower left')
at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(at)
P.savefig('./img/%02i-%s.png'%(m,g),dpi=240,transparent=False,bbox_inches='tight',pad_inches=0.0)