- Timestamp:
- Apr 28, 2015, 1:14:35 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/checking_output.py
r401 r402 86 86 # Available statistics 87 87 Availablestats = ['min', 'max', 'mean', 'stddev'] 88 LAvailablestats = {'min':'minimum', 'max':'maximum', 'mean':'mean', \ 89 'stddev':'standard deviation'} 90 88 91 Availableverifs = ['<', '>', '%'] 92 SAvailableverifs = {'<':'lt', '>':'gt', '%':'percen'} 93 LAvailableverifs = {'<':'smaller', '>':'bigger', '%':'percentage'} 89 94 90 95 ####### … … 183 188 print 'Checking',NVals,'parameters:',stats,'verifyed as:',statsverif.values() 184 189 190 # Creating output file 191 oobj = NetCDFFile(ofile, 'w') 192 193 # Dimensinos 194 newdim = oobj.createDimension('stats', NVals) 195 newdim = oobj.createDimension('verif', NVals) 196 newdim = oobj.createDimension('checks', 2) 197 newdim = oobj.createDimension('Lstring', 50) 198 199 # Variables with Dimensions values 200 newvar = oobj.createVariable('stats', 'c', ('stats', 'Lstring')) 201 newattr = ncvar.basicvardef(newvar, 'stats', 'statistics/parameters used to check', \ 202 '-') 203 newvals = ncvar.writing_str_nc(newvar, stats, 50) 204 205 newvar = oobj.createVariable('verifs', 'c', ('stats', 'Lstring')) 206 newattr = ncvar.basicvardef(newvar, 'verifs', 'verifications used to check', '-') 207 newvals = ncvar.writing_str_nc(newvar, stats, 50) 208 209 newvar = oobj.createVariable('checks', 'c', ('checks', 'Lstring')) 210 newattr = ncvar.basicvardef(newvar, 'checks', 'values used to check', '-') 211 newvals = ncvar.writing_str_nc(newvar, ['computed', 'limits'], 50) 212 213 # Global attributes 214 newattr = ncvar.set_attribute(oobj, 'script', main) 215 newattr = ncvar.set_attribute(oobj, 'version', version) 216 newattr = ncvar.set_attribute(oobj, 'author', author) 217 newattr = ncvar.set_attribute(oobj, 'institution', institution) 218 newattr = ncvar.set_attribute(oobj, 'city', city) 219 newattr = ncvar.set_attribute(oobj, 'country', country) 220 221 newattr = ncvar.set_attribute(oobj, 'description', 'Variables from ' + opts.ncfile + \ 222 ' with a wrong value according to ' + opts.lfile) 223 224 oobj.sync() 225 185 226 # Getting netCDF file and its values 186 227 ## … … 201 242 for ist in range(NVals): 202 243 stn = stats[ist] 244 Lstn = LAvailablestats[stn] 203 245 statpos = stats.index(stn) 204 246 limitval = limitvals[vn][statpos] … … 216 258 # checks 217 259 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 218 269 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 220 306 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 316 oobj.sync() 317 oobj.close() 223 318 224 319 # Results … … 227 322 print wrongVars 228 323 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 324 print "succesfull writting of checking output file '" + ofile + "' !!"
Note: See TracChangeset
for help on using the changeset viewer.