- Timestamp:
- Mar 12, 2019, 5:50:56 PM (6 years ago)
- 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 3 4 ## e.g. # checking_output.py -f histins.nc -v t2m -l 'limitsVariables.inf' 4 ## e.g. # pythonchecking_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' 5 6 # NOTE: 6 7 # `nc_var_tools.py' set of python scripts is required … … 12 13 from optparse import OptionParser 13 14 import nc_var_tools as ncvar 15 import generic_tools as gen 14 16 15 17 main = 'checking_output.py' … … 125 127 print ' >: Error if variable has values bigger than the limit' 126 128 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.' 127 143 quit() 128 144 … … 153 169 154 170 for 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] != '#': 157 175 # print ili,linevals 158 176 if ili == 0: … … 171 189 # Checking stats to compute 172 190 for st in stats: 173 if not ncvar.searchInlist(Availablestats,st):191 if not gen.searchInlist(Availablestats,st): 174 192 print errormsg 175 193 print ' ' + main + ": statistics/value '" + st + "' not ready!!" … … 180 198 for st in stats: 181 199 verin = statsverif[st] 182 if not ncvar.searchInlist(Availableverifs,verin[0:1]):200 if not gen.searchInlist(Availableverifs,verin[0:1]): 183 201 print errormsg 184 202 print ' ' + main + ": verification '" + verin + "' not ready!!" … … 232 250 vn = vns[iv] 233 251 print vn + '...' 234 if not ncvar.searchInlist(filevars, vn):252 if not gen.searchInlist(filevars, vn): 235 253 print errormsg 236 254 print ' ' + main + ": file '" + opts.ncfile + "' does not have variable '" +\ 237 255 vn + "' !!" 256 Varns = ncobj.variables.keys() 257 Varns.sort() 258 print ' available ones:', Varns 238 259 quit(-1) 239 260 240 vals = ncobj.variables[vn][:] 261 ovals = ncobj.variables[vn] 262 263 vals = ovals[:] 241 264 wrongstats = [] 242 265 for ist in range(NVals): … … 268 291 269 292 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 275 296 vobj = oobj.variables[vn] 276 if ncvar.searchInlist(vobj.ncattrs(),('units')):297 if gen.searchInlist(vobj.ncattrs(),('units')): 277 298 vunits = vobj.getncattr('units') 278 299 else: … … 306 327 if len(wrongstats) != 0: wrongVars[vn] = wrongstats 307 328 newattr = ncvar.set_attribute(vobj, 'wrong', \ 308 ncvar.numVector_String(wrongVars[vn], ' '))329 gen.numVector_String(wrongVars[vn], ' ')) 309 330 310 331 newvar = oobj.createVariable(vn + 'checks', 'f4', ('checks', 'stats')) -
trunk/tools/limitsVariables.inf
r403 r2407 1 1 varname min max mean stddev 2 2 - < > %10 %10 3 ALB 0. 1. 0.5 0.54 3 SST 273. 310. 300. 5. 5 sst 273. 310. 300. 30. 6 t2m -70. 50. 20. 40. 4 T2 200. 320. 293. 40. 7 5
Note: See TracChangeset
for help on using the changeset viewer.