Changeset 367 in lmdz_wrf for trunk/tools/vertical_interpolation.py
- Timestamp:
- Mar 19, 2015, 11:26:25 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/vertical_interpolation.py
r366 r367 313 313 varln = 'geopotential height' 314 314 varu = 'gpm' 315 varinterp = np.zeros((dimv[0], Nintvals, dimv[2], dimv[3]), dtype=np.float) 315 316 elif var == 'WRFrh': 316 317 print ' ' + main + ': computing relative humidity from WRF as ' + \ … … 329 330 varln = 'relative humidity of the air' 330 331 varu = '%' 332 varinterp = np.zeros((dimv[0], Nintvals, dimv[2], dimv[3]), dtype=np.float) 331 333 elif var == 'WRFt': 332 334 print ' ' + main + ': computing temperature from WRF as ' + \ … … 339 341 varln = 'temperature of the air' 340 342 varu = 'K' 341 343 varinterp = np.zeros((dimv[0], Nintvals, dimv[2], dimv[3]), dtype=np.float) 342 344 else: 343 345 print errormsg … … 361 363 362 364 # Getting variable values: 363 if len(varobj.shape) == 4: 364 varinterp = np.zeros((dimv[0], Nintvals, dimv[2], dimv[3]), dtype=np.float) 365 newvar = newnc.createVariable(var, 'f4', ('time','z','y','x')) 366 varvals = varobj[:] 367 elif len(varobj.shape) <= 3 and len(varobj.shape) >= 1: 368 varpdimvs = [] 369 varpdimns = [] 370 varpslice = [] 371 for vdim in vardims: 372 vardim = len(ncobj.dimensions[vdim]) 373 if ncvar.searchInlist(ncdims,vdim): 374 if vdim == dimpresn['Z']: 375 varpdimvs.append(Nintvals) 376 varpdimns.append('z') 365 if len(varobj.shape) == 4: 366 varinterp = np.zeros((dimv[0], Nintvals, dimv[2], dimv[3]), dtype=np.float) 367 newvar = newnc.createVariable(var, 'f4', ('time','z','y','x')) 368 varvals = varobj[:] 369 elif len(varobj.shape) <= 3 and len(varobj.shape) >= 1: 370 varpdimvs = [] 371 varpdimns = [] 372 varpslice = [] 373 for vdim in vardims: 374 vardim = len(ncobj.dimensions[vdim]) 375 if ncvar.searchInlist(ncdims,vdim): 376 if vdim == dimpresn['Z']: 377 varpdimvs.append(Nintvals) 378 varpdimns.append('z') 379 varpslice.append(slice(0,vardim)) 380 else: 381 varpdimvs.append(vardim) 382 varpslice.append(slice(0,vardim)) 383 if dimpresn.has_key('X') and vdim == dimpresn['X']: 384 varpdimns.append('x') 385 elif dimpresn.has_key('Y') and vdim == dimpresn['Y']: 386 varpdimns.append('y') 387 elif dimpresn.has_key('T') and vdim == dimpresn['T']: 388 varpdimns.append('time') 389 else: 390 print errormsg 391 print ' ' + main + ": dimension variable '" + vdim + \ 392 "' is in pressure but it is not found?" 393 print ' pressure dimensions:', ncdims 394 quit(-1) 395 else: 396 # Dimension of the variable is not in the pressure variable 397 varpdimvs.append(vardim) 398 varpdimns.append(vdim) 377 399 varpslice.append(slice(0,vardim)) 378 else: 379 varpdimvs.append(vardim) 380 varpslice.append(slice(0,vardim)) 381 if dimpresn.has_key('X') and vdim == dimpresn['X']: 382 varpdimns.append('x') 383 elif dimpresn.has_key('Y') and vdim == dimpresn['Y']: 384 varpdimns.append('y') 385 elif dimpresn.has_key('T') and vdim == dimpresn['T']: 386 varpdimns.append('time') 387 else: 388 print errormsg 389 print ' ' + main + ": dimension variable '" + vdim + \ 390 "' is in pressure but it is not found?" 391 print ' pressure dimensions:', ncdims 392 quit(-1) 393 else: 394 # Dimension of the variable is not in the pressure variable 395 varpdimvs.append(vardim) 396 varpdimns.append(vdim) 397 varpslice.append(slice(0,vardim)) 398 if not newnc.dimensions.has_key(vdim) and not \ 399 ncvar.searchInlist(dimpresn,vdim): 400 print ' ' + main + ": dimension '" + vdim + "' not in the " + \ 401 'pressure variable adding it!' 402 if ncobj.dimensions[vdim].isunlimited(): 403 newnc.createDimension(vdim, None) 404 else: 405 newnc.createDimension(vdim, vardim) 406 407 varinterp = np.zeros((varpdimvs), dtype=np.float) 408 newvar = newnc.createVariable(var, 'f4', tuple(varpdimns)) 409 410 varvals = varobj[tuple(varpslice)] 411 else: 412 print errormsg 413 print ' ' + main + ': variable shape "', varvals.shape, '" not ready !!!!' 414 quit(-1) 400 if not newnc.dimensions.has_key(vdim) and not \ 401 ncvar.searchInlist(dimpresn,vdim): 402 print ' ' + main + ": dimension '" + vdim + "' not in the " + \ 403 'pressure variable adding it!' 404 if ncobj.dimensions[vdim].isunlimited(): 405 newnc.createDimension(vdim, None) 406 else: 407 newnc.createDimension(vdim, vardim) 408 409 varinterp = np.zeros((varpdimvs), dtype=np.float) 410 newvar = newnc.createVariable(var, 'f4', tuple(varpdimns)) 411 412 varvals = varobj[tuple(varpslice)] 413 else: 414 print errormsg 415 print ' ' + main + ': variable shape "', varobj.shape, '" not ready !!!!' 416 quit(-1) 415 417 416 418 # print 'variable:',var,'shape:',varvals.shape,'len:',len(varvals.shape)
Note: See TracChangeset
for help on using the changeset viewer.