Changeset 1811 in lmdz_wrf for trunk/tools/nc_var_tools.py
- Timestamp:
- Mar 19, 2018, 1:57:49 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1810 r1811 16 16 import generic_tools as gen 17 17 import subprocess as sub 18 import module_ForDef as fdef 18 19 19 20 ####### Contents: … … 174 175 infmsg = 'INFORMATION -- information -- INFORMATION -- information' 175 176 177 # Which resolution has been defined for Fortran reals? 178 if type(fdef.module_definitions.onerk) == type(np.float64): 179 isFR64 = True 180 else: 181 isFR64 = False 182 print 'Lluis oneRK:', type(fdef.module_definitions.onerk), 'isFR64:', isFR64 183 176 184 ## Constants 177 185 # Radius of the Earth (m) … … 18051 18059 def pinterp(values, ncfile, variables): 18052 18060 """ Function to vertically interpolate using subroutines from the p_interp.F90 NCAR program 18061 Using fortran codes: module_generic.F90 18053 18062 values= [interplevs],[linloginterp],[extrap] 18054 18063 [interplevs]: ':' separated list of pressure values to interpolate [Pa] (decreassing in Pa) … … 18060 18069 variables = ',' separated list of names of variables to interpolate ('all', fo all 4D-atmospheric variables) 18061 18070 'WRFght': for WRF geopotential height 18062 'WRFhus': for WRF specific humidity18063 18071 'WRFrh': for WRF relative humidity 18064 18072 'WRFt': for WRF temperature 18065 18073 'WRFu': for WRF x-wind de-staggered 18066 18074 'WRFv': for WRF y-wind de-staggered 18067 'WRFw': for WRF z-wind de-staggered18068 18075 """ 18069 18076 import module_ForInt as fin … … 18181 18188 18182 18189 pres0 = ovar1[:] + ovar2[:] 18183 pres = pres0.astype('float64') 18190 if isFR64: 18191 pres = pres0.astype('float64') 18192 else: 18193 pres = pres0.astype('float') 18184 18194 18185 18195 dimx = pres.shape[3] … … 18193 18203 elif modname == 'LMDZ': 18194 18204 ovar1 = onc.variables['pres'] 18195 pres = ovar1[:].astype('float64') 18205 if isFR64: 18206 pres = ovar1[:].astype('float64') 18207 else: 18208 pres = ovar1[:].astype('float') 18196 18209 dimx = pres.shape[3] 18197 18210 dimy = pres.shape[2] … … 18203 18216 elif modname == 'cfLMDZ': 18204 18217 ovar1 = onc.variables['p'] 18205 pres = ovar1[:].astype('float64') 18218 if isFR64: 18219 pres = ovar1[:].astype('float64') 18220 else: 18221 pres = ovar1[:].astype('float') 18206 18222 dimx = pres.shape[3] 18207 18223 dimy = pres.shape[2] … … 18213 18229 else: 18214 18230 ovar1 = onc.variables['p'] 18215 pres = ovar1[:].astype('float64') 18231 if isFR64: 18232 pres = ovar1[:].astype('float64') 18233 else: 18234 pres = ovar1[:].astype('float') 18216 18235 dimx = pres.shape[3] 18217 18236 dimy = pres.shape[2] … … 18227 18246 if modname == 'WRF': 18228 18247 ovar1 = onc.variables['PSFC'] 18229 psfc = ovar1[:].astype('float64') 18248 if isFR64: 18249 psfc = ovar1[:].astype('float64') 18250 else: 18251 psfc = ovar1[:].astype('float') 18230 18252 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18231 18253 ovar1 = onc.variables['psol'] 18232 psfc = ovar1[:].astype('float64') 18254 if isFR64: 18255 psfc = ovar1[:].astype('float64') 18256 else: 18257 psfc = ovar1[:].astype('float') 18233 18258 else: 18234 18259 ovar1 = onc.variables['ps'] 18235 psfc = ovar1[:].astype('float64') 18260 if isFR64: 18261 psfc = ovar1[:].astype('float64') 18262 else: 18263 psfc = ovar1[:].astype('float') 18236 18264 18237 18265 # geopotential height … … 18243 18271 unstg[1] = unstg[1] - 1 18244 18272 geop = np.zeros(tuple(unstg), dtype=np.float) 18245 geop = 0.5*(geop0[:,1:dimz+1,:,:] + geop0[:,0:dimz,:,:]).astype('float64') 18273 if isFR64: 18274 geop = 0.5*(geop0[:,1:dimz+1,:,:] + geop0[:,0:dimz,:,:]).astype('float64') 18275 else: 18276 geop = 0.5*(geop0[:,1:dimz+1,:,:] + geop0[:,0:dimz,:,:]).astype('float') 18246 18277 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18247 18278 ovar1 = onc.variables['geop'] 18248 geop = ovar1[:].astype('float64') 18279 if isFR64: 18280 geop = ovar1[:].astype('float64') 18281 else: 18282 geop = ovar1[:].astype('float') 18249 18283 else: 18250 18284 ovar1 = onc.variables['z'] 18251 geop = ovar1[:].astype('float64') 18285 if isFR64: 18286 geop = ovar1[:].astype('float64') 18287 else: 18288 geop = ovar1[:].astype('float') 18252 18289 18253 18290 # terrain height 18254 18291 if modname == 'WRF': 18255 18292 ovar1 = onc.variables['HGT'] 18256 hgt = ovar1[0,:,:].astype('float64') 18293 if isFR64: 18294 hgt = ovar1[0,:,:].astype('float64') 18295 else: 18296 hgt = ovar1[0,:,:].astype('float') 18257 18297 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18258 18298 grav = 9.81 18259 18299 ovar1 = onc.variables['phis'] 18260 hgt = (ovar1[0,:,:]/grav).astype('float64') 18300 if isFR64: 18301 hgt = (ovar1[0,:,:]/grav).astype('float64') 18302 else: 18303 hgt = (ovar1[0,:,:]/grav).astype('float') 18261 18304 else: 18262 18305 ovar1 = onc.variables['orog'] 18263 hgt = ovar1[:].astype('float64') 18306 if isFR64: 18307 hgt = ovar1[:].astype('float64') 18308 else: 18309 hgt = ovar1[:].astype('float') 18264 18310 18265 18311 # water vapour mixing ratio 18266 18312 if modname == 'WRF': 18267 18313 ovar1 = onc.variables['QVAPOR'] 18268 qv = ovar1[:].astype('float64') 18314 if isFR64: 18315 qv = ovar1[:].astype('float64') 18316 else: 18317 qv = ovar1[:].astype('float') 18269 18318 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18270 18319 ovar1 = onc.variables['ovap'] 18271 qv = ovar1[:].astype('float64') 18320 if isFR64: 18321 qv = ovar1[:].astype('float64') 18322 else: 18323 qv = ovar1[:].astype('float') 18272 18324 else: 18273 18325 ovar1 = onc.variables['hus'] 18274 qv = ovar1[:].astype('float64') 18326 if isFR64: 18327 qv = ovar1[:].astype('float64') 18328 else: 18329 qv = ovar1[:].astype('float') 18275 18330 18276 18331 # temperature … … 18282 18337 ovar10 = onc.variables['T'] 18283 18338 var10 = ovar10[:] 18284 ovar1 = (var10).astype('float64') 18339 if isFR64: 18340 ovar1 = (var10).astype('float64') 18341 else: 18342 ovar1 = (var10).astype('float') 18285 18343 temp0 = (ovar1[:]+300.)*(pres[:]/p0)**RCP 18286 temp = temp0.astype('float64') 18344 if isFR64: 18345 temp = temp0.astype('float64') 18346 else: 18347 temp = temp0.astype('float') 18287 18348 elif modname == 'LMDZ' or modname == 'cfLMDZ': 18288 18349 ovar1 = onc.variables['temp'] 18289 temp = ovar1[:].astype('float64') 18350 if isFR64: 18351 temp = ovar1[:].astype('float64') 18352 else: 18353 temp = ovar1[:].astype('float') 18290 18354 else: 18291 18355 ovar1 = onc.variables['ta'] 18292 temp = ovar1[:].astype('float64') 18356 if isFR64: 18357 temp = ovar1[:].astype('float64') 18358 else: 18359 temp = ovar1[:].astype('float') 18293 18360 18294 18361 onewnc = NetCDFFile(ofile, 'w') … … 18351 18418 isgeop = True 18352 18419 varattrs = gen.variables_values('WRFght') 18353 CFvn = varattrs[0]18354 newvarattr['standard_name'] = varattrs[1]18355 newvarattr['long_name'] = varattrs[4].replace('|',' ')18356 newvarattr['units'] = varattrs[5]18357 elif vn == 'WRFhus':18358 # relative humidity18359 varin = qv/(1.+qv)18360 isgeop = False18361 varattrs = gen.variables_values('hus')18362 18420 CFvn = varattrs[0] 18363 18421 newvarattr['standard_name'] = varattrs[1] … … 18409 18467 newvarattr['long_name'] = varattrs[4].replace('|',' ') 18410 18468 newvarattr['units'] = varattrs[5] 18411 elif vn == 'WRFw':18412 ovarin = onc.variables['W']18413 print infmsg18414 print ' ' + fname + ': De-staggering z-wind variable !!'18415 print ' from:', ovarin.shape, 'to', (dimt, dimz, dimy, dimx)18416 varin = np.zeros((dimt, dimz, dimy, dimx), dtype=np.float64)18417 varin[:] = 0.5*(ovarin[:,0:dimz,:,:] + ovarin[:,1:dimz+1,:,:])18418 isgeop = False18419 varattrs = gen.variables_values('wa')18420 CFvn = varattrs[0]18421 newvarattr['standard_name'] = varattrs[1]18422 newvarattr['long_name'] = varattrs[4].replace('|',' ')18423 newvarattr['units'] = varattrs[5]18424 18469 elif vn == 'pres': 18425 18470 varin = pres
Note: See TracChangeset
for help on using the changeset viewer.