Skip to content

Charts

Charts

FIGURE: Charts of absolute (bars) and annually cumulated (lines) values of daily precipitation for three selected locations in Jordan (Amman, WadiMusa, Aqaba) extracted from three different gridded data products: UERRA, ERA5 and CHIRPS.

Amman

Amman

Screenshot

Screenshot

Screenshot

WadiMusa

WadiMusa

Screenshot

Screenshot

Screenshot

Aqaba

Aqaba

Screenshot

Screenshot

Screenshot


Code

Importing

import sys
import os
import matplotlib
matplotlib.use('Agg') # Must be before importing matplotlib.pyplot or pylab!
import matplotlib.pyplot as plt
import matplotlib.pyplot as P
from mpl_toolkits.basemap import Basemap,shiftgrid,maskoceans
from matplotlib.path import Path
from matplotlib.patches import PathPatch
import shapefile
#from netCDF4 import Dataset
import numpy as N
from netCDF4 import Dataset, num2date,date2num
import datetime
from scipy import signal,stats
import matplotlib.colors as colors
#from datetime import datetime
from matplotlib.offsetbox import AnchoredText
#from scipy.interpolate import griddata
#import scipy
import matplotlib as mpl


plt.style.use('seaborn-talk')

params = {      'legend.fontsize': 8,\
                'font.family': 'serif',\
                }
plt.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

Reading

city = {

   'Amman':[35.930359,31.963158],
   'Aqaba':[35.00778,29.52667],
   'WadiMusa':[35.480125,30.321635],

}

datas = ['UERRA','ERA5','CHIRPS']

for data in datas:

     if(data=='UERRA'): file = '../../data/ClimateExplorer/tp_daily_uerra_19810101-20181231.cdf'
     if(data=='CHIRPS'): file = '../../data/ClimateExplorer/v2p0chirps_25_34-40E_29-34N.cdf'
     if(data=='ERA5'): file = '../../data/ClimateExplorer/era5_tp_daily_af_34-40E_29-34N_su.cdf'

     nc = Dataset(file,'r')
     lon = N.array(nc.variables['longitude'][:])
     lat = N.array(nc.variables['latitude'][:])
     dat = N.array(nc.variables['tp'][:])
     tim = nc.variables['time']

     print (data,dat.shape,N.max(dat),N.min(dat))

     dat[dat>1000] = N.nan

     tim = num2date(tim[:],units=tim.units,calendar=tim.calendar) 

     jj = []
     mm = []
     dd = []

     for it in tim:

         jj.append(it.year)
         mm.append(it.month)
         dd.append(it.day)

     jj = N.array(jj)
     mm = N.array(mm)
     dd = N.array(dd)

     nc.close()

     nd = dat.shape[0]
     ny = dat.shape[1]
     nx = dat.shape[2]

     jmin = N.min(jj)
     jmax = N.max(jj)

     jo = N.arange(jmin,jmax+1,1);nj = len(jo)
     do = N.arange(1,366,1);nd = len(do)

     for c in city:

         tmp = N.zeros((nj,nd),float)
         tmp[:,:] = N.nan

         distance = (lon-city[c][0])**2 + (lat-city[c][1])**2
         iy,ix = N.where(distance==distance.min())

         ix = ix[0]
         iy = iy[0]

         for j in range(nj):

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

             if(ni>365): 

                 id = id[:nd]

                 #dum = N.reshape(dat[id,iy-3:iy+4,ix-3:ix+4],(nd,7*7))                

                 tmp[j,:ni] = dat[id,iy,ix]

             else: 

                 #dum = N.reshape(dat[id,iy-3:iy+4,ix-3:ix+4],(nd,7*7))

                 tmp[j,:ni] = dat[id,iy,ix]

         fig = P.figure(figsize=(8,4))
         ax = P.subplot(111)

         for j in range(nj):

             P.bar(do,tmp[j,:],width=0.8,color='dodgerblue',lw=0.5,alpha=0.3)

         P.ylim(0,200)
         P.ylabel('Daily Precipiation [mm]',weight='bold',fontsize=12)

         P.twinx()

         for j in range(nj):

             P.plot(do,N.cumsum(tmp[j,:]),'k',lw=0.5,alpha=0.3)

         P.xlim(0,366)
         P.ylim(0,500)
         P.xticks([1,60,120,180,240,300,365],['Jan 1','Mar 1','May 1','Jul 1','Sep 1','Nov 1','Jan 1'])

         P.ylabel('Cumulative Precipiation [mm]',weight='bold',fontsize=12)

         at = AnchoredText('%s %i-%i: %s'%(data,jmin,jmax,c),prop=dict(size=8,weight='bold'),frameon=True,loc='upper left')
         at.patch.set_boxstyle("round,pad=0.,rounding_size=0.1")
         ax.add_artist(at)

         plt.savefig('./img/%s_%s.png'%(data,c),dpi=240,transparent=False,bbox_inches='tight',pad_inches=0.0)