Changeset 524 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 22, 2015, 12:47:29 PM (10 years ago)
Author:
lfita
Message:

First attempt of working with 'exact', 'closest', 'between'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/validation_sim.py

    r523 r524  
    14851485
    14861486stdescsim = ['E', 'C', 'B']
     1487prestdescsim = ['exact', 'closest', 'between']
    14871488Lstdescsim = ['exact time', 'cloest time', 'between observational time-steps']
    14881489
     
    18481849
    18491850# Dimensions
    1850 newdim = onewnc.createDimension('time',None)
    1851 newdim = onewnc.createDimension('betweentime',None)
     1851for kst in range(Nstsim):
     1852    newdim = onewnc.createDimension(prestdescsim[kst] + 'time',None)
     1853    if stdescsim[kst] != 'E':
     1854        newdim = onewnc.createDimension(prestdescsim[kst] + 'obstime',None)
     1855
    18521856newdim = onewnc.createDimension('bnds',2)
    1853 newdim = onewnc.createDimension('obstime',None)
    18541857newdim = onewnc.createDimension('couple',2)
    18551858newdim = onewnc.createDimension('StrLength',StringLength)
     
    18631866# Variable dimensions
    18641867##
    1865 newvar = onewnc.createVariable('exacttime','f8',('time'))
    1866 basicvardef(newvar, 'obstime', 'exact coincident time observations and simulation', obstunits)
    1867 set_attribute(newvar, 'calendar', 'standard')
    1868 print 'Lluis Nexacttvalues:',len(exacttvalues[:,3])
    1869 newvar[:] = exacttvalues[:,3]
    1870 
    1871 newvar = onewnc.createVariable('obstime','f8',('obstime'))
    1872 basicvardef(newvar, 'obstime', 'time observations for between values', obstunits)
    1873 set_attribute(newvar, 'calendar', 'standard')
    1874 newvar[:] = closesttvalues[:,3]
    1875 
    18761868newvar = onewnc.createVariable('couple', 'c', ('couple','StrLength'))
    18771869basicvardef(newvar, 'couple', 'couples of values', '-')
     
    19471939
    19481940    for kst in range(Nstsim):
     1941        timedn = prestdescsim[kst] + 'time'
    19491942
    19501943        if stdescsim[kst] == 'E':
     
    19541947              ovobs, exacttvalues, oFillValue, Ngrid, 'instantaneous')
    19551948
     1949            vname = prestdescsim[kst] + 'time'
     1950 
     1951            newvar = onewnc.createVariable(vname,'f8', (timedn))
     1952            basicvardef(newvar, vname, 'exact coincident time observations and ' +   \
     1953              'simulation', obstunits)
     1954            set_attribute(newvar, 'calendar', 'standard')
     1955            newvar[:] = exacttvalues[:,3]
     1956
    19561957        elif = stdescsim[kst] == 'C':
    19571958# Simualted closest to Observed times
     
    19601961              ovobs, closesttvalues, oFillValue, Ngrid, 'instantaneous')
    19611962
    1962             newvar = onewnc.createVariable('closesttime','f8',('obstime'))
    1963             basicvardef(newvar, 'closesttime', 'time simulations closest to ' +      \
    1964               'observed values', simtunits )
     1963            vname = prestdescsim[kst] + 'time'
     1964
     1965            newvar = onewnc.createVariable(vname,'f8', (timedn))
     1966            basicvardef(newvar, vname, 'time simulations closest to observed values',\
     1967              obstunits )
     1968            set_attribue(newvar, 'calendar', 'standard')
     1969            newvar[:] = closesttvalues[:,2]
     1970
     1971            vname  = (prestdescsim[kst] + 'obstime'
     1972            newvar = onewnc.createVariable(vname,'f8', (vname))
     1973            basicvardef(newvar, vname, 'closest time observations', obstunits)
    19651974            set_attribute(newvar, 'calendar', 'standard')
    1966             newvar[:] = closesttvalues[:,2]
     1975            newvar[:] = closesttvalues[:,3]
    19671976
    19681977        elif = stdescsim[kst] == 'B':
     
    19721981              coindtvalues, oFillValue, Ngrid, 'tbackwardSmean')
    19731982
    1974             newvar = onewnc.createVariable('betweentime','f8',('betweentime'))
    1975             basicvardef(newvar, 'obstime', 'time simulations for between values',    \
    1976               simtunits )
     1983            vname = prestdescsim[kst] + 'time'
     1984            newvar = onewnc.createVariable(vname,'f8', (timedn))
     1985            basicvardef(newvar, vname, 'simulation time between observations',       \
     1986              obstunits )
    19771987            set_attribute(newvar, 'calendar', 'standard')
    19781988            set_attribute(newvar, 'bounds', 'time_bnds')
    19791989            newvar[:] = simobsTtvalues[:,1]
    19801990
     1991            vname = prestdescsim[kst] + 'obstime'
     1992            newvar = onewnc.createVariable(vname,'f8', (vname))
     1993            basicvardef(newvar, vname, 'observed between time', obstunits )
     1994            set_attribute(newvar, 'calendar', 'standard')
     1995            newvar[:] = np.unique(coindtvalues[:,2])
     1996
    19811997# Re-arranging values...
    1982     arrayvals = np.array(simobsvalues)
    1983     if len(valvars[ivar]) > 2:
    1984         const=np.float(valvars[ivar][3])
    1985         if valvars[ivar][2] == 'sumc':
    1986             simobsSvalues = simobsSvalues + const
    1987             arrayvals[:,0] = arrayvals[:,0] + const
    1988         elif valvars[ivar][2] == 'subc':
    1989             simobsSvalues = simobsSvalues - const
    1990             arrayvals[:,0] = arrayvals[:,0] - const
    1991         elif valvars[ivar][2] == 'mulc':
    1992             simobsSvalues = simobsSvalues * const
    1993             arrayvals[:,0] = arrayvals[:,0] * const
    1994         elif valvars[ivar][2] == 'divc':
    1995             simobsSvalues = simobsSvalues / const
    1996             arrayvals[:,0] = arrayvals[:,0] / const
    1997         else:
    1998             print errormsg
    1999             print '  ' + fname + ": operation '" + valvars[ivar][2] + "' not ready!!"
    2000             quit(-1)
     1998        arrayvals = np.array(simobsvalues)
     1999        if len(valvars[ivar]) > 2:
     2000            const=np.float(valvars[ivar][3])
     2001            if valvars[ivar][2] == 'sumc':
     2002                simobsSvalues = simobsSvalues + const
     2003                arrayvals[:,0] = arrayvals[:,0] + const
     2004            elif valvars[ivar][2] == 'subc':
     2005                simobsSvalues = simobsSvalues - const
     2006                arrayvals[:,0] = arrayvals[:,0] - const
     2007            elif valvars[ivar][2] == 'mulc':
     2008                simobsSvalues = simobsSvalues * const
     2009                arrayvals[:,0] = arrayvals[:,0] * const
     2010            elif valvars[ivar][2] == 'divc':
     2011                simobsSvalues = simobsSvalues / const
     2012                arrayvals[:,0] = arrayvals[:,0] / const
     2013            else:
     2014                print errormsg
     2015                print '  ' + fname + ": operation '"+valvars[ivar][2]+"' not ready!!"
     2016                quit(-1)
    20012017
    20022018# statisics sim
    2003     simstats = np.zeros((2,5), dtype=np.float)
    2004     simstats[0,0] = np.min(Earrayvals[:,0])
    2005     simstats[0,1] = np.max(Earrayvals[:,0])
    2006     simstats[0,2] = np.mean(Earrayvals[:,0])
    2007     simstats[0,3] = np.mean(Earrayvals[:,0]*Earrayvals[:,0])
    2008     simstats[0,4] = np.sqrt(simstats[0,3] - simstats[0,2]*simstats[0,2])
    2009 
    2010     simstats[1,0] = np.min(arrayvals[:,0])
    2011     simstats[1,1] = np.max(arrayvals[:,0])
    2012     simstats[1,2] = np.mean(arrayvals[:,0])
    2013     simstats[1,3] = np.mean(arrayvals[:,0]*arrayvals[:,0])
    2014     simstats[1,4] = np.sqrt(simstats[1,3] - simstats[1,2]*simstats[1,2])
     2019        simstats = np.zeros((Nstsim,5), dtype=np.float)
     2020        simstats[kst,0] = np.min(arrayvals[:,0])
     2021        simstats[kst,1] = np.max(arrayvals[:,0])
     2022        simstats[kst,2] = np.mean(arrayvals[:,0])
     2023        simstats[kst,3] = np.mean(arrayvals[:,0]*arrayvals[:,0])
     2024        simstats[kst,4] = np.sqrt(simstats[kst,3] - simstats[kst,2]*simstats[kst,2])
    20152025
    20162026# statisics obs
    20172027# Masking 'nan'
    2018     Eobsmask0 = np.where(Earrayvals[:,1] != Earrayvals[:,1], fillValueF,
    2019       Earrayvals[:,1])
    2020     obsmask0 = np.where(arrayvals[:,1] != arrayvals[:,1], fillValueF, arrayvals[:,1])
    2021 
    2022     Eobsmask = ma.masked_equal(Eobsmask0, fillValueF)
    2023     Eobsmask2 = Eobsmask*Eobsmask
    2024     obsmask = ma.masked_equal(obsmask0, fillValueF)
    2025     obsmask2 = obsmask*obsmask
    2026 
    2027     obsstats = np.zeros((2,5), dtype=np.float)
    2028     obsstats[0,0] = obsmask.min()
    2029     obsstats[0,1] = obsmask.max()
    2030     obsstats[0,2] = obsmask.mean()
    2031     obsstats[0,3] = obsmask2.mean()
    2032     obsstats[0,4] = np.sqrt(obsstats[0,3] - obsstats[0,2]*obsstats[0,2])
    2033 
    2034     obsstats[1,0] = obsmask.min()
    2035     obsstats[1,1] = obsmask.max()
    2036     obsstats[1,2] = obsmask.mean()
    2037     obsstats[1,3] = obsmask2.mean()
    2038     obsstats[1,4] = np.sqrt(obsstats[1,3] - obsstats[1,2]*obsstats[1,2])
    2039  
     2028        obsmask0 = np.where(arrayvals[:,1] != arrayvals[:,1], fillValueF,            \
     2029          arrayvals[:,1])
     2030
     2031        obsmask = ma.masked_equal(obsmask0, fillValueF)
     2032        obsmask2 = obsmask*obsmask
     2033
     2034        obsstats = np.zeros((Nstsim,5), dtype=np.float)
     2035        obsstats[kst,0] = obsmask.min()
     2036        obsstats[kst,1] = obsmask.max()
     2037        obsstats[kst,2] = obsmask.mean()
     2038        obsstats[kst,3] = obsmask2.mean()
     2039        obsstats[kst,4] = np.sqrt(obsstats[kst,3] - obsstats[kst,2]*obsstats[kst,2])
     2040
    20402041# Statistics sim-obs
    2041     simobsstats = np.zeros((2,13), dtype=np.float)
    2042     Ediffvals = np.zeros((Nexactt), dtype=np.float)
    2043     diffvals = np.zeros((Ncoindt), dtype=np.float)
    2044 
    2045     Ediffvals = Earrayvals[:,0] - Eobsmask
    2046     diffvals = arrayvals[:,0] - obsmask
    2047 
    2048     Ediff2vals = Ediffvals*Ediffvals
    2049     Esumdiff = Ediffvals.sum()
    2050     Esumdiff2 = Ediff2vals.sum()
    2051 
    2052     diff2vals = diffvals*diffvals
    2053     sumdiff = diffvals.sum()
    2054     sumdiff2 = diff2vals.sum()
    2055 
    2056     simobsstats[0,0] = simstats[0,0] - obsstats[0,0]
    2057     simobsstats[0,1] = np.mean(Earrayvals[:,0]*Eobsmask)
    2058     simobsstats[0,2] = Ediffvals.min()
    2059     simobsstats[0,3] = Ediffvals.max()
    2060     simobsstats[0,4] = Ediffvals.mean()
    2061     simobsstats[0,5] = np.abs(Ediffvals).mean()
    2062     simobsstats[0,6] = np.sqrt(Ediff2vals.mean())
    2063     simobsstats[0,7], simobsstats[0,8] = sts.mstats.pearsonr(Earrayvals[:,0],        \
    2064       Eobsmask)
    2065 
    2066     simobsstats[1,0] = simstats[1,0] - obsstats[1,0]
    2067     simobsstats[1,1] = np.mean(arrayvals[:,0]*obsmask)
    2068     simobsstats[1,2] = diffvals.min()
    2069     simobsstats[1,3] = diffvals.max()
    2070     simobsstats[1,4] = diffvals.mean()
    2071     simobsstats[1,5] = np.abs(diffvals).mean()
    2072     simobsstats[1,6] = np.sqrt(diff2vals.mean())
    2073     simobsstats[1,7], simobsstats[1,8] = sts.mstats.pearsonr(arrayvals[:,0],         \
    2074       obsmask)
     2042        simobsstats = np.zeros((Nstsim,13), dtype=np.float)
     2043        diffvals = np.zeros((Ncoindt), dtype=np.float)
     2044
     2045        diffvals = arrayvals[:,0] - obsmask
     2046
     2047        diff2vals = diffvals*diffvals
     2048        sumdiff = diffvals.sum()
     2049        sumdiff2 = diff2vals.sum()
     2050
     2051        simobsstats[kst,0] = simstats[kst,0] - obsstats[kst,0]
     2052        simobsstats[kst,1] = np.mean(arrayvals[:,0]*obsmask)
     2053        simobsstats[kst,2] = diffvals.min()
     2054        simobsstats[kst,3] = diffvals.max()
     2055        simobsstats[kst,4] = diffvals.mean()
     2056        simobsstats[kst,5] = np.abs(diffvals).mean()
     2057        simobsstats[kst,6] = np.sqrt(diff2vals.mean())
     2058        simobsstats[kst,7], simobsstats[kst,8] = sts.mstats.pearsonr(arrayvals[:,0], \
     2059          obsmask)
    20752060# From:
    20762061#Willmott, C. J. 1981. 'On the validation of models. Physical Geography', 2, 184-194
     
    20862071#
    20872072# Deviation of residuals (SDR)
    2088     simobsstats[0,9] = np.mean(np.sqrt(np.abs((Ediffvals-simobsstats[0,0])*(Ediffvals-\
    2089       obsstats[0,0]))))
    2090     simobsstats[1,9] = np.mean(np.sqrt(np.abs((diffvals-simobsstats[1,0])*(diffvals- \
    2091       obsstats[1,0]))))
     2073        simobsstats[kst,9] = np.mean(np.sqrt(np.abs((diffvals-simobsstats[kst,0])*   \
     2074          (diffvals-obsstats[kst,0]))))
    20922075# Index of Efficiency (IOE)
    2093     Eobsbias2series = (Eobsmask - obsstats[0,0])*(Eobsmask - obsstats[0,0])
    2094     Esumobsbias2series = Eobsbias2series.sum()
    2095     obsbias2series = (obsmask - obsstats[1,0])*(obsmask - obsstats[1,0])
    2096     sumobsbias2series = obsbias2series.sum()
    2097 
    2098     simobsstats[0,10] = 1. - Esumdiff2/(Esumobsbias2series)
    2099     simobsstats[1,10] = 1. - sumdiff2/(sumobsbias2series)
     2076        obsbias2series = (obsmask - obsstats[kst,0])*(obsmask - obsstats[kst,0])
     2077        sumobsbias2series = obsbias2series.sum()
     2078
     2079        simobsstats[kst,10] = 1. - sumdiff2/(sumobsbias2series)
    21002080# Index of Agreement (IOA)
    2101     Esimbias2series = Earrayvals[:,0] - obsstats[0,0]
    2102     simbias2series = arrayvals[:,0] - obsstats[1,0]
    2103 
    2104     Eobsbias2series = Eobsmask - obsstats[0,0]
    2105     obsbias2series = obsmask - obsstats[1,0]
    2106 
    2107     Eabssimbias2series = np.abs(Esimbias2series)
    2108     abssimbias2series = np.abs(simbias2series)
    2109     Eabsobsbias2series = np.where(Eobsbias2series<0, -Eobsbias2series, Eobsbias2series)
    2110     absobsbias2series = np.where(obsbias2series<0, -obsbias2series, obsbias2series)
    2111 
    2112     Eabssimobsbias2series=(Eabssimbias2series+Eabsobsbias2series)*(Eabssimbias2series+\
    2113       Eabsobsbias2series)
    2114     abssimobsbias2series = (abssimbias2series+absobsbias2series)*(abssimbias2series +\
    2115       absobsbias2series)
    2116 
    2117     simobsstats[0,11] = 1. - Esumdiff2/(Eabssimobsbias2series.sum())
    2118     simobsstats[1,11] = 1. - sumdiff2/(abssimobsbias2series.sum())
     2081        simbias2series = arrayvals[:,0] - obsstats[kst,0]
     2082        obsbias2series = obsmask - obsstats[kst,0]
     2083
     2084        abssimbias2series = np.abs(simbias2series)
     2085        absobsbias2series = np.where(obsbias2series<0, -obsbias2series,              \
     2086          obsbias2series)
     2087
     2088        abssimobsbias2series = (abssimbias2series+absobsbias2series)*(               \
     2089          abssimbias2series + absobsbias2series)
     2090
     2091        simobsstats[kst,11] = 1. - sumdiff2/(abssimobsbias2series.sum())
    21192092# Fractional Mean Bias (FMB)
    2120     simobsstats[0,12]=(simstats[0,0]-obsstats[0,0])/(0.5*(simstats[0,0]+obsstats[0,0]))
    2121     simobsstats[1,12]=(simstats[1,0]-obsstats[1,0])/(0.5*(simstats[1,0]+obsstats[1,0]))
    2122 
    2123 # Statistics around sim values exact
    2124     Earoundstats = np.zeros((5,Nexactt), dtype=np.float)
    2125     for it in range(Nexactt):
    2126         Earoundstats[0,it] = np.min(EsimobsSvalues[it,])
    2127         Earoundstats[1,it] = np.max(EsimobsSvalues[it,])
    2128         Earoundstats[2,it] = np.mean(EsimobsSvalues[it,])
    2129         Earoundstats[3,it] = np.mean(EsimobsSvalues[it,]*EsimobsSvalues[it,])
    2130         Earoundstats[4,it] = np.sqrt(Earoundstats[3,it] - Earoundstats[2,it]*        \
    2131           Earoundstats[2,it])
    2132 
    2133 # Statistics around sim values between
    2134     aroundstats = np.zeros((5,Ncoindt), dtype=np.float)
    2135     for it in range(Ncoindt):
    2136         aroundstats[0,it] = np.min(simobsSvalues[it,])
    2137         aroundstats[1,it] = np.max(simobsSvalues[it,])
    2138         aroundstats[2,it] = np.mean(simobsSvalues[it,])
    2139         aroundstats[3,it] = np.mean(simobsSvalues[it,]*simobsSvalues[it,])
    2140         aroundstats[4,it] = np.sqrt(aroundstats[3,it] - aroundstats[2,it]*           \
    2141           aroundstats[2,it])
    2142 
    2143 # exact sim Values to netCDF
    2144     newvar = onewnc.createVariable(valvars[ivar][0] + '_Esim', 'f', ('time'),        \
    2145       fill_value=fillValueF)
    2146     descvar = 'exact time simulated: ' + valvars[ivar][0]
    2147     basicvardef(newvar, valvars[ivar][0], descvar, ovobs.getncattr('units'))
    2148     print 'Lluis NEarratvals:',len(Earrayvals[:,0])
    2149     newvar[:] = Earrayvals[:,0]
    2150 
    2151 # exact obs Values to netCDF
    2152     newvar = onewnc.createVariable(valvars[ivar][1] + '_Eobs', 'f', ('time'),        \
    2153       fill_value=fillValueF)
    2154     descvar = 'exact time observed: ' + valvars[ivar][1]
    2155     basicvardef(newvar, valvars[ivar][1], descvar, ovobs.getncattr('units'))
    2156     newvar[:] = Earrayvals[:,1]
    2157 
    2158 # between sim Values to netCDF
    2159     newvar = onewnc.createVariable(valvars[ivar][0] + '_sim', 'f', ('betweentime'),  \
    2160       fill_value=fillValueF)
    2161     descvar = 'between observed time simulated: ' + valvars[ivar][0]
    2162     basicvardef(newvar, valvars[ivar][0], descvar, ovobs.getncattr('units'))
    2163     newvar[:] = arrayvals[:,0]
    2164 
    2165 # between obs Values to netCDF
    2166     newvar = onewnc.createVariable(valvars[ivar][1] + '_obs', 'f', ('obstime'),      \
    2167       fill_value=fillValueF)
    2168     descvar = 'observed: ' + valvars[ivar][1]
    2169     basicvardef(newvar, valvars[ivar][1], descvar, ovobs.getncattr('units'))
    2170     newvar[:] = arrayvals[:,1]
    2171 
    2172 # Around values exact
    2173     if not onewnc.variables.has_key(valvars[ivar][0] + 'Earound'):
     2093        simobsstats[ksy,12]=(simstats[ksy,0]-obsstats[kst,0])/(0.5*(simstats[kst,0] +\
     2094          obsstats[kst,0]))
     2095
     2096# Statistics around sim values
     2097        aroundstats = np.zeros((5,Ncoindt), dtype=np.float)
     2098        for it in range(Ncoindt):
     2099            aroundstats[0,it] = np.min(simobsSvalues[it,])
     2100            aroundstats[1,it] = np.max(simobsSvalues[it,])
     2101            aroundstats[2,it] = np.mean(simobsSvalues[it,])
     2102            aroundstats[3,it] = np.mean(simobsSvalues[it,]*simobsSvalues[it,])
     2103            aroundstats[4,it] = np.sqrt(aroundstats[3,it] - aroundstats[2,it]*       \
     2104              aroundstats[2,it])
     2105
     2106# sim Values to netCDF
     2107        newvar = onewnc.createVariable(valvars[ivar][0] + '_' + stdescsim[kst] +     \
     2108          'sim', 'f', (timedn), fill_value=fillValueF)
     2109        descvar = prestdescsim[kst] + ' time simulated: ' + valvars[ivar][0]
     2110        basicvardef(newvar, valvars[ivar][0], descvar, ovobs.getncattr('units'))
     2111        newvar[:] = arrayvals[:,0]
     2112
     2113# obs Values to netCDF
     2114        newvar = onewnc.createVariable(valvars[ivar][1] + '_' + stdescsim[kst] +     \
     2115          'obs', 'f', (timedn), fill_value=fillValueF)
     2116        descvar = prestdescsim[kst] + ' time simulated: ' + valvars[ivar][1]
     2117        basicvardef(newvar, valvars[ivar][1], descvar, ovobs.getncattr('units'))
     2118        newvar[:] = arrayvals[:,1]
     2119
     2120# Around values
     2121        if not onewnc.variables.has_key(valvars[ivar][0] + 'around'):
     2122            vname = prestdescsim[kst] + valvars[ivar][0] + 'around'
     2123        else:
     2124            vname = prestdescsim[kst] + valvars[ivar][0] + 'Around'
     2125
    21742126        if dims.has_key('Z'):
    21752127            if not onewnc.dimensions.has_key('zaround'):
    21762128                newdim = onewnc.createDimension('zaround',Ngrid*2+1)
    2177                 newvar = onewnc.createVariable(valvars[ivar][0] + 'Earound', 'f',    \
    2178                   ('time','zaround','yaround','xaround'), fill_value=fillValueF)
     2129                newvar = onewnc.createVariable(vname, 'f', (timedn,'zaround',        \
     2130                  'yaround','xaround'), fill_value=fillValueF)
    21792131        else:
    2180             newvar = onewnc.createVariable(valvars[ivar][0] + 'Earound', 'f',        \
    2181               ('time','yaround','xaround'), fill_value=fillValueF)
    2182 
    2183         descvar = 'exact around simulated values +/- grid values: ' + valvars[ivar][0]
    2184         basicvardef(newvar, varsimobs + 'Earound', descvar, ovobs.getncattr('units'))
    2185         newvar[:] = EsimobsSvalues
    2186 
    2187 # Around values between
    2188     if not onewnc.variables.has_key(valvars[ivar][0] + 'around'):
    2189         if dims.has_key('Z'):
    2190             if not onewnc.dimensions.has_key('zaround'):
    2191                 newdim = onewnc.createDimension('zaround',Ngrid*2+1)
    2192                 newvar = onewnc.createVariable(valvars[ivar][0] + 'around', 'f',     \
    2193                   ('betweentime','zaround','yaround','xaround'),fill_value=fillValueF)
     2132            newvar = onewnc.createVariable(vname, 'f', (timedn,'yaround','xaround'), \
     2133              fill_value=fillValueF)
     2134
     2135        descvar = prestdescsim[kst] + 'around simulated values +/- grid values: ' +  \
     2136          valvars[ivar][0]
     2137        basicvardef(newvar, vname, descvar, ovobs.getncattr('units'))
     2138        newvar[:] = simobsSvalues
     2139
     2140
     2141# around sim Statistics between
     2142        if not searchInlist(onewnc.variables,prestdescsim[kst] + valvars[ivar][0] +  \
     2143          'staround'):
     2144            vname = prestdescsim[kst] + valvars[ivar][0] + 'staround'
    21942145        else:
    2195             newvar = onewnc.createVariable(valvars[ivar][0] + 'around', 'f',         \
    2196               ('betweentime','yaround','xaround'), fill_value=fillValueF)
    2197 
    2198         descvar = 'around simulated values +/- grid values: ' + valvars[ivar][0]
    2199         basicvardef(newvar, varsimobs + 'around', descvar, ovobs.getncattr('units'))
    2200         newvar[:] = simobsSvalues
     2146            vname = prestdescsim[kst] + valvars[ivar][0] + 'Staround'
     2147
     2148        newvar = onewnc.createVariable(vname, 'f', (timedn,'stats'),                 \
     2149          fill_value=fillValueF)
     2150        descvar = prestdescsim[kst] + ' around (' +  str(Ngrid) + ', ' + str(Ngrid) +\
     2151          ') simulated statisitcs: ' + valvars[ivar][0]
     2152        basicvardef(newvar, vname, descvar, ovobs.getncattr('units'))
     2153        set_attribute(newvar, 'cell_methods', 'time_bnds')
     2154        newvar[:] = aroundstats.transpose()
     2155
     2156        if stdescsim[kst] == 'B':
     2157            if not searchInlist(onewnc.variables, 'time_bnds'):
     2158                newvar = onewnc.createVariable('time_bnds','f8',(imedn,'bnds'))
     2159                basicvardef(newvar, 'time_bnds', timedn, obstunits )
     2160                set_attribute(newvar, 'calendar', 'standard')
     2161                newvar[:] = simobsTtvalues
     2162
     2163# around obs Statistics between
     2164        if not searchInlist(onewnc.variables, prestdescsim[kst] + valvars[ivar][1] + \
     2165          'staround'):
     2166            vname = prestdescsim[kst] + valvars[ivar][1] + 'staround'
     2167        else:
     2168            vname = prestdescsim[kst] + valvars[ivar][1] + 'Staround'
     2169
     2170        newvar = onewnc.createVariable(vname, 'f', (timedn,'tstats'),                \
     2171          fill_value=fillValueF)
     2172        descvar = prestdescsim[kst] + ' around temporal observed statisitcs: ' +     \
     2173          valvars[ivar][1]
     2174        basicvardef(newvar, vname, descvar, ovobs.getncattr('units'))
     2175        set_attribute(newvar, 'cell_methods', 'time_bnds')
     2176        newvar[:] = aroundostats.transpose()
    22012177
    22022178# sim Statistics
    22032179    if not searchInlist(onewnc.variables,valvars[ivar][0] + 'stsim'):
    2204         newvar = onewnc.createVariable(valvars[ivar][0] + 'stsim', 'f', ('Nstsim',   \
    2205           'stats'), fill_value=fillValueF)
    2206         descvar = 'simulated statisitcs: ' + valvars[ivar][0]
    2207         basicvardef(newvar, valvars[ivar][0] + 'stsim', descvar,                     \
    2208           ovobs.getncattr('units'))
    2209         newvar[:] = simstats
     2180        vname = valvars[ivar][0] + 'stsim'
     2181    else:
     2182        vname = valvars[ivar][0] + 'stSim'
     2183
     2184    newvar = onewnc.createVariable(vname, 'f', ('Nstsim', 'stats'),                  \
     2185      fill_value=fillValueF)
     2186    descvar = 'simulated statisitcs: ' + valvars[ivar][0]
     2187    basicvardef(newvar, vname, descvar, ovobs.getncattr('units'))
     2188    newvar[:] = simstats
    22102189
    22112190# obs Statistics
    22122191    if not searchInlist(onewnc.variables,valvars[ivar][1] + 'stobs'):
    2213         newvar = onewnc.createVariable(valvars[ivar][1] + 'stobs', 'f', ('Nstsim',   \
    2214           'stats'), fill_value=fillValueF)
    2215         descvar = 'observed statisitcs: ' + valvars[ivar][1]
    2216         basicvardef(newvar, valvars[ivar][1] + 'stobs', descvar,                     \
    2217           ovobs.getncattr('units'))
    2218         newvar[:] = obsstats
     2192        vname = valvars[ivar][1] + 'stobs'
     2193    else:
     2194        vname = valvars[ivar][1] + 'stObs'
     2195
     2196    newvar = onewnc.createVariable(vname, 'f', ('Nstsim', 'stats'),                  \
     2197      fill_value=fillValueF)
     2198    descvar = 'observed statisitcs: ' + valvars[ivar][1]
     2199    basicvardef(newvar, vname, descvar, ovobs.getncattr('units'))
     2200    newvar[:] = obsstats
    22192201
    22202202# sim-obs Statistics
    22212203    if not searchInlist(onewnc.variables,varsimobs + 'st'):
    2222         newvar = onewnc.createVariable(varsimobs + 'st', 'f', ('Nstsim', 'gstats'),  \
    2223           fill_value=fillValueF)
    2224         descvar = 'simulated-observed tatisitcs: ' + varsimobs
    2225         basicvardef(newvar, varsimobs + 'st', descvar, ovobs.getncattr('units'))
    2226         newvar[:] = simobsstats
    2227 
    2228 # around sim Statistics exact
    2229     if not searchInlist(onewnc.variables,valvars[ivar][0] + 'Estaround'):
    2230         newvar = onewnc.createVariable(valvars[ivar][0] + 'Estaround', 'f',          \
    2231           ('time','stats'), fill_value=fillValueF)
    2232         descvar = 'exact around (' +  str(Ngrid) + ', ' + str(Ngrid) +               \
    2233           ') simulated statisitcs: ' + valvars[ivar][0]
    2234         basicvardef(newvar, valvars[ivar][0] + 'Estaround', descvar,                 \
    2235           ovobs.getncattr('units'))
    2236         set_attribute(newvar, 'cell_methods', 'Etime_bnds')
    2237         newvar[:] = Earoundstats.transpose()
    2238 
    2239     if not searchInlist(onewnc.variables, 'Etime_bnds'):
    2240         newvar = onewnc.createVariable('Etime_bnds','f8',('time','bnds'))
    2241         basicvardef(newvar, 'Etime_bnds', 'betweentime', obstunits )
    2242         set_attribute(newvar, 'calendar', 'standard')
    2243         newvar[:] = EsimobsTtvalues
    2244 
    2245 # around obs Statistics exact
    2246     if not searchInlist(onewnc.variables,valvars[ivar][1] + 'Estaround'):
    2247         newvar = onewnc.createVariable(valvars[ivar][1] + 'Estaround', 'f',          \
    2248           ('time','tstats'), fill_value=fillValueF)
    2249         descvar = 'exact around temporal observed statisitcs: ' + valvars[ivar][1]
    2250         basicvardef(newvar, valvars[ivar][1] + 'Estaround', descvar,                  \
    2251           ovobs.getncattr('units'))
    2252         set_attribute(newvar, 'cell_methods', 'Etime_bnds')
    2253 
    2254         newvar[:] = aroundostats.transpose()
    2255 
    2256 # around sim Statistics between
    2257     if not searchInlist(onewnc.variables,valvars[ivar][0] + 'staround'):
    2258         newvar = onewnc.createVariable(valvars[ivar][0] + 'staround', 'f',           \
    2259           ('betweentime','stats'), fill_value=fillValueF)
    2260         descvar = 'between around (' +  str(Ngrid) + ', ' + str(Ngrid) +             \
    2261           ') simulated statisitcs: ' + valvars[ivar][0]
    2262         basicvardef(newvar, valvars[ivar][0] + 'staround', descvar,                  \
    2263           ovobs.getncattr('units'))
    2264         set_attribute(newvar, 'cell_methods', 'time_bnds')
    2265         newvar[:] = aroundstats.transpose()
    2266 
    2267     if not searchInlist(onewnc.variables, 'time_bnds'):
    2268         newvar = onewnc.createVariable('time_bnds','f8',('betweentime','bnds'))
    2269         basicvardef(newvar, 'time_bnds', 'betweentime', obstunits )
    2270         set_attribute(newvar, 'calendar', 'standard')
    2271         newvar[:] = simobsTtvalues
    2272 
    2273 # around obs Statistics between
    2274     if not searchInlist(onewnc.variables,valvars[ivar][1] + 'staround'):
    2275         newvar = onewnc.createVariable(valvars[ivar][1] + 'staround', 'f',           \
    2276           ('betweentime','tstats'), fill_value=fillValueF)
    2277         descvar = 'betweem around temporal observed statisitcs: ' + valvars[ivar][1]
    2278         basicvardef(newvar, valvars[ivar][1] + 'staround', descvar,                  \
    2279           ovobs.getncattr('units'))
    2280         set_attribute(newvar, 'cell_methods', 'time_bnds')
    2281         newvar[:] = aroundostats.transpose()
    2282 
    2283         onewnc.sync()
     2204        vname = varsimobs + 'st'
     2205    else:
     2206        vname = varSimobs + 'st'
     2207
     2208    newvar = onewnc.createVariable(vname, 'f', ('Nstsim', 'gstats'),                 \
     2209      fill_value=fillValueF)
     2210    descvar = 'simulated-observed tatisitcs: ' + varsimobs
     2211    basicvardef(newvar, vname, descvar, ovobs.getncattr('units'))
     2212    newvar[:] = simobsstats
     2213
     2214    onewnc.sync()
    22842215
    22852216if trjsim is not None:
Note: See TracChangeset for help on using the changeset viewer.