Changeset 496 in lmdz_wrf for trunk/tools/validation_sim.py
- Timestamp:
- Jun 15, 2015, 1:15:31 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/validation_sim.py
r495 r496 1035 1035 return 1036 1036 1037 def getting_ValidationValues(okind, dimt, ds, trjpos, ovs, ovo, tvalues, ofill, Ng): 1038 """ Function to get the values to validate accroding to the type of observation 1039 okind= observational kind 1040 dimt= number of values to retrieve 1041 ds= dictionary with the names of the dimensions (sim, obs) 1042 trjpos= positions of the multi-stations (t, Y, X) or trajectory ([Z], Y, X) 1043 ovs= object with the values of the simulation 1044 ovs= object with the values of the observations 1045 tvalues= temporal values (sim. time step, obs. time step, sim t value, obs t value, t diff) 1046 ofill= Fill Value for the observations 1047 Ng= number of grid points around the observation 1048 return: 1049 sovalues= simulated values at the observation point and time 1050 soSvalues= values Ngrid points around the simulated point 1051 soTvalues= inital/ending period between two consecutive obsevations (for `single-station') 1052 trjs= trajectory on the simulation space 1053 """ 1054 fname = 'getting_ValidationValues' 1055 1056 sovalues = [] 1057 1058 # Simulated values spatially around 1059 if ds.has_key('Z'): 1060 soSvalues = np.zeros((dimt, Ng*2+1, Ng*2+1, Ng*2+1), \ 1061 dtype = np.float) 1062 if okind == 'trajectory': 1063 trjs = np.zeros((4,dimt), dtype=int) 1064 else: 1065 trjS = None 1066 else: 1067 soSvalues = np.zeros((dimt, Ng*2+1, Ng*2+1), dtype = np.float) 1068 if okind == 'trajectory': 1069 trjs = np.zeros((3,dimt), dtype=int) 1070 else: 1071 trjS = None 1072 1073 if okind == 'single-station': 1074 soTvalues = {} 1075 soTtvalues = np.zeros((dimt,2), dtype=np.float) 1076 else: 1077 None 1078 1079 if okind == 'multi-points': 1080 for it in range(dimt): 1081 slicev = ds['X'][0] + ':' + str(trjpos[2,it]) + '|' + \ 1082 ds['Y'][0]+ ':' + str(trjpos[1,it]) + '|' + \ 1083 ds['T'][0]+ ':' + str(tvalues[it][0]) 1084 slicevar, dimslice = slice_variable(ovs, slicev) 1085 sovalues.append([ slicevar, ovo[tvalues[it][1]]]) 1086 slicev = ds['X'][0] + ':' + str(trjpos[2,it]-Ng) + '@' + \ 1087 str(trjpos[2,it]+Ng) + '|' + ds['Y'][0] + ':' + \ 1088 str(trjpos[1,it]-Ng) + '@' + str(trjpos[1,it]+Ng) + '|' + \ 1089 ds['T'][0]+':'+str(tvalues[it][0]) 1090 slicevar, dimslice = slice_variable(ovs, slicev) 1091 soSvalues[it,:,:] = slicevar 1092 1093 elif okind == 'single-station': 1094 for it in range(dimt): 1095 ito = int(tvalues[it,1]) 1096 if valdimsim.has_key('X') and valdimsim.has_key('Y'): 1097 slicev = ds['X'][0] + ':' + str(stationpos[1]) + '|' + \ 1098 ds['Y'][0] + ':' + str(stationpos[0]) + '|' + \ 1099 ds['T'][0] + ':' + str(int(tvalues[it][0])) 1100 else: 1101 slicev = ds['T'][0] + ':' + str(int(tvalues[it][0])) 1102 slicevar, dimslice = slice_variable(ovs, slicev) 1103 if ovo[int(ito)] == oFill or ovo[int(ito)] == '--': 1104 sovalues.append([ slicevar, fillValueF]) 1105 # elif ovo[int(ito)] != ovo[int(ito)]: 1106 # sovalues.append([ slicevar, fillValueF]) 1107 else: 1108 sovalues.append([ slicevar, ovo[int(ito)]]) 1109 if valdimsim.has_key('X') and valdimsim.has_key('Y'): 1110 slicev = ds['X'][0] + ':' + str(stationpos[1]-Ng) + '@' + \ 1111 str(stationpos[1]+Ng+1) + '|' + ds['Y'][0] + ':' + \ 1112 str(stationpos[0]-Ng) + '@' + str(stationpos[0]+Ng+1) + '|' +\ 1113 ds['T'][0] + ':' + str(int(tvalues[it,0])) 1114 else: 1115 slicev = ds['T'][0] + ':' + str(int(tvalues[it][0])) 1116 slicevar, dimslice = slice_variable(ovs, slicev) 1117 soSvalues[it,:,:] = slicevar 1118 1119 if it == 0: 1120 itoi = 0 1121 itof = int(tvalues[it,1]) / 2 1122 elif it == dimt-1: 1123 itoi = int( (ito + int(tvalues[it-1,1])) / 2) 1124 itof = int(tvalues[it,1]) 1125 else: 1126 itod = int( (ito - int(tvalues[it-1,1])) / 2 ) 1127 itoi = ito - itod 1128 itod = int( (int(tvalues[it+1,1]) - ito) / 2 ) 1129 itof = ito + itod 1130 1131 slicev = ds['T'][1] + ':' + str(itoi) + '@' + str(itof + 1) 1132 1133 slicevar, dimslice = slice_variable(ovo, slicev) 1134 soTvalues[str(it)] = slicevar 1135 1136 soTtvalues[it,0] = valdimobs['T'][itoi] 1137 soTtvalues[it,1] = valdimobs['T'][itof] 1138 1139 elif okind == 'trajectory': 1140 if ds.has_key('Z'): 1141 for it in range(dimt): 1142 ito = int(tvalues[it,1]) 1143 if notfound[ito] == 0: 1144 trjpos[2,ito] = index_mat(valdimsim['Z'][tvalues[it,0],:, \ 1145 trjpos[1,ito],trjpos[0,ito]], valdimobs['Z'][ito]) 1146 slicev = ds['X'][0]+':'+str(trjpos[0,ito]) + '|' + \ 1147 ds['Y'][0]+':'+str(trjpos[1,ito]) + '|' + \ 1148 ds['Z'][0]+':'+str(trjpos[2,ito]) + '|' + \ 1149 ds['T'][0]+':'+str(int(tvalues[it,0])) 1150 slicevar, dimslice = slice_variable(ovs, slicev) 1151 sovalues.append([ slicevar, ovo[int(ito)]]) 1152 minx = np.max([trjpos[0,ito]-Ng,0]) 1153 maxx = np.min([trjpos[0,ito]+Ng+1,ovs.shape[3]]) 1154 miny = np.max([trjpos[1,ito]-Ng,0]) 1155 maxy = np.min([trjpos[1,ito]+Ng+1,ovs.shape[2]]) 1156 minz = np.max([trjpos[2,ito]-Ng,0]) 1157 maxz = np.min([trjpos[2,ito]+Ng+1,ovs.shape[1]]) 1158 1159 slicev = ds['X'][0] + ':' + str(minx) + '@' + str(maxx) + '|' +\ 1160 ds['Y'][0] + ':' + str(miny) + '@' + str(maxy) + '|' + \ 1161 ds['Z'][0] + ':' + str(minz) + '@' + str(maxz) + '|' + \ 1162 ds['T'][0] + ':' + str(int(tvalues[it,0])) 1163 slicevar, dimslice = slice_variable(ovs, slicev) 1164 1165 sliceS = [] 1166 sliceS.append(it) 1167 sliceS.append(slice(0,maxz-minz)) 1168 sliceS.append(slice(0,maxy-miny)) 1169 sliceS.append(slice(0,maxx-minx)) 1170 1171 soSvalues[tuple(sliceS)] = slicevar 1172 if ivar == 0: 1173 trjs[0,it] = trjpos[0,ito] 1174 trjs[1,it] = trjpos[1,ito] 1175 trjs[2,it] = trjpos[2,ito] 1176 trjs[3,it] = tvalues[it,0] 1177 else: 1178 sovalues.append([fillValueF, fillValueF]) 1179 soSvalues[it,:,:,:]= np.ones((Ng*2+1,Ng*2+1,Ng*2+1), \ 1180 dtype = np.float)*fillValueF 1181 # 2D trajectory 1182 else: 1183 for it in range(dimt): 1184 if notfound[it] == 0: 1185 ito = tvalues[it,1] 1186 slicev = ds['X'][0]+':'+str(trjpos[2,ito]) + '|' + \ 1187 ds['Y'][0]+':'+str(trjpos[1,ito]) + '|' + \ 1188 ds['T'][0]+':'+str(tvalues[ito,0]) 1189 slicevar, dimslice = slice_variable(ovs, slicev) 1190 sovalues.append([ slicevar, ovo[tvalues[it,1]]]) 1191 slicev = ds['X'][0] + ':' + str(trjpos[0,it]-Ng) + '@' + \ 1192 str(trjpos[0,it]+Ng) + '|' + ds['Y'][0] + ':' + \ 1193 str(trjpos[1,it]-Ng) + '@' + str(trjpos[1,it]+Ng) + \ 1194 '|' + ds['T'][0] + ':' + str(tvalues[it,0]) 1195 slicevar, dimslice = slice_variable(ovs, slicev) 1196 soSvalues[it,:,:] = slicevar 1197 else: 1198 sovalues.append([fillValue, fillValue]) 1199 soSvalues[it,:,:] = np.ones((Ng*2+1,Ng*2+1), \ 1200 dtype = np.float)*fillValueF 1201 print sovalues[varsimobs][:][it] 1202 else: 1203 print errormsg 1204 print ' ' + fname + ": observatino kind '" + okind + "' not ready!!' 1205 quit(-1) 1206 1207 1208 return sovalues, soSvalues, soTvalues, trjs 1209 1210 1037 1211 ####### ###### ##### #### ### ## # 1038 1212 … … 1457 1631 if dims.has_key('Z'): 1458 1632 newdim = onewnc.createDimension('simtrj',4) 1459 trjsim = np.zeros((4,Ncoindt), dtype=int)1460 trjsimval = np.zeros((4,Ncoindt), dtype=np.float)1461 1633 else: 1462 1634 newdim = onewnc.createDimension('simtrj',3) 1463 trjsim = np.zeros((3,Ncoindt), dtype=int)1464 trjsimval = np.zeros((3,Ncoindt), dtype=np.float)1465 1635 1466 1636 Nvars = len(valvars) … … 1498 1668 if searchInlist(ovobs.ncattrs(),'_FillValue'): 1499 1669 oFillValue = ovobs.getncattr('_FillValue') 1670 1671 simobsvalues, simobsSvalues, simobsTvalues, trjsim = \ 1672 getting_ValidationValues(obskind, Ncoindt, dims, trajpos, ovsim, ovobs \ 1673 coindtvalues, ofillValue, Ngrid): 1674 quit(-1) 1675 1500 1676 1501 1677 # Simulated values spatially around coincident times
Note: See TracChangeset
for help on using the changeset viewer.