Changeset 752 in lmdz_wrf
- Timestamp:
- May 4, 2016, 11:54:10 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r751 r752 12198 12198 longvarname = 'using inverse of variable ' + varname + ' as space weights' 12199 12199 if len(loopshape) == 1: 12200 newvals = np.ones((loopshape[0]), dtype=np.float)*fillValueF 12200 newvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF 12201 newsumvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF 12201 12202 for id1 in range(loopshape[0]): 12202 12203 slicevalues = SliceVar(iovar,dimsloop,[id1]) 12203 12204 slicewgt = SliceVar(iovarwgt,dimsloop,[id1]) 12204 12205 TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)]) 12206 newsumvals[id1] = np.sum(ivarv[tuple(slicevalues)] / \ 12207 ivarwgtv[tuple(slicewgt)]) 12205 12208 newvals[id1] = np.sum(ivarv[tuple(slicevalues)] / \ 12206 12209 ivarwgtv[tuple(slicewgt)]) / TOTsumwgt 12207 12210 elif len(loopshape) == 2: 12208 12211 newvals = np.ones((loopshape[0],loopshape[1]),dtype=np.float)* \ 12209 fillValueF 12212 gen.fillValueF 12213 newsumvals = np.ones((loopshape[0],loopshape[1]),dtype=np.float)* \ 12214 gen.fillValueF 12210 12215 for id1 in range(loopshape[0]): 12211 12216 for id2 in range(loopshape[1]): … … 12213 12218 slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2]) 12214 12219 TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)]) 12220 newsumvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)] / \ 12221 ivarwgtv[tuple(slicewgt)]) 12215 12222 newvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)] / \ 12216 12223 ivarwgtv[tuple(slicewgt)]) / TOTsumwgt 12217 12224 elif len(loopshape) == 3: 12218 12225 newvals = np.ones((loopshape[0],loopshape[1],loopshape[2]), \ 12219 dtype=np.float)*fillValueF 12226 dtype=np.float)*gen.fillValueF 12227 newsumvals = np.ones((loopshape[0],loopshape[1],loopshape[2]), \ 12228 dtype=np.float)*gen.fillValueF 12220 12229 for id1 in range(loopshape[0]): 12221 12230 for id2 in range(loopshape[1]): … … 12224 12233 slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2,id3]) 12225 12234 TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)]) 12235 newsumvals[id1,id2,id3]=np.sum(ivarv[tuple(slicevalues)]/\ 12236 ivarwgtv[tuple(slicewgt)]) 12226 12237 newvals[id1,id2,id3]= np.sum(ivarv[tuple(slicevalues)]/ \ 12227 12238 ivarwgtv[tuple(slicewgt)]) / TOTsumwgt … … 12230 12241 longvarname = 'using variable ' + varname + ' as space weights' 12231 12242 if len(loopshape) == 1: 12232 newvals = np.ones((loopshape[0]), dtype=np.float)*fillValueF 12243 newvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF 12244 newsumvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF 12233 12245 for id1 in range(loopshape[0]): 12234 12246 slicevalues = SliceVar(iovar,dimsloop,[id1]) 12235 12247 slicewgt = SliceVar(iovarwgt,dimsloop,[id1]) 12236 12248 TOTsumwgt = np.sum(ivarwgtv[tuple(slicewgt)]) 12249 newsumvals[id1] = np.sum(ivarv[tuple(slicevalues)]* \ 12250 ivarwgtv[tuple(slicewgt)]) 12237 12251 newvals[id1] = np.sum(ivarv[tuple(slicevalues)]* \ 12238 12252 ivarwgtv[tuple(slicewgt)]) / TOTsumwgt 12239 12253 elif len(loopshape) == 2: 12240 12254 newvals = np.ones((loopshape[0],loopshape[1]), dtype=np.float)* \ 12241 fillValueF 12255 gen.fillValueF 12256 newsumvals = np.ones((loopshape[0],loopshape[1]), dtype=np.float)* \ 12257 gen.fillValueF 12242 12258 for id1 in range(loopshape[0]): 12243 12259 for id2 in range(loopshape[1]): … … 12245 12261 slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2]) 12246 12262 TOTsumwgt = np.sum(ivarwgtv[tuple(slicewgt)]) 12263 newsumvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)]* \ 12264 ivarwgtv[tuple(slicewgt)]) 12247 12265 newvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)]* \ 12248 12266 ivarwgtv[tuple(slicewgt)]) / TOTsumwgt 12249 12267 elif len(loopshape) == 3: 12250 12268 newvals = np.ones((loopshape[0],loopshape[1],loopshape[2]), \ 12251 dtype=np.float)*fillValueF 12269 dtype=np.float)*gen.fillValueF 12270 newsumvals = np.ones((loopshape[0],loopshape[1],loopshape[2]), \ 12271 dtype=np.float)*gen.fillValueF 12252 12272 for id1 in range(loopshape[0]): 12253 12273 for id2 in range(loopshape[1]): … … 12256 12276 slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2,id3]) 12257 12277 TOTsumwgt = np.sum(ivarwgtv[tuple(slicewgt)]) 12278 newsumvals[id1,id2,id3]=np.sum(ivarv[tuple(slicevalues)]*\ 12279 ivarwgtv[tuple(slicewgt)]) 12258 12280 newvals[id1,id2,id3]=np.sum(ivarv[tuple(slicevalues)]* \ 12259 12281 ivarwgtv[tuple(slicewgt)]) / TOTsumwgt … … 12264 12286 if len(loopshape) == 1: 12265 12287 newvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF 12288 newsumvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF 12266 12289 for id1 in range(loopshape[0]): 12267 12290 slicevalues = SliceVar(iovar,dimsloop,[id1]) 12268 12291 slicewgt = SliceVar(iovarwgt1,dimsloop,[id1]) 12269 12292 TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)]) 12293 newsumvals[id1] = np.sum(ivarv[tuple(slicevalues)] / \ 12294 ivarwgtv[tuple(slicewgt)]) 12270 12295 newvals[id1] = np.sum(ivarv[tuple(slicevalues)] / \ 12271 12296 ivarwgtv[tuple(slicewgt)]) / TOTsumwgt 12272 12297 elif len(loopshape) == 2: 12273 12298 newvals = np.ones((loopshape[0],loopshape[1]),dtype=np.float)* \ 12299 gen.fillValueF 12300 newsumvals = np.ones((loopshape[0],loopshape[1]),dtype=np.float)* \ 12274 12301 gen.fillValueF 12275 12302 for id1 in range(loopshape[0]): … … 12278 12305 slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2]) 12279 12306 TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)]) 12307 newsumvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)] / \ 12308 ivarwgtv[tuple(slicewgt)]) 12280 12309 newvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)] / \ 12281 12310 ivarwgtv[tuple(slicewgt)]) / TOTsumwgt 12282 12311 elif len(loopshape) == 3: 12283 12312 newvals = np.ones((loopshape[0],loopshape[1],loopshape[2]), \ 12313 dtype=np.float)*gen.fillValueF 12314 newsumvals = np.ones((loopshape[0],loopshape[1],loopshape[2]), \ 12284 12315 dtype=np.float)*gen.fillValueF 12285 12316 for id1 in range(loopshape[0]): … … 12289 12320 slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2,id3]) 12290 12321 TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)]) 12322 newsumvals[id1,id2,id3]=np.sum(ivarv[tuple(slicevalues)]/\ 12323 ivarwgtv[tuple(slicewgt)]) 12291 12324 newvals[id1,id2,id3]= np.sum(ivarv[tuple(slicevalues)]/ \ 12292 12325 ivarwgtv[tuple(slicewgt)]) / TOTsumwgt … … 12315 12348 TOTsumwgt = np.sum(ivarwgtv) 12316 12349 12317 print 'Lluis len(looopshape):', len(loopshape)12318 12350 if len(loopshape) == 1: 12319 newvals = np.ones((loopshape[0]), dtype=np.float)* fillValueF12320 newsumvals = np.ones((loopshape[0]), dtype=np.float)* fillValueF12351 newvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF 12352 newsumvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF 12321 12353 for id1 in range(loopshape[0]): 12322 12354 slicevalues = SliceVar(iovar,dimsloop,[id1]) … … 12327 12359 newvals[id1] = newsumvals[id1]/TOTsumwgt 12328 12360 elif len(loopshape) == 2: 12329 newvals = np.ones((loopshape[0],loopshape[1]), dtype=np.float)*fillValueF 12330 newsumvals = np.ones((loopshape[0],loopshape[1]), dtype=np.float)*fillValueF 12361 newvals = np.ones((loopshape[0],loopshape[1]), \ 12362 dtype=np.float)*gen.fillValueF 12363 newsumvals = np.ones((loopshape[0],loopshape[1]), \ 12364 dtype=np.float)*gen.fillValueF 12331 12365 for id1 in range(loopshape[0]): 12332 12366 for id2 in range(loopshape[1]): … … 12339 12373 elif len(loopshape) == 3: 12340 12374 newvals = np.ones((loopshape[0],loopshape[1],loopshape[2]), \ 12341 dtype=np.float)* fillValueF12375 dtype=np.float)*gen.fillValueF 12342 12376 newsumvals = np.ones((loopshape[0],loopshape[1],loopshape[2]), \ 12343 dtype=np.float)* fillValueF12377 dtype=np.float)*gen.fillValueF 12344 12378 for id1 in range(loopshape[0]): 12345 12379 for id2 in range(loopshape[1]):
Note: See TracChangeset
for help on using the changeset viewer.