Changeset 498 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 15, 2015, 4:17:24 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/validation_sim.py
r497 r498 1035 1035 return 1036 1036 1037 def getting_ValidationValues(okind, dimt, ds, trjpos, ovs, ovo, tvalues, o fill, Ng):1037 def getting_ValidationValues(okind, dimt, ds, trjpos, ovs, ovo, tvalues, oFill, Ng): 1038 1038 """ Function to get the values to validate accroding to the type of observation 1039 1039 okind= observational kind … … 1044 1044 ovs= object with the values of the observations 1045 1045 tvalues= temporal values (sim. time step, obs. time step, sim t value, obs t value, t diff) 1046 o fill= Fill Value for the observations1046 oFill= Fill Value for the observations 1047 1047 Ng= number of grid points around the observation 1048 1048 return: 1049 1049 sovalues= simulated values at the observation point and time 1050 1050 soSvalues= values Ngrid points around the simulated point 1051 soTvalues= inital/ending period between two consecutive obsevations (for `single-station') 1051 soTvalues= values around observed times (for `single-station') 1052 soTtvalues= inital/ending period between two consecutive obsevations (for `single-station') 1052 1053 trjs= trajectory on the simulation space 1053 1054 """ … … 1063 1064 trjs = np.zeros((4,dimt), dtype=int) 1064 1065 else: 1065 trj S= None1066 trjs = None 1066 1067 else: 1067 1068 soSvalues = np.zeros((dimt, Ng*2+1, Ng*2+1), dtype = np.float) … … 1069 1070 trjs = np.zeros((3,dimt), dtype=int) 1070 1071 else: 1071 trj S= None1072 trjs = None 1072 1073 1073 1074 if okind == 'single-station': … … 1206 1207 1207 1208 1208 return sovalues, soSvalues, soTvalues, trjs1209 return sovalues, soSvalues, soTvalues, soTtvalues, trjs 1209 1210 1210 1211 … … 1445 1446 [valdimobs['X'][it],valdimobss['Y'][it]]) 1446 1447 elif obskind == 'single-station': 1448 trajpos = None 1447 1449 stationpos = np.zeros((2), dtype=int) 1448 1450 if valdimsim.has_key('X') and valdimsim.has_key('Y'): … … 1570 1572 'observed times) coincident times between simulation and observations' 1571 1573 print ' ',coindtvalues 1572 quit()1573 1574 1574 1575 if Ncoindt == 0: … … 1668 1669 if searchInlist(ovobs.ncattrs(),'_FillValue'): 1669 1670 oFillValue = ovobs.getncattr('_FillValue') 1670 1671 simobsvalues, simobsSvalues, simobsTvalues, trjsim = \ 1671 else: 1672 oFillValue = None 1673 1674 # Observed values temporally around coincident times 1675 simobsvalues, simobsSvalues, simobsTvalues, simobsTtvalues, trjsim = \ 1672 1676 getting_ValidationValues(obskind, Ncoindt, dims, trajpos, ovsim, ovobs, \ 1673 coindtvalues, ofillValue, Ngrid) 1674 quit(-1) 1675 1676 1677 # Simulated values spatially around coincident times 1678 if dims.has_key('Z'): 1679 simobsSvalues = np.zeros((Ncoindt, Ngrid*2+1, Ngrid*2+1, Ngrid*2+1), \ 1680 dtype = np.float) 1681 else: 1682 simobsSvalues = np.zeros((Ncoindt, Ngrid*2+1, Ngrid*2+1), dtype = np.float) 1683 1684 # Observed values temporally around coincident times 1685 simobsTvalues = {} 1686 simobsTtvalues = np.zeros((Ncoindt,2), dtype=np.float) 1687 1688 if obskind == 'multi-points': 1689 for it in range(Ncoindt): 1690 slicev = dims['X'][0] + ':' + str(trajpos[2,it]) + '|' + \ 1691 dims['Y'][0]+ ':' + str(trajpos[1,it]) + '|' + \ 1692 dims['T'][0]+ ':' + str(coindtvalues[it][0]) 1693 slicevar, dimslice = slice_variable(ovsim, slicev) 1694 simobsvalues.append([ slicevar, ovobs[coindtvalues[it][1]]]) 1695 slicev = dims['X'][0] + ':' + str(trajpos[2,it]-Ngrid) + '@' + \ 1696 str(trajpos[2,it]+Ngrid) + '|' + dims['Y'][0] + ':' + \ 1697 str(trajpos[1,it]-Ngrid) + '@' + str(trajpos[1,it]+Ngrid) + '|' + \ 1698 dims['T'][0]+':'+str(coindtvalues[it][0]) 1699 slicevar, dimslice = slice_variable(ovsim, slicev) 1700 simobsSvalues[it,:,:] = slicevar 1701 1702 elif obskind == 'single-station': 1703 for it in range(Ncoindt): 1704 ito = int(coindtvalues[it,1]) 1705 if valdimsim.has_key('X') and valdimsim.has_key('Y'): 1706 slicev = dims['X'][0] + ':' + str(stationpos[1]) + '|' + \ 1707 dims['Y'][0] + ':' + str(stationpos[0]) + '|' + \ 1708 dims['T'][0] + ':' + str(int(coindtvalues[it][0])) 1709 else: 1710 slicev = dims['T'][0] + ':' + str(int(coindtvalues[it][0])) 1711 slicevar, dimslice = slice_variable(ovsim, slicev) 1712 if ovobs[int(ito)] == oFillValue or ovobs[int(ito)] == '--': 1713 simobsvalues.append([ slicevar, fillValueF]) 1714 # elif ovobs[int(ito)] != ovobs[int(ito)]: 1715 # simobsvalues.append([ slicevar, fillValueF]) 1716 else: 1717 simobsvalues.append([ slicevar, ovobs[int(ito)]]) 1718 if valdimsim.has_key('X') and valdimsim.has_key('Y'): 1719 slicev = dims['X'][0] + ':' + str(stationpos[1]-Ngrid) + '@' + \ 1720 str(stationpos[1]+Ngrid+1) + '|' + dims['Y'][0] + ':' + \ 1721 str(stationpos[0]-Ngrid) + '@' + str(stationpos[0]+Ngrid+1) + '|' +\ 1722 dims['T'][0] + ':' + str(int(coindtvalues[it,0])) 1723 else: 1724 slicev = dims['T'][0] + ':' + str(int(coindtvalues[it][0])) 1725 slicevar, dimslice = slice_variable(ovsim, slicev) 1726 simobsSvalues[it,:,:] = slicevar 1727 1728 if it == 0: 1729 itoi = 0 1730 itof = int(coindtvalues[it,1]) / 2 1731 elif it == Ncoindt-1: 1732 itoi = int( (ito + int(coindtvalues[it-1,1])) / 2) 1733 itof = int(coindtvalues[it,1]) 1734 else: 1735 itod = int( (ito - int(coindtvalues[it-1,1])) / 2 ) 1736 itoi = ito - itod 1737 itod = int( (int(coindtvalues[it+1,1]) - ito) / 2 ) 1738 itof = ito + itod 1739 1740 slicev = dims['T'][1] + ':' + str(itoi) + '@' + str(itof + 1) 1741 1742 slicevar, dimslice = slice_variable(ovobs, slicev) 1743 simobsTvalues[str(it)] = slicevar 1744 1745 simobsTtvalues[it,0] = valdimobs['T'][itoi] 1746 simobsTtvalues[it,1] = valdimobs['T'][itof] 1747 1748 elif obskind == 'trajectory': 1749 if dims.has_key('Z'): 1750 for it in range(Ncoindt): 1751 ito = int(coindtvalues[it,1]) 1752 if notfound[ito] == 0: 1753 trajpos[2,ito] = index_mat(valdimsim['Z'][coindtvalues[it,0],:, \ 1754 trajpos[1,ito],trajpos[0,ito]], valdimobs['Z'][ito]) 1755 slicev = dims['X'][0]+':'+str(trajpos[0,ito]) + '|' + \ 1756 dims['Y'][0]+':'+str(trajpos[1,ito]) + '|' + \ 1757 dims['Z'][0]+':'+str(trajpos[2,ito]) + '|' + \ 1758 dims['T'][0]+':'+str(int(coindtvalues[it,0])) 1759 slicevar, dimslice = slice_variable(ovsim, slicev) 1760 simobsvalues.append([ slicevar, ovobs[int(ito)]]) 1761 minx = np.max([trajpos[0,ito]-Ngrid,0]) 1762 maxx = np.min([trajpos[0,ito]+Ngrid+1,ovsim.shape[3]]) 1763 miny = np.max([trajpos[1,ito]-Ngrid,0]) 1764 maxy = np.min([trajpos[1,ito]+Ngrid+1,ovsim.shape[2]]) 1765 minz = np.max([trajpos[2,ito]-Ngrid,0]) 1766 maxz = np.min([trajpos[2,ito]+Ngrid+1,ovsim.shape[1]]) 1767 1768 slicev = dims['X'][0] + ':' + str(minx) + '@' + str(maxx) + '|' +\ 1769 dims['Y'][0] + ':' + str(miny) + '@' + str(maxy) + '|' + \ 1770 dims['Z'][0] + ':' + str(minz) + '@' + str(maxz) + '|' + \ 1771 dims['T'][0] + ':' + str(int(coindtvalues[it,0])) 1772 slicevar, dimslice = slice_variable(ovsim, slicev) 1773 1774 sliceS = [] 1775 sliceS.append(it) 1776 sliceS.append(slice(0,maxz-minz)) 1777 sliceS.append(slice(0,maxy-miny)) 1778 sliceS.append(slice(0,maxx-minx)) 1779 1780 simobsSvalues[tuple(sliceS)] = slicevar 1781 if ivar == 0: 1782 trjsim[0,it] = trajpos[0,ito] 1783 trjsim[1,it] = trajpos[1,ito] 1784 trjsim[2,it] = trajpos[2,ito] 1785 trjsim[3,it] = coindtvalues[it,0] 1786 else: 1787 simobsvalues.append([fillValueF, fillValueF]) 1788 simobsSvalues[it,:,:,:]= np.ones((Ngrid*2+1,Ngrid*2+1,Ngrid*2+1),\ 1789 dtype = np.float)*fillValueF 1790 else: 1791 for it in range(Ncoindt): 1792 if notfound[it] == 0: 1793 ito = coindtvalues[it,1] 1794 slicev = dims['X'][0]+':'+str(trajpos[2,ito]) + '|' + \ 1795 dims['Y'][0]+':'+str(trajpos[1,ito]) + '|' + \ 1796 dims['T'][0]+':'+str(coindtvalues[ito,0]) 1797 slicevar, dimslice = slice_variable(ovsim, slicev) 1798 simobsvalues.append([ slicevar, ovobs[coindtvalues[it,1]]]) 1799 slicev = dims['X'][0] + ':' + str(trajpos[0,it]-Ngrid) + '@' + \ 1800 str(trajpos[0,it]+Ngrid) + '|' + dims['Y'][0] + ':' + \ 1801 str(trajpos[1,it]-Ngrid) + '@' + str(trajpos[1,it]+Ngrid) + \ 1802 '|' + dims['T'][0] + ':' + str(coindtvalues[it,0]) 1803 slicevar, dimslice = slice_variable(ovsim, slicev) 1804 simobsSvalues[it,:,:] = slicevar 1805 else: 1806 simobsvalues.append([fillValue, fillValue]) 1807 simobsSvalues[it,:,:] = np.ones((Ngrid*2+1,Ngrid*2+1), \ 1808 dtype = np.float)*fillValueF 1809 print simobsvalues[varsimobs][:][it] 1810 1677 coindtvalues, oFillValue, Ngrid) 1678 1679 # Re-arranging values... 1811 1680 arrayvals = np.array(simobsvalues) 1812 1681 if len(valvars[ivar]) > 2:
Note: See TracChangeset
for help on using the changeset viewer.