Changeset 503 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 15, 2015, 6:55:30 PM (10 years ago)
Author:
lfita
Message:

Working version with the new statistics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/validation_sim.py

    r502 r503  
    12431243statsn = ['minimum', 'maximum', 'mean', 'mean2', 'standard deviation']
    12441244gstatsn = ['bias', 'simobs_mean', 'sim_obsmin', 'sim_obsmax', 'sim_obsmean', 'mae',  \
    1245   'rmse', 'r_pearsoncorr', 'p_pearsoncorr']
     1245  'rmse', 'r_pearsoncorr', 'p_pearsoncorr', 'deviation_of_residuals_SDR',            \
     1246  'indef_of_efficiency_IOE', 'index_of_agreement_IOA', 'fractional_mean_bias_FMB']
    12461247ostatsn = ['number of points', 'minimum', 'maximum', 'mean', 'mean2',                \
    12471248  'standard deviation']
     
    16001601newdim = onewnc.createDimension('xaround',Ngrid*2+1)
    16011602newdim = onewnc.createDimension('yaround',Ngrid*2+1)
    1602 newdim = onewnc.createDimension('gstats',9)
     1603newdim = onewnc.createDimension('gstats',13)
    16031604newdim = onewnc.createDimension('stats',5)
    16041605newdim = onewnc.createDimension('tstats',6)
    1605 newdim = onewnc.createDimension('Nstsim, 2)
     1606newdim = onewnc.createDimension('Nstsim', 2)
    16061607
    16071608# Variable dimensions
     
    17421743# statisics obs
    17431744# Masking 'nan'
     1745    Eobsmask0 = np.where(Earrayvals[:,1] != Earrayvals[:,1], fillValueF,
     1746      Earrayvals[:,1])
    17441747    obsmask0 = np.where(arrayvals[:,1] != arrayvals[:,1], fillValueF, arrayvals[:,1])
     1748
     1749    Eobsmask = ma.masked_equal(Eobsmask0, fillValueF)
     1750    Eobsmask2 = Eobsmask*Eobsmask
    17451751    obsmask = ma.masked_equal(obsmask0, fillValueF)
    17461752    obsmask2 = obsmask*obsmask
    17471753
    1748     obsstats = np.zeros((5), dtype=np.float)
    1749     obsstats[0] = obsmask.min()
    1750     obsstats[1] = obsmask.max()
    1751     obsstats[2] = obsmask.mean()
    1752     obsstats[3] = obsmask2.mean()
    1753     obsstats[4] = np.sqrt(obsstats[3] - obsstats[2]*obsstats[2])
     1754    obsstats = np.zeros((2,5), dtype=np.float)
     1755    obsstats[0,0] = obsmask.min()
     1756    obsstats[0,1] = obsmask.max()
     1757    obsstats[0,2] = obsmask.mean()
     1758    obsstats[0,3] = obsmask2.mean()
     1759    obsstats[0,4] = np.sqrt(obsstats[0,3] - obsstats[0,2]*obsstats[0,2])
     1760
     1761    obsstats[1,0] = obsmask.min()
     1762    obsstats[1,1] = obsmask.max()
     1763    obsstats[1,2] = obsmask.mean()
     1764    obsstats[1,3] = obsmask2.mean()
     1765    obsstats[1,4] = np.sqrt(obsstats[1,3] - obsstats[1,2]*obsstats[1,2])
    17541766 
    17551767# Statistics sim-obs
     
    17581770    diffvals = np.zeros((Ncoindt), dtype=np.float)
    17591771
    1760     Ediffvals = Earrayvals[:,0] - obsmask
     1772    Ediffvals = Earrayvals[:,0] - Eobsmask
    17611773    diffvals = arrayvals[:,0] - obsmask
    17621774
     
    17691781    sumdiff2 = diff2vals.sum()
    17701782
    1771     simobsstats[0,0] = simstats[0,0] - obsstats[0]
    1772     simobsstats[0,1] = np.mean(Earrayvals[:,0]*obsmask)
     1783    simobsstats[0,0] = simstats[0,0] - obsstats[0,0]
     1784    simobsstats[0,1] = np.mean(Earrayvals[:,0]*Eobsmask)
    17731785    simobsstats[0,2] = Ediffvals.min()
    17741786    simobsstats[0,3] = Ediffvals.max()
     
    17771789    simobsstats[0,6] = np.sqrt(Ediff2vals.mean())
    17781790    simobsstats[0,7], simobsstats[0,8] = sts.mstats.pearsonr(Earrayvals[:,0],        \
    1779       obsmask)
    1780 
    1781     simobsstats[1,0] = simstats[1,0] - obsstats[0]
     1791      Eobsmask)
     1792
     1793    simobsstats[1,0] = simstats[1,0] - obsstats[1,0]
    17821794    simobsstats[1,1] = np.mean(arrayvals[:,0]*obsmask)
    17831795    simobsstats[1,2] = diffvals.min()
     
    17891801      obsmask)
    17901802# From:
    1791 #Willmott, C. J. 1981. On the validation of models. Physical Geography, 2, 184–194
    1792 #Willmott, C. J. (1984). On the evaluation of model performance in physical geography. Spatial Statistics and Models, G. L. Gaile and C. J. Willmott, eds., 443-460
    1793 #Willmott, C. J., S. G. Ackleson, R. E. Davis, J. J. Feddema, K. M. Klink, D. R. Legates, J. O'Donnell, and C. M. Rowe (1985), Statistics for the Evaluation and Comparison of Models, J. Geophys. Res., 90(C5), 8995-9005
    1794 #Legates, D. R., and G. J. McCabe Jr. (1999), Evaluating the Use of "Goodness-of-Fit" Measures in Hydrologic and Hydroclimatic Model Validation, Water Resour. Res., 35(1), 233–241
     1803#Willmott, C. J. 1981. 'On the validation of models. Physical Geography', 2, 184-194
     1804#Willmott, C. J. (1984). 'On the evaluation of model performance in physical
     1805#  geography'. Spatial Statistics and Models, G. L. Gaile and C. J. Willmott, eds.,
     1806#  443-460
     1807#Willmott, C. J., S. G. Ackleson, R. E. Davis, J. J. Feddema, K. M. Klink, D. R.
     1808#  Legates, J. O'Donnell, and C. M. Rowe (1985), 'Statistics for the Evaluation and
     1809#  Comparison of Models', J. Geophys. Res., 90(C5), 8995-9005
     1810#Legates, D. R., and G. J. McCabe Jr. (1999), 'Evaluating the Use of "Goodness-of-Fit"
     1811#   Measures in Hydrologic and Hydroclimatic Model Validation', Water Resour. Res.,
     1812#   35(1), 233-241
    17951813#
    17961814# Deviation of residuals (SDR)
    17971815    simobsstats[0,9] = np.mean(np.sqrt(np.abs((Ediffvals-simobsstats[0,0])*(Ediffvals-\
    1798       obsstats[0]))))
     1816      obsstats[0,0]))))
    17991817    simobsstats[1,9] = np.mean(np.sqrt(np.abs((diffvals-simobsstats[1,0])*(diffvals- \
    1800       obsstats[0]))))
     1818      obsstats[1,0]))))
    18011819# Index of Efficiency (IOE)
    1802     obsbias2series = (obsmask - obsstats[0])*(obsmask - obsstats[0])
     1820    Eobsbias2series = (Eobsmask - obsstats[0,0])*(Eobsmask - obsstats[0,0])
     1821    Esumobsbias2series = Eobsbias2series.sum()
     1822    obsbias2series = (obsmask - obsstats[1,0])*(obsmask - obsstats[1,0])
    18031823    sumobsbias2series = obsbias2series.sum()
    18041824
    1805     simobsstats[1,10] = 1. - Esumdiff2/(sumobsbias2series)
     1825    simobsstats[0,10] = 1. - Esumdiff2/(Esumobsbias2series)
    18061826    simobsstats[1,10] = 1. - sumdiff2/(sumobsbias2series)
    18071827# Index of Agreement (IOA)
    1808     Esimbias2series = Earrayvals[:,0] - obsstats[0]
    1809     simbias2series = arrayvals[:,0] - obsstats[0]
    1810 
    1811     obsbias2series = obsmask - obsstats[0]
     1828    Esimbias2series = Earrayvals[:,0] - obsstats[0,0]
     1829    simbias2series = arrayvals[:,0] - obsstats[1,0]
     1830
     1831    Eobsbias2series = Eobsmask - obsstats[0,0]
     1832    obsbias2series = obsmask - obsstats[1,0]
    18121833
    18131834    Eabssimbias2series = np.abs(Esimbias2series)
    18141835    abssimbias2series = np.abs(simbias2series)
    1815     absobsbias2series = obbias2series.abs()
    1816 
    1817     Eabssimobsbias2series = (Eabssimbias2series+absobsbias2series)*(Eabssimbias2series +\
    1818       absobsbias2series)
     1836    Eabsobsbias2series = np.where(Eobsbias2series<0, -Eobsbias2series, Eobsbias2series)
     1837    absobsbias2series = np.where(obsbias2series<0, -obsbias2series, obsbias2series)
     1838
     1839    Eabssimobsbias2series=(Eabssimbias2series+Eabsobsbias2series)*(Eabssimbias2series+\
     1840      Eabsobsbias2series)
    18191841    abssimobsbias2series = (abssimbias2series+absobsbias2series)*(abssimbias2series +\
    18201842      absobsbias2series)
     
    18231845    simobsstats[1,11] = 1. - sumdiff2/(abssimobsbias2series.sum())
    18241846# Fractional Mean Bias (FMB)
    1825     simobsstats[0,12] = (simstats[0,0]-obsstats[0])/(0.5*(simstats[0,0]+obsstats[0]))
    1826     simobsstats[1,12] = (simstats[1,0]-obsstats[0])/(0.5*(simstats[1,0]+obsstats[0]))
     1847    simobsstats[0,12]=(simstats[0,0]-obsstats[0,0])/(0.5*(simstats[0,0]+obsstats[0,0]))
     1848    simobsstats[1,12]=(simstats[1,0]-obsstats[1,0])/(0.5*(simstats[1,0]+obsstats[1,0]))
    18271849
    18281850# Statistics around sim values
     
    18811903
    18821904# sim Statistics
    1883     for ist in range(Nstsim):
    18841905    if not searchInlist(onewnc.variables,valvars[ivar][0] + 'stsim'):
    18851906        newvar = onewnc.createVariable(valvars[ivar][0] + 'stsim', 'f', ('Nstsim',   \
     
    18911912# obs Statistics
    18921913    if not searchInlist(onewnc.variables,valvars[ivar][1] + 'stobs'):
    1893         newvar = onewnc.createVariable(valvars[ivar][1] + 'stobs', 'f', ('stats'),   \
    1894           fill_value=fillValueF)
     1914        newvar = onewnc.createVariable(valvars[ivar][1] + 'stobs', 'f', ('Nstsim',   \
     1915          'stats'), fill_value=fillValueF)
    18951916        descvar = 'observed statisitcs: ' + valvars[ivar][1]
    18961917        basicvardef(newvar, valvars[ivar][1] + 'stobs', descvar,                     \
Note: See TracChangeset for help on using the changeset viewer.