- Timestamp:
- Mar 9, 2015, 7:02:22 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/validation_sim.py
r343 r344 1018 1018 "(WRFdiagnosted variables also available: " + varNOcheckinf + ")" 1019 1019 statsn = ['minimum', 'maximum', 'mean', 'mean2', 'standard deviation'] 1020 gstatsn = ['bias', 'simobs_mean', 'sim_obsmin', 'sim_obsmax', 'sim_obsmean', 'mae', \ 1021 'rmse', 'r_pearsoncorr', 'p_pearsoncorr'] 1022 ostatsn = ['number of points', 'start', 'end', 'minimum', 'maximum', 'mean', \ 1023 'mean2', 'standard deviation'] 1020 1024 1021 1025 parser = OptionParser() … … 1334 1338 newdim = onewnc.createDimension('xaround',Ngrid*2+1) 1335 1339 newdim = onewnc.createDimension('yaround',Ngrid*2+1) 1340 newdim = onewnc.createDimension('gstats',9) 1336 1341 newdim = onewnc.createDimension('stats',5) 1342 newdim = onewnc.createDimension('tstats',8) 1337 1343 1338 1344 # Variable dimensions … … 1350 1356 basicvardef(newvar, 'statistics', 'statitics from values', '-') 1351 1357 writing_str_nc(newvar, statsn, StringLength) 1358 1359 newvar = onewnc.createVariable('gstatistics', 'c', ('gstats','StrLength')) 1360 basicvardef(newvar, 'gstatistics', 'global statitics from values', '-') 1361 writing_str_nc(newvar, gstatsn, StringLength) 1362 1363 newvar = onewnc.createVariable('tstatistics', 'c', ('tstats','StrLength')) 1364 basicvardef(newvar, 'tstatistics', 'statitics from values along time', '-') 1365 writing_str_nc(newvar, ostatsn, StringLength) 1352 1366 1353 1367 if obskind == 'trajectory': … … 1402 1416 1403 1417 ovobs = oobs.variables[valvars[ivar][1]] 1418 1419 # Simulated values spatially around coincident times 1404 1420 if dims.has_key('Z'): 1405 1421 simobsSvalues = np.zeros((Ncoindt, Ngrid*2+1, Ngrid*2+1, Ngrid*2+1), \ … … 1407 1423 else: 1408 1424 simobsSvalues = np.zeros((Ncoindt, Ngrid*2+1, Ngrid*2+1), dtype = np.float) 1425 1426 # Observed values temporally around coincident times 1427 simobsTvalues = {} 1428 simobsTtvalues = np.zeros((Ncoindt,2), dtype=np.float) 1409 1429 1410 1430 if obskind == 'multi-points': … … 1439 1459 slicevar, dimslice = slice_variable(ovsim, slicev) 1440 1460 simobsSvalues[it,:,:] = slicevar 1461 1462 if it == 0: 1463 itoi = 0 1464 itof = int(coindtvalues[it,1]) / 2 1465 elif it == Ncoindt-1: 1466 itoi = int( (ito + int(coindtvalues[it-1,1])) / 2) 1467 itof = int(coindtvalues[it,1]) 1468 else: 1469 itod = int( (ito - int(coindtvalues[it-1,1])) / 2 ) 1470 itoi = ito - itod 1471 itod = int( (int(coindtvalues[it+1,1]) - ito) / 2 ) 1472 itof = ito + itod 1473 1474 slicev = dims['T'][1] + ':' + str(itoi) + '@' + str(itof + 1) 1475 1476 slicevar, dimslice = slice_variable(ovobs, slicev) 1477 simobsTvalues[str(it)] = slicevar 1478 1479 simobsTtvalues[it,0] = valdimobs['T'][itoi] 1480 simobsTtvalues[it,1] = valdimobs['T'][itof] 1441 1481 1442 1482 elif obskind == 'trajectory': … … 1532 1572 1533 1573 # statisics obs 1534 obsmask = ma.masked_equal(arrayvals , fillValueF)1574 obsmask = ma.masked_equal(arrayvals[:,1], fillValueF) 1535 1575 obsmask2 = obsmask*obsmask 1536 1537 print 'Lluis',obsmask1538 1576 1539 1577 obsstats = np.zeros((5), dtype=np.float) … … 1545 1583 1546 1584 # Statistics sim-obs 1547 simobsstats = np.zeros(( 5), dtype=np.float)1585 simobsstats = np.zeros((9), dtype=np.float) 1548 1586 diffvals = np.zeros((Ncoindt), dtype=np.float) 1549 1587 1550 diffvals = arrayvals[:,0] - arrayvals[:,1] 1588 diffvals = arrayvals[:,0] - obsmask 1589 1551 1590 simobsstats[0] = simstats[0] - obsstats[0] 1552 simobsstats[1] = np.mean(np.abs(diffvals)) 1553 simobsstats[2] = np.sqrt(simstats[3] + obsstats[3] - 2.*simstats[2]*obsstats[2]) 1554 simobsstats[3], simobsstats[4] = sts.pearsonr(arrayvals[:,0], arrayvals[:,1]) 1555 1556 print 'Lluis means sim:',simstats[0],'obs:',obsstats[0] 1557 print 'Lluis tests rmse:',simobsstats[2], np.sqrt(np.mean(diffvals*diffvals)) 1558 1559 # Statistics around values 1591 simobsstats[1] = np.mean(arrayvals[:,0]*obsmask) 1592 simobsstats[2] = np.min(diffvals) 1593 simobsstats[3] = np.max(diffvals) 1594 simobsstats[4] = np.mean(diffvals) 1595 simobsstats[5] = np.mean(np.abs(diffvals)) 1596 simobsstats[6] = np.sqrt(np.mean(diffvals*diffvals)) 1597 simobsstats[7], simobsstats[8] = sts.pearsonr(arrayvals[:,0], arrayvals[:,1]) 1598 1599 # Statistics around sim values 1560 1600 aroundstats = np.zeros((5,Ncoindt), dtype=np.float) 1561 1601 for it in range(Ncoindt): … … 1566 1606 aroundstats[4,it] = np.sqrt(aroundstats[3,it] - aroundstats[2,it]* \ 1567 1607 aroundstats[2,it]) 1608 1609 # Statistics around obs values 1610 aroundostats = np.zeros((8,Ncoindt), dtype=np.float) 1611 1612 for it in range(Ncoindt): 1613 obsmask = ma.masked_equal(simobsTvalues[str(it)], fillValueF) 1614 obsmask2 = obsmask*obsmask 1615 1616 aroundostats[0,it] = len(obsmask.flatten()) 1617 aroundostats[1,it] = simobsTtvalues[it,0] 1618 aroundostats[2,it] = simobsTtvalues[it,1] 1619 aroundostats[3,it] = obsmask.min() 1620 aroundostats[4,it] = obsmask.max() 1621 aroundostats[5,it] = obsmask.mean() 1622 aroundostats[6,it] = obsmask2.mean() 1623 aroundostats[7,it] = np.sqrt(aroundostats[6,it] - aroundostats[5,it]* \ 1624 aroundostats[5,it]) 1568 1625 1569 1626 # Values to netCDF … … 1590 1647 newvar[:] = simobsSvalues 1591 1648 1592 # Statistics 1593 if not searchInlist(onewnc.variables,valvars[ivar][0]): 1649 # sim Statistics 1650 if not searchInlist(onewnc.variables,valvars[ivar][0] + 'stsim'): 1651 newvar = onewnc.createVariable(valvars[ivar][0] + 'stsim', 'f', ('stats'), \ 1652 fill_value=fillValueF) 1653 descvar = 'simulated statisitcs: ' + valvars[ivar][0] 1654 basicvardef(newvar, valvars[ivar][0] + 'stsim', descvar, ovobs.getncattr('units')) 1655 newvar[:] = simstats 1656 1657 # obs Statistics 1658 if not searchInlist(onewnc.variables,valvars[ivar][1] + 'stobs'): 1659 newvar = onewnc.createVariable(valvars[ivar][1] + 'stobs', 'f', ('stats'), \ 1660 fill_value=fillValueF) 1661 descvar = 'observed statisitcs: ' + valvars[ivar][1] 1662 basicvardef(newvar, valvars[ivar][1] + 'stobs', descvar, \ 1663 ovobs.getncattr('units')) 1664 newvar[:] = obsstats 1665 1666 # sim-obs Statistics 1667 if not searchInlist(onewnc.variables,varsimobs + 'st'): 1668 newvar = onewnc.createVariable(varsimobs + 'st', 'f', ('gstats'), \ 1669 fill_value=fillValueF) 1670 descvar = 'simulated-observed statisitcs: ' + varsimobs 1671 basicvardef(newvar, varsimobs + 'st', descvar, ovobs.getncattr('units')) 1672 newvar[:] = simobsstats 1673 1674 # around sim Statistics 1675 if not searchInlist(onewnc.variables,valvars[ivar][0] + 'staround'): 1594 1676 newvar = onewnc.createVariable(valvars[ivar][0] + 'staround', 'f', \ 1595 1677 ('time','stats'), fill_value=fillValueF) 1596 descvar = 'around simulated statisitcs: ' + valvars[ivar][0] 1597 basicvardef(newvar, varsimobs + 'staround', descvar, ovobs.getncattr('units')) 1678 descvar = 'around (' + str(Ngrid) + ', ' + str(Ngrid) + \ 1679 ') simulated statisitcs: ' + valvars[ivar][0] 1680 basicvardef(newvar, valvars[ivar][0] + 'staround', descvar, \ 1681 ovobs.getncattr('units')) 1598 1682 newvar[:] = aroundstats.transpose() 1683 1684 # around obs Statistics 1685 if not searchInlist(onewnc.variables,valvars[ivar][1] + 'staround'): 1686 newvar = onewnc.createVariable(valvars[ivar][1] + 'staround', 'f', \ 1687 ('time','tstats'), fill_value=fillValueF) 1688 descvar = 'around temporal observed statisitcs: ' + valvars[ivar][1] 1689 basicvardef(newvar, valvars[ivar][1] + 'staround', descvar, \ 1690 ovobs.getncattr('units')) 1691 newvar[:] = aroundostats.transpose() 1599 1692 1600 1693 onewnc.sync()
Note: See TracChangeset
for help on using the changeset viewer.