Changeset 502 in lmdz_wrf for trunk/tools/validation_sim.py
- Timestamp:
- Jun 15, 2015, 6:26:59 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/validation_sim.py
r501 r502 1268 1268 (opts, args) = parser.parse_args() 1269 1269 1270 ####### ###### ##### #### ### ## # 1271 # Number of different statistics according to the temporal coincidence 1272 # 0: Exact time 1273 # 1: Simulation values between consecutive observed times 1274 Nstsim = 2 1275 1276 stdescsim = ['E', 'B'] 1277 Lstdescsim = ['exact time', 'between observational time-steps'] 1278 1270 1279 ####### ####### 1271 1280 ## MAIN … … 1594 1603 newdim = onewnc.createDimension('stats',5) 1595 1604 newdim = onewnc.createDimension('tstats',6) 1605 newdim = onewnc.createDimension('Nstsim, 2) 1596 1606 1597 1607 # Variable dimensions … … 1618 1628 basicvardef(newvar, 'tstatistics', 'statitics from values along time', '-') 1619 1629 writing_str_nc(newvar, ostatsn, StringLength) 1630 1631 newvar = onewnc.createVariable('ksimstatistics', 'c', ('Nstsim','StrLength')) 1632 basicvardef(newvar, 'ksimstatistics', 'kind of simulated statitics', '-') 1633 writing_str_nc(newvar, Lstdescsim, StringLength) 1634 1620 1635 1621 1636 if obskind == 'trajectory': … … 1671 1686 oFillValue = None 1672 1687 1673 # Observed values temporally around coincident times1674 # simobsvalues, simobsSvalues, simobsTvalues, simobsTtvalues, trjsim =\1675 #getting_ValidationValues(obskind, Nexactt, dims, trajpos, ovsim, ovobs, \1676 #exacttvalues, oFillValue, Ngrid)1688 # Observed values temporally exact times 1689 Esimobsvalues, EsimobsSvalues, EsimobsTvalues, EsimobsTtvalues, trjsim = \ 1690 getting_ValidationValues(obskind, Nexactt, dims, trajpos, ovsim, ovobs, \ 1691 exacttvalues, oFillValue, Ngrid) 1677 1692 1678 1693 # Observed values temporally around coincident times … … 1682 1697 1683 1698 # Re-arranging values... 1699 Earrayvals = np.array(Esimobsvalues) 1684 1700 arrayvals = np.array(simobsvalues) 1685 1701 if len(valvars[ivar]) > 2: 1686 1702 const=np.float(valvars[ivar][3]) 1687 1703 if valvars[ivar][2] == 'sumc': 1704 EsimobsSvalues = EsimobsSvalues + const 1705 Earrayvals[:,0] = Earrayvals[:,0] + const 1688 1706 simobsSvalues = simobsSvalues + const 1689 1707 arrayvals[:,0] = arrayvals[:,0] + const 1690 1708 elif valvars[ivar][2] == 'subc': 1709 EsimobsSvalues = EsimobsSvalues - const 1710 Earrayvals[:,0] = Earrayvals[:,0] - const 1691 1711 simobsSvalues = simobsSvalues - const 1692 1712 arrayvals[:,0] = arrayvals[:,0] - const 1693 1713 elif valvars[ivar][2] == 'mulc': 1714 EsimobsSvalues = EsimobsSvalues * const 1715 Earrayvals[:,0] = Earrayvals[:,0] * const 1694 1716 simobsSvalues = simobsSvalues * const 1695 1717 arrayvals[:,0] = arrayvals[:,0] * const 1696 1718 elif valvars[ivar][2] == 'divc': 1719 EsimobsSvalues = EsimobsSvalues / const 1720 Earrayvals[:,0] = Earrayvals[:,0] / const 1697 1721 simobsSvalues = simobsSvalues / const 1698 1722 arrayvals[:,0] = arrayvals[:,0] / const … … 1703 1727 1704 1728 # statisics sim 1705 simstats = np.zeros((5), dtype=np.float) 1706 simstats[0] = np.min(arrayvals[:,0]) 1707 simstats[1] = np.max(arrayvals[:,0]) 1708 simstats[2] = np.mean(arrayvals[:,0]) 1709 simstats[3] = np.mean(arrayvals[:,0]*arrayvals[:,0]) 1710 simstats[4] = np.sqrt(simstats[3] - simstats[2]*simstats[2]) 1729 simstats = np.zeros((2,5), dtype=np.float) 1730 simstats[0,0] = np.min(Earrayvals[:,0]) 1731 simstats[0,1] = np.max(Earrayvals[:,0]) 1732 simstats[0,2] = np.mean(Earrayvals[:,0]) 1733 simstats[0,3] = np.mean(Earrayvals[:,0]*Earrayvals[:,0]) 1734 simstats[0,4] = np.sqrt(simstats[0,3] - simstats[0,2]*simstats[0,2]) 1735 1736 simstats[1,0] = np.min(arrayvals[:,0]) 1737 simstats[1,1] = np.max(arrayvals[:,0]) 1738 simstats[1,2] = np.mean(arrayvals[:,0]) 1739 simstats[1,3] = np.mean(arrayvals[:,0]*arrayvals[:,0]) 1740 simstats[1,4] = np.sqrt(simstats[1,3] - simstats[1,2]*simstats[1,2]) 1711 1741 1712 1742 # statisics obs … … 1724 1754 1725 1755 # Statistics sim-obs 1726 simobsstats = np.zeros((9), dtype=np.float) 1756 simobsstats = np.zeros((2,13), dtype=np.float) 1757 Ediffvals = np.zeros((Nexactt), dtype=np.float) 1727 1758 diffvals = np.zeros((Ncoindt), dtype=np.float) 1728 1759 1760 Ediffvals = Earrayvals[:,0] - obsmask 1729 1761 diffvals = arrayvals[:,0] - obsmask 1730 1762 1731 simobsstats[0] = simstats[0] - obsstats[0] 1732 simobsstats[1] = np.mean(arrayvals[:,0]*obsmask) 1733 simobsstats[2] = np.min(diffvals) 1734 simobsstats[3] = np.max(diffvals) 1735 simobsstats[4] = np.mean(diffvals) 1736 simobsstats[5] = np.mean(np.abs(diffvals)) 1737 simobsstats[6] = np.sqrt(np.mean(diffvals*diffvals)) 1738 simobsstats[7], simobsstats[8] = sts.mstats.pearsonr(arrayvals[:,0], arrayvals[:,1]) 1763 Ediff2vals = Ediffvals*Ediffvals 1764 Esumdiff = Ediffvals.sum() 1765 Esumdiff2 = Ediff2vals.sum() 1766 1767 diff2vals = diffvals*diffvals 1768 sumdiff = diffvals.sum() 1769 sumdiff2 = diff2vals.sum() 1770 1771 simobsstats[0,0] = simstats[0,0] - obsstats[0] 1772 simobsstats[0,1] = np.mean(Earrayvals[:,0]*obsmask) 1773 simobsstats[0,2] = Ediffvals.min() 1774 simobsstats[0,3] = Ediffvals.max() 1775 simobsstats[0,4] = Ediffvals.mean() 1776 simobsstats[0,5] = np.abs(Ediffvals).mean() 1777 simobsstats[0,6] = np.sqrt(Ediff2vals.mean()) 1778 simobsstats[0,7], simobsstats[0,8] = sts.mstats.pearsonr(Earrayvals[:,0], \ 1779 obsmask) 1780 1781 simobsstats[1,0] = simstats[1,0] - obsstats[0] 1782 simobsstats[1,1] = np.mean(arrayvals[:,0]*obsmask) 1783 simobsstats[1,2] = diffvals.min() 1784 simobsstats[1,3] = diffvals.max() 1785 simobsstats[1,4] = diffvals.mean() 1786 simobsstats[1,5] = np.abs(diffvals).mean() 1787 simobsstats[1,6] = np.sqrt(diff2vals.mean()) 1788 simobsstats[1,7], simobsstats[1,8] = sts.mstats.pearsonr(arrayvals[:,0], \ 1789 obsmask) 1790 # From: 1791 #Willmott, C. J. 1981. On the validation of models. Physical Geography, 2, 184â194 1792 #Willmott, C. J. (1984). On the evaluation of model performance in physical geography. Spatial Statistics and Models, G. L. Gaile and C. J. Willmott, eds., 443-460 1793 #Willmott, C. J., S. G. Ackleson, R. E. Davis, J. J. Feddema, K. M. Klink, D. R. Legates, J. O'Donnell, and C. M. Rowe (1985), Statistics for the Evaluation and Comparison of Models, J. Geophys. Res., 90(C5), 8995-9005 1794 #Legates, D. R., and G. J. McCabe Jr. (1999), Evaluating the Use of "Goodness-of-Fit" Measures in Hydrologic and Hydroclimatic Model Validation, Water Resour. Res., 35(1), 233â241 1795 # 1796 # Deviation of residuals (SDR) 1797 simobsstats[0,9] = np.mean(np.sqrt(np.abs((Ediffvals-simobsstats[0,0])*(Ediffvals-\ 1798 obsstats[0])))) 1799 simobsstats[1,9] = np.mean(np.sqrt(np.abs((diffvals-simobsstats[1,0])*(diffvals- \ 1800 obsstats[0])))) 1801 # Index of Efficiency (IOE) 1802 obsbias2series = (obsmask - obsstats[0])*(obsmask - obsstats[0]) 1803 sumobsbias2series = obsbias2series.sum() 1804 1805 simobsstats[1,10] = 1. - Esumdiff2/(sumobsbias2series) 1806 simobsstats[1,10] = 1. - sumdiff2/(sumobsbias2series) 1807 # Index of Agreement (IOA) 1808 Esimbias2series = Earrayvals[:,0] - obsstats[0] 1809 simbias2series = arrayvals[:,0] - obsstats[0] 1810 1811 obsbias2series = obsmask - obsstats[0] 1812 1813 Eabssimbias2series = np.abs(Esimbias2series) 1814 abssimbias2series = np.abs(simbias2series) 1815 absobsbias2series = obbias2series.abs() 1816 1817 Eabssimobsbias2series = (Eabssimbias2series+absobsbias2series)*(Eabssimbias2series +\ 1818 absobsbias2series) 1819 abssimobsbias2series = (abssimbias2series+absobsbias2series)*(abssimbias2series +\ 1820 absobsbias2series) 1821 1822 simobsstats[0,11] = 1. - Esumdiff2/(Eabssimobsbias2series.sum()) 1823 simobsstats[1,11] = 1. - sumdiff2/(abssimobsbias2series.sum()) 1824 # Fractional Mean Bias (FMB) 1825 simobsstats[0,12] = (simstats[0,0]-obsstats[0])/(0.5*(simstats[0,0]+obsstats[0])) 1826 simobsstats[1,12] = (simstats[1,0]-obsstats[0])/(0.5*(simstats[1,0]+obsstats[0])) 1739 1827 1740 1828 # Statistics around sim values … … 1793 1881 1794 1882 # sim Statistics 1883 for ist in range(Nstsim): 1795 1884 if not searchInlist(onewnc.variables,valvars[ivar][0] + 'stsim'): 1796 newvar = onewnc.createVariable(valvars[ivar][0] + 'stsim', 'f', (' stats'), \1797 fill_value=fillValueF)1885 newvar = onewnc.createVariable(valvars[ivar][0] + 'stsim', 'f', ('Nstsim', \ 1886 'stats'), fill_value=fillValueF) 1798 1887 descvar = 'simulated statisitcs: ' + valvars[ivar][0] 1799 1888 basicvardef(newvar, valvars[ivar][0] + 'stsim', descvar, ovobs.getncattr('units')) … … 1811 1900 # sim-obs Statistics 1812 1901 if not searchInlist(onewnc.variables,varsimobs + 'st'): 1813 newvar = onewnc.createVariable(varsimobs + 'st', 'f', (' gstats'),\1902 newvar = onewnc.createVariable(varsimobs + 'st', 'f', ('Nstsim', 'gstats'), \ 1814 1903 fill_value=fillValueF) 1815 1904 descvar = 'simulated-observed statisitcs: ' + varsimobs
Note: See TracChangeset
for help on using the changeset viewer.