Changeset 523 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 19, 2015, 6:43:07 PM (10 years ago)
Author:
lfita
Message:

Starting to re-structure to add 'closest' times

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/validation_sim.py

    r521 r523  
    14801480# Number of different statistics according to the temporal coincidence
    14811481#  0: Exact time
    1482 #  1: Simulation values between consecutive observed times
    1483 Nstsim = 2
    1484 
    1485 stdescsim = ['E', 'B']
    1486 Lstdescsim = ['exact time', 'between observational time-steps']
     1482#  1: Simulation values closest to observed times
     1483#  2: Simulation values between consecutive observed times
     1484Nstsim = 3
     1485
     1486stdescsim = ['E', 'C', 'B']
     1487Lstdescsim = ['exact time', 'cloest time', 'between observational time-steps']
    14871488
    14881489#######    #######
     
    17721773print main + ': found',Nexactt,'Temporal same values in simulation and observations'
    17731774
     1775# Sim Closest times
     1776##
     1777Nsimt = 0
     1778closesttvalues0 = []
     1779closesttvalues0st = []
     1780tsiminit = 0
     1781tsimend = 0
     1782
     1783dtsim = simobstimes[1] - simobstimes[0]
     1784
     1785for it in range(dimtsim):
     1786    ot = 0
     1787    for ito in range(ot,dimtobs-1):
     1788        if np.abs(valdimobs['T'][ito] - simobstimes[it]) <= dtsim/2.:
     1789            ot = ito
     1790            tdist = simobstimes[it] - valdimobs['T'][ito]
     1791            closesttvalues0.append([it, ito, simobstimes[it], valdimobs['T'][ito],     \
     1792              tdist])
     1793            Nsimt = Nsimt + 1
     1794            if tsiminit == 0: tsiminit=simobstimes[it]
     1795            tsimend = simobstimes[it]
     1796
     1797closesttvalues = np.array(closesttvalues0, dtype=np.float)
     1798
     1799Nclosest = len(closesttvalues[:,0])
     1800print main + ': found',Nclosest,'Simulation time-values closest to observations'
     1801
     1802if Nclosest == 0:
     1803    print warnmsg
     1804    print main + ': no cclosest times found !!'
     1805    print '  stopping it'
     1806    quit(-1)
     1807
    17741808# Sim Coincident times
    17751809##
    1776 sumsimval = 0.
    1777 sum2simval = 0.
    17781810Nsimt = 0
    17791811coindtvalues0 = []
     
    18271859newdim = onewnc.createDimension('stats',5)
    18281860newdim = onewnc.createDimension('tstats',6)
    1829 newdim = onewnc.createDimension('Nstsim', 2)
     1861newdim = onewnc.createDimension('Nstsim', 3)
    18301862
    18311863# Variable dimensions
     
    18401872basicvardef(newvar, 'obstime', 'time observations for between values', obstunits)
    18411873set_attribute(newvar, 'calendar', 'standard')
    1842 set_attribute(newvar, 'bounds', 'time_bnds')
    1843 newvar[:] = coindtvalues[:,3]
    1844 
    1845 newvar = onewnc.createVariable('betweentime','f8',('betweentime'))
    1846 basicvardef(newvar, 'obstime', 'time simulations for between values', simtunits )
    1847 set_attribute(newvar, 'calendar', 'standard')
    1848 set_attribute(newvar, 'bounds', 'time_bnds')
    1849 newvar[:] = coindtvalues[:,2]
     1874newvar[:] = closesttvalues[:,3]
    18501875
    18511876newvar = onewnc.createVariable('couple', 'c', ('couple','StrLength'))
     
    18681893basicvardef(newvar, 'ksimstatistics', 'kind of simulated statitics', '-')
    18691894writing_str_nc(newvar, Lstdescsim, StringLength)
    1870 
    18711895
    18721896if obskind == 'trajectory':
     
    19221946        oFillValue = None
    19231947
    1924 # Observed values temporally exact times
    1925     Esimobsvalues, EsimobsSvalues, EsimobsTtvalues, trjsim =                         \
    1926         getting_ValidationValues(obskind, Nexactt, dims, trajpos, ovsim, ovobs,      \
    1927         exacttvalues, oFillValue, Ngrid, 'instantaneous')
    1928 
     1948    for kst in range(Nstsim):
     1949
     1950        if stdescsim[kst] == 'E':
     1951# Observed and simualted exact times
     1952            simobsvalues, simobsSvalues, simobsTtvalues, trjsim =                    \
     1953              getting_ValidationValues(obskind, Nexactt, dims, trajpos, ovsim,       \
     1954              ovobs, exacttvalues, oFillValue, Ngrid, 'instantaneous')
     1955
     1956        elif = stdescsim[kst] == 'C':
     1957# Simualted closest to Observed times
     1958            simobsvalues, simobsSvalues, simobsTtvalues, trjsim =                    \
     1959              getting_ValidationValues(obskind, Nclosest, dims, trajpos, ovsim,      \
     1960              ovobs, closesttvalues, oFillValue, Ngrid, 'instantaneous')
     1961
     1962            newvar = onewnc.createVariable('closesttime','f8',('obstime'))
     1963            basicvardef(newvar, 'closesttime', 'time simulations closest to ' +      \
     1964              'observed values', simtunits )
     1965            set_attribute(newvar, 'calendar', 'standard')
     1966            newvar[:] = closesttvalues[:,2]
     1967
     1968        elif = stdescsim[kst] == 'B':
    19291969# Observed values temporally around coincident times
    1930     simobsvalues, simobsSvalues, simobsTtvalues, trjsim =                            \
    1931         getting_ValidationValues(obskind, Ncoindt, dims, trajpos, ovsim, ovobs,      \
    1932         coindtvalues, oFillValue, Ngrid, 'tbackwardSmean')
     1970            simobsvalues, simobsSvalues, simobsTtvalues, trjsim =                    \
     1971              getting_ValidationValues(obskind, Ncoindt, dims, trajpos, ovsim, ovobs,\
     1972              coindtvalues, oFillValue, Ngrid, 'tbackwardSmean')
     1973
     1974            newvar = onewnc.createVariable('betweentime','f8',('betweentime'))
     1975            basicvardef(newvar, 'obstime', 'time simulations for between values',    \
     1976              simtunits )
     1977            set_attribute(newvar, 'calendar', 'standard')
     1978            set_attribute(newvar, 'bounds', 'time_bnds')
     1979            newvar[:] = simobsTtvalues[:,1]
    19331980
    19341981# Re-arranging values...
    1935     Earrayvals = np.array(Esimobsvalues)
    19361982    arrayvals = np.array(simobsvalues)
    19371983    if len(valvars[ivar]) > 2:
    19381984        const=np.float(valvars[ivar][3])
    19391985        if valvars[ivar][2] == 'sumc':
    1940             EsimobsSvalues = EsimobsSvalues + const
    1941             Earrayvals[:,0] = Earrayvals[:,0] + const
    19421986            simobsSvalues = simobsSvalues + const
    19431987            arrayvals[:,0] = arrayvals[:,0] + const
    19441988        elif valvars[ivar][2] == 'subc':
    1945             EsimobsSvalues = EsimobsSvalues - const
    1946             Earrayvals[:,0] = Earrayvals[:,0] - const
    19471989            simobsSvalues = simobsSvalues - const
    19481990            arrayvals[:,0] = arrayvals[:,0] - const
    19491991        elif valvars[ivar][2] == 'mulc':
    1950             EsimobsSvalues = EsimobsSvalues * const
    1951             Earrayvals[:,0] = Earrayvals[:,0] * const
    19521992            simobsSvalues = simobsSvalues * const
    19531993            arrayvals[:,0] = arrayvals[:,0] * const
    19541994        elif valvars[ivar][2] == 'divc':
    1955             EsimobsSvalues = EsimobsSvalues / const
    1956             Earrayvals[:,0] = Earrayvals[:,0] / const
    19571995            simobsSvalues = simobsSvalues / const
    19581996            arrayvals[:,0] = arrayvals[:,0] / const
Note: See TracChangeset for help on using the changeset viewer.