Changeset 402 in lmdz_wrf for trunk


Ignore:
Timestamp:
Apr 28, 2015, 1:14:35 PM (10 years ago)
Author:
lfita
Message:

Adding output matrices and more variables and attributes for information

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/checking_output.py

    r401 r402  
    8686# Available statistics
    8787Availablestats = ['min', 'max', 'mean', 'stddev']
     88LAvailablestats = {'min':'minimum', 'max':'maximum', 'mean':'mean',                  \
     89  'stddev':'standard deviation'}
     90
    8891Availableverifs = ['<', '>', '%']
     92SAvailableverifs = {'<':'lt', '>':'gt', '%':'percen'}
     93LAvailableverifs = {'<':'smaller', '>':'bigger', '%':'percentage'}
    8994
    9095#######
     
    183188print 'Checking',NVals,'parameters:',stats,'verifyed as:',statsverif.values()
    184189
     190# Creating output file
     191oobj = NetCDFFile(ofile, 'w')
     192
     193# Dimensinos
     194newdim = oobj.createDimension('stats', NVals)
     195newdim = oobj.createDimension('verif', NVals)
     196newdim = oobj.createDimension('checks', 2)
     197newdim = oobj.createDimension('Lstring', 50)
     198
     199# Variables with Dimensions values
     200newvar = oobj.createVariable('stats', 'c', ('stats', 'Lstring'))
     201newattr = ncvar.basicvardef(newvar, 'stats', 'statistics/parameters used to check',  \
     202  '-')
     203newvals = ncvar.writing_str_nc(newvar, stats, 50)
     204
     205newvar = oobj.createVariable('verifs', 'c', ('stats', 'Lstring'))
     206newattr = ncvar.basicvardef(newvar, 'verifs', 'verifications used to check', '-')
     207newvals = ncvar.writing_str_nc(newvar, stats, 50)
     208
     209newvar = oobj.createVariable('checks', 'c', ('checks', 'Lstring'))
     210newattr = ncvar.basicvardef(newvar, 'checks', 'values used to check', '-')
     211newvals = ncvar.writing_str_nc(newvar, ['computed', 'limits'], 50)
     212
     213# Global attributes
     214newattr = ncvar.set_attribute(oobj, 'script', main)
     215newattr = ncvar.set_attribute(oobj, 'version', version)
     216newattr = ncvar.set_attribute(oobj, 'author', author)
     217newattr = ncvar.set_attribute(oobj, 'institution', institution)
     218newattr = ncvar.set_attribute(oobj, 'city', city)
     219newattr = ncvar.set_attribute(oobj, 'country', country)
     220
     221newattr = ncvar.set_attribute(oobj, 'description', 'Variables from ' + opts.ncfile + \
     222  ' with a wrong value according to ' + opts.lfile)
     223
     224oobj.sync()
     225
    185226# Getting netCDF file and its values
    186227##
     
    201242    for ist in range(NVals):
    202243        stn = stats[ist]
     244        Lstn = LAvailablestats[stn]
    203245        statpos = stats.index(stn)
    204246        limitval = limitvals[vn][statpos]
     
    216258# checks
    217259        if not checking(stn,valsstats[ist,iv],verif,limitval,vn):
     260            vval = valsstats[ist,iv]
     261            Sverif = SAvailableverifs[verif[0:1]]
     262            Lverif = LAvailableverifs[verif[0:1]]
     263            if verif[0:1] != '<' and verif[0:1] != '>':
     264                Vverif = np.float(verif[1:len(verif)])
     265                VverifS = str(Vverif)
     266            else:
     267                VverifS = ''
     268
    218269            wrongstats.append(stn)
    219 
     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')
     275            vobj = oobj.variables[vn]
     276            if ncvar.searchInlist(vobj.ncattrs(),('units')):
     277                vunits = vobj.getncattr('units')
     278            else:
     279                vunits = '-'
     280
     281            dims = vobj.dimensions
     282# 1/0 Matrix with wrong values
     283            if stn == 'max':
     284                wrongvals = np.where(vals > limitval, 1, 0)
     285                newvar = oobj.createVariable(vn+'Wrong'+stn+Sverif, 'i', dims)
     286                newattr = ncvar.basicvardef(newvar, vn+'_wrong_'+stn+'_'+Sverif,     \
     287                  'wrong ' + vn + ' ' + str(vval) + ' ' + Lstn + ' ' + VverifS + ' '+\
     288                  Lverif + ' ' + str(limitval), vunits)
     289                newvar[:] = wrongvals
     290            elif stn == 'mean':
     291                newattr = ncvar.set_attribute(vobj, 'wrong_'+stn+'_'+Sverif+VverifS, \
     292                  'wrong ' + vn + ' ' + str(vval) + ' ' + Lstn + ' ' + VverifS + ' '+\
     293                  Lverif + ' ' + str(limitval))
     294            elif stn == 'min':
     295                wrongvals = np.where(vals < limitval, 1, 0)
     296                newvar = oobj.createVariable(vn+'Wrong'+stn+Sverif, 'i', dims)
     297                newattr = ncvar.basicvardef(newvar, vn+'_wrong_'+stn+'_'+Sverif,     \
     298                  'wrong ' + vn + ' ' + str(vval) + ' ' + Lstn + ' ' + VverifS + ' '+\
     299                  Lverif + ' ' + str(limitval), vunits)
     300                newvar[:] = wrongvals
     301            elif stn == 'stddev':
     302                newattr = ncvar.set_attribute(vobj, 'wrong_'+stn+'_'+Sverif+VverifS, \
     303                  'wrong ' + vn + ' ' + str(vval) + ' ' + Lstn + ' ' + VverifS + ' '+\
     304                  Lverif + ' ' + str(limitval))
     305       
    220306        if len(wrongstats) != 0: wrongVars[vn] = wrongstats
    221 
    222 ncobj.close()
     307    newattr = ncvar.set_attribute(vobj, 'wrong',                                     \
     308      ncvar.numVector_String(wrongVars[vn], ' '))
     309
     310    newvar = oobj.createVariable(vn + 'checks', 'f4', ('checks', 'stats'))
     311    newattr = ncvar.basicvardef(newvar, vn + '_checks', vn +                         \
     312      ' computed/checked', vunits)
     313    for ist in range(NVals):
     314        newvar[:,ist] = [valsstats[ist,iv], limitvals[vn][ist]]
     315
     316oobj.sync()
     317oobj.close()
    223318
    224319# Results
     
    227322print wrongVars
    228323
    229 oobj = NetCDFFile(ofile, 'w')
    230 newattr = ncvar.set_attribute(oobj, 'script', main)
    231 newattr = ncvar.set_attribute(oobj, 'version', version)
    232 newattr = ncvar.set_attribute(oobj, 'author', author)
    233 newattr = ncvar.set_attribute(oobj, 'institution', institution)
    234 newattr = ncvar.set_attribute(oobj, 'city', city)
    235 newattr = ncvar.set_attribute(oobj, 'country', country)
    236 
    237 newattr = ncvar.set_attribute(oobj, 'description', 'Variables from ' + opts.ncfile + \
    238   ' with a wrong value according to ' + opts.lfile)
    239 
    240 oobj.sync()
    241 oobj.close()
    242 
    243 for var in wrongVars.keys():
    244     ncvar.fvaradd(opts.ncfile + ':' + var, ofile)
    245     oobj = NetCDFFile(ofile ,'a')
    246     novar = oobj.variables[var]
    247     vpos = vns.index(var)
    248     for st in wrongVars[var]:
    249         statpos = stats.index(st)
    250         lval = limitvals[vn][statpos]
    251         verif = statsverif[st]
    252         vval = valsstats[statpos,vpos]
    253         newattr = ncvar.set_attribute(novar, 'wrong_' + st, str(vval) + ' ' + verif +\
    254           ' ' + str(lval))
    255        
    256 oobj.sync()
    257 oobj.close()
    258 
    259 
     324print "succesfull writting of checking output file '" + ofile + "' !!"
Note: See TracChangeset for help on using the changeset viewer.