Skip to content

Validation

Saisonality of the observed and generated weather-type sequences


1961-1990

Fig.: Comparison of the observed and generated monthly weather-type frequency: 1961-1990.


1990-2019

Fig.: Comparison of the observed and generated monthly weather-type frequency: 1990-2019.


Code

Importing

from sklearn import tree #For our Decision Tree
import pandas as pd # For our DataFrame
import pydotplus # To create our Decision Tree Graph
from IPython.display import Image  # To Display a image of our graph
import numpy as N
import pylab as P
import random
import datetime
from scipy import signal,stats

Functioning

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

Setting

P.style.use('bmh')
P.rcParams["font.family"] = "serif"
P.rcParams["legend.fontsize"] = 8
jz = 'ja'

Reading

ja = 1990
je = 2019

file = '../csv/gwlneudatum.dat' 
dat0=N.genfromtxt(file,names=True,comments='#',dtype=None,encoding='utf-8')

id = N.where((dat0['ja']>=ja)&(dat0['ja']<=je))[0]
dat0 = dat0[id]

file = '../csv/gen_%i-%i/gen_%i-%i.txt'%(ja,je,ja,je) 
dat1=N.genfromtxt(file,names=True,comments='#',dtype=None,encoding='utf-8')

go = N.array(['WA','WZ','WS','WW','SWA','SWZ','NWA','NWZ','HM','BM','TM','NA','NZ','HNA','HNZ','HB','TRM','NEA','NEZ','HFA','HFZ','HNFA','HNFZ','SEA','SEZ','SA','SZ','TB','TRW'])
mon = N.array(['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'])

ng = len(go)
nd = len(dat0)
mo = N.arange(1,13,1)
nm = len(mo)

print (go)

Processing

obs = N.zeros((nm,ng),float)
gen = N.zeros((nm,ng),float)

for g in range(ng):
    for m in range(nm):

        id = N.where((dat0['gw']==go[g])&(dat0['mo']==mo[m]))[0]
        obs[m,g] = len(id)/30.

        id = N.where((dat1['gw']==go[g])&(dat1['mo']==mo[m]))[0]
        gen[m,g] = len(id)/1000.

Plotting

gg = N.arange(ng)

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

ax = P.subplot(211)

ax.tick_params(direction='out')

P.pcolor(obs,cmap=P.get_cmap('YlGnBu'),vmin=0,vmax=8,edgecolors='k', linewidths=1)

P.xticks(gg+0.5,go,rotation=45)    
P.yticks(mo-0.5,mon)
P.title('obs: %i-%i'%(ja,je),loc='left')

for m in range(nm):
    for g in range(ng):

        P.text(g+0.5,m+0.5,'%.1f'%obs[m,g],fontsize=5,ha='center',va='center')

ax = P.subplot(212)

ax.tick_params(direction='out')

P.pcolor(gen,cmap=P.get_cmap('YlGnBu'),vmin=0,vmax=8,edgecolors='k', linewidths=1)

P.xticks(gg+0.5,go,rotation=45)    
P.yticks(mo-0.5,mon)
P.title('gen: %i-%i'%(ja,je),loc='left')

for m in range(nm):
    for g in range(ng):

        P.text(g+0.5,m+0.5,'%.1f'%gen[m,g],fontsize=5,ha='center',va='center')

P.tight_layout()
P.savefig('./img/saison_%i-%i.png'%(ja,je),dpi=240,transparent=False,bbox_inches='tight',pad_inches=0.0)