Changeset 2407 in lmdz_wrf for trunk


Ignore:
Timestamp:
Mar 12, 2019, 5:50:56 PM (6 years ago)
Author:
lfita
Message:

update and working version of the script

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/checking_output.py

    r403 r2407  
    1 ## Python script to check model outputs within a given set of values from an external ASII file
    2 # L. Fita, LMD. April 2015
     1## PyNCplot
     2## Python script to check model outputs within a given set of values from an external ASCII file
     3# L. Fita, CIMA. March 2019
    34## e.g. # checking_output.py -f histins.nc -v t2m -l 'limitsVariables.inf'
    4 ## e.g. # python checking_output.py -f limit.nc -v SST,ALB -l 'limitsVariables.inf'
     5## e.g. # checking_output.py -f limit.nc -v SST,ALB -l 'limitsVariables.inf'
    56# NOTE:
    67# `nc_var_tools.py' set of python scripts is required
     
    1213from optparse import OptionParser
    1314import nc_var_tools as ncvar
     15import generic_tools as gen
    1416
    1517main = 'checking_output.py'
     
    125127    print '    >: Error if variable has values bigger than the limit'
    126128    print '    %N: Error if variable has values +/- N % than the limit'
     129    print '  Thus each variable is checked by the n-[stats], n-[verifs] by '
     130    print '    the n-[values] as:'
     131    print '    stat[i](varname) verif[i] value[i] i=1, n'
     132    print '    e.g. _______'
     133    print '    varname min max mean stddev'
     134    print '     - < > %10 %10'
     135    print '    SST 273. 310. 300. 5.'
     136    print '    T2 200. 320. 293. 40.'
     137    print ' ------- ------ ----- ---- --- -- - '
     138    print '    error if :'
     139    print '       min(T2) < 200.'
     140    print '       max(T2) > 320.'
     141    print '       mean(T2)*0.9 < 293. or mean(T2)*1.1 > 293.'
     142    print '       stddev(T2)*0.9 < 40. or stddev(T2)*1.1 > 40.'
    127143    quit()
    128144
     
    153169
    154170for line in olval:
    155     linevals = ncvar.reduce_spaces(line)
    156     if len(linevals) != 0 and linevals[0][0:0] != '#':
     171    if len(line) < 2: continue
     172    linevals = gen.reduce_spaces(line)
     173    print 'Linevals:', linevals[0]
     174    if len(linevals) != 0 and linevals[0][0:1] != '#':
    157175#        print ili,linevals
    158176        if ili == 0:
     
    171189# Checking stats to compute
    172190for st in stats:
    173     if not ncvar.searchInlist(Availablestats,st):
     191    if not gen.searchInlist(Availablestats,st):
    174192        print errormsg
    175193        print '  ' + main + ": statistics/value '" + st + "' not ready!!"
     
    180198for st in stats:
    181199    verin = statsverif[st]
    182     if not ncvar.searchInlist(Availableverifs,verin[0:1]):
     200    if not gen.searchInlist(Availableverifs,verin[0:1]):
    183201        print errormsg
    184202        print '  ' + main + ": verification '" + verin + "' not ready!!"
     
    232250    vn = vns[iv]
    233251    print vn + '...'
    234     if not ncvar.searchInlist(filevars, vn):
     252    if not gen.searchInlist(filevars, vn):
    235253        print errormsg
    236254        print '  ' + main + ": file '" + opts.ncfile + "' does not have variable '" +\
    237255          vn + "' !!"
     256        Varns = ncobj.variables.keys()
     257        Varns.sort()
     258        print '    available ones:', Varns
    238259        quit(-1)
    239260
    240     vals = ncobj.variables[vn][:]
     261    ovals = ncobj.variables[vn]
     262
     263    vals = ovals[:]
    241264    wrongstats = []
    242265    for ist in range(NVals):
     
    268291
    269292            wrongstats.append(stn)
    270             if not ncvar.searchInlist(oobj.variables.keys(), vn):
    271                 oobj.close()
    272                 ncvar.fvaradd(opts.ncfile + ':' + vn, ofile)
    273 
    274             oobj = NetCDFFile(ofile ,'a')
     293            if not oobj.variables.has_key(vn):
     294                ncvar.add_vars(ncobj, oobj, [vn])
     295
    275296            vobj = oobj.variables[vn]
    276             if ncvar.searchInlist(vobj.ncattrs(),('units')):
     297            if gen.searchInlist(vobj.ncattrs(),('units')):
    277298                vunits = vobj.getncattr('units')
    278299            else:
     
    306327        if len(wrongstats) != 0: wrongVars[vn] = wrongstats
    307328    newattr = ncvar.set_attribute(vobj, 'wrong',                                     \
    308       ncvar.numVector_String(wrongVars[vn], ' '))
     329      gen.numVector_String(wrongVars[vn], ' '))
    309330
    310331    newvar = oobj.createVariable(vn + 'checks', 'f4', ('checks', 'stats'))
  • trunk/tools/limitsVariables.inf

    r403 r2407  
    11varname min max mean stddev
    22 - < > %10 %10
    3 ALB 0. 1. 0.5 0.5
    43SST 273. 310. 300. 5.
    5 sst 273. 310. 300. 30.
    6 t2m -70. 50. 20. 40.
     4T2 200. 320. 293. 40.
    75
Note: See TracChangeset for help on using the changeset viewer.