Changeset 514 in lmdz_wrf for trunk/tools/validation_sim.py


Ignore:
Timestamp:
Jun 19, 2015, 12:04:50 PM (9 years ago)
Author:
lfita
Message:

Starting to add the mean values ofr the coincident times

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/validation_sim.py

    r512 r514  
    11201120    return
    11211121
    1122 def getting_ValidationValues(okind, dimt, ds, trjpos, ovs, ovo, tvalues, oFill, Ng):
     1122def getting_ValidationValues(okind, dimt0, ds, trjpos, ovs, ovo, tvalues, oFill, Ng, kvals):
    11231123    """ Function to get the values to validate accroding to the type of observation
    11241124      okind= observational kind
    1125       dimt= number of values to retrieve
     1125      dimt0= initial number of values to retrieve
    11261126      ds= dictionary with the names of the dimensions (sim, obs)
    11271127      trjpos= positions of the multi-stations (t, Y, X) or trajectory ([Z], Y, X)
     
    11311131      oFill= Fill Value for the observations
    11321132      Ng= number of grid points around the observation
     1133      kvals= kind of values
     1134        'instantaneous':  values are taken as instantaneous values
     1135        'tbackwardSmean':  simulated values are taken as time averages from back to the point
     1136        'tbackwardOmean':  observed values are taken as time averages from back to the point
    11331137    return:
    11341138      sovalues= simulated values at the observation point and time
     
    11411145
    11421146    sovalues = []
     1147
     1148    if kvals == 'instantaneous':
     1149        dimt = dimt0
     1150    elif kvals == 'tbackwardSmean':
     1151        print '  ' + fname + ':',kvals,'!!'
     1152        dimt = len(tvalues[:,3])
     1153        print '    : initially we got',dimt0,'values which will become',dimt
     1154        quit()
     1155    elif kvals == 'tbackwardOmean':
     1156        print '  ' + fname + ':',kvals,'!!'
     1157        dimt = len(tvalues[:,2])
     1158        print '    : initially we got',dimt0,'values which will become',dimt
     1159    else:
     1160        print errormsg
     1161        print '  ' + fname + ": kind of values '" + kvals + "' not ready!!"
     1162        quit(-1)
    11431163
    11441164# Simulated values spatially around
     
    18101830    Esimobsvalues, EsimobsSvalues, EsimobsTvalues, EsimobsTtvalues, trjsim =         \
    18111831        getting_ValidationValues(obskind, Nexactt, dims, trajpos, ovsim, ovobs,      \
    1812         exacttvalues, oFillValue, Ngrid)
     1832        exacttvalues, oFillValue, Ngrid, 'instantaneous')
    18131833
    18141834# Observed values temporally around coincident times
    18151835    simobsvalues, simobsSvalues, simobsTvalues, simobsTtvalues, trjsim =             \
    18161836        getting_ValidationValues(obskind, Ncoindt, dims, trajpos, ovsim, ovobs,      \
    1817         coindtvalues, oFillValue, Ngrid)
     1837        coindtvalues, oFillValue, Ngrid, 'tbackwardaverage')
    18181838
    18191839# Re-arranging values...
     
    19681988    simobsstats[1,12]=(simstats[1,0]-obsstats[1,0])/(0.5*(simstats[1,0]+obsstats[1,0]))
    19691989
    1970 # Statistics around sim values
     1990# Statistics around sim values exact
     1991    Earoundstats = np.zeros((5,Nexactt), dtype=np.float)
     1992    for it in range(Nexactt):
     1993        Earoundstats[0,it] = np.min(EsimobsSvalues[it,])
     1994        Earoundstats[1,it] = np.max(EsimobsSvalues[it,])
     1995        Earoundstats[2,it] = np.mean(EsimobsSvalues[it,])
     1996        Earoundstats[3,it] = np.mean(EsimobsSvalues[it,]*EsimobsSvalues[it,])
     1997        Earoundstats[4,it] = np.sqrt(Earoundstats[3,it] - Earoundstats[2,it]*        \
     1998          Earoundstats[2,it])
     1999
     2000# Statistics around obs values exact
     2001    Earoundostats = np.zeros((6,Nexactt), dtype=np.float)
     2002
     2003    for it in range(Nexactt):
     2004        obsmask = ma.masked_equal(EsimobsTvalues[str(it)], fillValueF)
     2005        obsmask2 = obsmask*obsmask
     2006
     2007        Earoundostats[0,it] = len(obsmask.flatten())
     2008        Earoundostats[1,it] = obsmask.min()
     2009        Earoundostats[2,it] = obsmask.max()
     2010        Earoundostats[3,it] = obsmask.mean()
     2011        Earoundostats[4,it] = obsmask2.mean()
     2012        Earoundostats[5,it] = np.sqrt(Earoundostats[4,it] - Earoundostats[3,it]*     \
     2013          Earoundostats[3,it])
     2014
     2015# Statistics around sim values between
    19712016    aroundstats = np.zeros((5,Ncoindt), dtype=np.float)
    19722017    for it in range(Ncoindt):
     
    19782023          aroundstats[2,it])
    19792024
    1980 # Statistics around obs values
     2025# Statistics around obs values between
    19812026    aroundostats = np.zeros((6,Ncoindt), dtype=np.float)
    19822027
     
    20222067    newvar[:] = arrayvals[:,1]
    20232068
    2024 # Around values
     2069# Around values exact
     2070    if not onewnc.variables.has_key(valvars[ivar][0] + 'Earound'):
     2071        if dims.has_key('Z'):
     2072            if not onewnc.dimensions.has_key('zaround'):
     2073                newdim = onewnc.createDimension('zaround',Ngrid*2+1)
     2074                newvar = onewnc.createVariable(valvars[ivar][0] + 'Earound', 'f',    \
     2075                  ('time','zaround','yaround','xaround'), fill_value=fillValueF)
     2076        else:
     2077            newvar = onewnc.createVariable(valvars[ivar][0] + 'Earound', 'f',        \
     2078              ('time','yaround','xaround'), fill_value=fillValueF)
     2079
     2080        descvar = 'exact around simulated values +/- grid values: ' + valvars[ivar][0]
     2081        basicvardef(newvar, varsimobs + 'Earound', descvar, ovobs.getncattr('units'))
     2082        newvar[:] = EsimobsSvalues
     2083
     2084# Around values between
    20252085    if not onewnc.variables.has_key(valvars[ivar][0] + 'around'):
    20262086        if dims.has_key('Z'):
     
    20282088                newdim = onewnc.createDimension('zaround',Ngrid*2+1)
    20292089                newvar = onewnc.createVariable(valvars[ivar][0] + 'around', 'f',     \
    2030                   ('time','zaround','yaround','xaround'), fill_value=fillValueF)
     2090                  ('betweentime','zaround','yaround','xaround'),fill_value=fillValueF)
    20312091        else:
    20322092            newvar = onewnc.createVariable(valvars[ivar][0] + 'around', 'f',         \
     
    20632123        newvar[:] = simobsstats
    20642124
    2065 # around sim Statistics
     2125# around sim Statistics exact
     2126    if not searchInlist(onewnc.variables,valvars[ivar][0] + 'Estaround'):
     2127        newvar = onewnc.createVariable(valvars[ivar][0] + 'Estaround', 'f',          \
     2128          ('time','stats'), fill_value=fillValueF)
     2129        descvar = 'exact around (' +  str(Ngrid) + ', ' + str(Ngrid) +               \
     2130          ') simulated statisitcs: ' + valvars[ivar][0]
     2131        basicvardef(newvar, valvars[ivar][0] + 'Estaround', descvar,                 \
     2132          ovobs.getncattr('units'))
     2133        set_attribute(newvar, 'cell_methods', 'Etime_bnds')
     2134        newvar[:] = Earoundstats.transpose()
     2135
     2136    if not searchInlist(onewnc.variables, 'Etime_bnds'):
     2137        newvar = onewnc.createVariable('Etime_bnds','f8',('time','bnds'))
     2138        basicvardef(newvar, 'Etime_bnds', 'betweentime', obstunits )
     2139        set_attribute(newvar, 'calendar', 'standard')
     2140        newvar[:] = EsimobsTtvalues
     2141
     2142# around obs Statistics exact
     2143    if not searchInlist(onewnc.variables,valvars[ivar][1] + 'Estaround'):
     2144        newvar = onewnc.createVariable(valvars[ivar][1] + 'Estaround', 'f',          \
     2145          ('time','tstats'), fill_value=fillValueF)
     2146        descvar = 'exact around temporal observed statisitcs: ' + valvars[ivar][1]
     2147        basicvardef(newvar, valvars[ivar][1] + 'Estaround', descvar,                  \
     2148          ovobs.getncattr('units'))
     2149        set_attribute(newvar, 'cell_methods', 'Etime_bnds')
     2150
     2151        newvar[:] = aroundostats.transpose()
     2152
     2153# around sim Statistics between
    20662154    if not searchInlist(onewnc.variables,valvars[ivar][0] + 'staround'):
    20672155        newvar = onewnc.createVariable(valvars[ivar][0] + 'staround', 'f',           \
    20682156          ('betweentime','stats'), fill_value=fillValueF)
    2069         descvar = 'around (' +  str(Ngrid) + ', ' + str(Ngrid) +                     \
     2157        descvar = 'between around (' +  str(Ngrid) + ', ' + str(Ngrid) +             \
    20702158          ') simulated statisitcs: ' + valvars[ivar][0]
    20712159        basicvardef(newvar, valvars[ivar][0] + 'staround', descvar,                  \
    20722160          ovobs.getncattr('units'))
     2161        set_attribute(newvar, 'cell_methods', 'time_bnds')
    20732162        newvar[:] = aroundstats.transpose()
    20742163
     
    20792168        newvar[:] = simobsTtvalues
    20802169
    2081 # around obs Statistics
     2170# around obs Statistics between
    20822171    if not searchInlist(onewnc.variables,valvars[ivar][1] + 'staround'):
    20832172        newvar = onewnc.createVariable(valvars[ivar][1] + 'staround', 'f',           \
    20842173          ('betweentime','tstats'), fill_value=fillValueF)
    2085         descvar = 'around temporal observed statisitcs: ' + valvars[ivar][1]
     2174        descvar = 'betweem around temporal observed statisitcs: ' + valvars[ivar][1]
    20862175        basicvardef(newvar, valvars[ivar][1] + 'staround', descvar,                  \
    20872176          ovobs.getncattr('units'))
    2088         set_attribute(newvar, 'cell_methods', 'statistics')
    2089 
     2177        set_attribute(newvar, 'cell_methods', 'time_bnds')
    20902178        newvar[:] = aroundostats.transpose()
    20912179
Note: See TracChangeset for help on using the changeset viewer.