Changeset 1055 in lmdz_wrf for trunk/tools/nc_var_tools.py


Ignore:
Timestamp:
Aug 27, 2016, 10:43:17 AM (8 years ago)
Author:
lfita
Message:

Right values for `cfLMDZ' in 'pinterp'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r1054 r1055  
    1619416194    # Gessing orgin of the file
    1619516195    dimsinfile = onc.dimensions.keys()
     16196    varsinfile = onc.variables.keys()
     16197 
    1619616198    if gen.searchInlist(dimsinfile,'bottom_top'):
    1619716199        modname = 'WRF'
     
    1622016222          'lat', 'time_counter']
    1622116223        MODvardims = ['lon', 'lat', 'time_counter']
     16224    elif gen.searchInlist(dimsinfile,'pres') and gen.searchInlist(varsinfile,        \
     16225      'psol'):
     16226        modname = 'cfLMDZ'
     16227        print warnmsg
     16228        print '  ' + fname + ": gessing that file '" + ncfile + "' comes from '" +   \
     16229          modname + "' ('pres, time_counter' variables renamed as 'p, time') !!"
     16230
     16231        # Variables to interpolate
     16232        MODdims = ['time', 'pres', 'lat', 'lon']
     16233        newMODdims = ['time', 'pres', 'lat', 'lon']
     16234        notCHK = []
     16235        MODvarrequired = ['p', 'psol', 'geop', 'phis', 'temp', 'ovap', 'lon',     \
     16236          'lat', 'time']
     16237        MODvardims = ['lon', 'lat', 'time']
    1622216238    else:
    1622316239        modname = 'CF'
     
    1628616302        CFdimvs = {'time': dimt, 'presnivs': dimz, 'lat': dimy, 'lon': dimx}
    1628716303        unstaggerDIM = 'lon'
     16304    elif modname == 'cfLMDZ':
     16305        ovar1 = onc.variables['p']
     16306        pres = ovar1[:].astype('float64')
     16307        dimx = pres.shape[3]
     16308        dimy = pres.shape[2]
     16309        dimz = pres.shape[1]
     16310        dimt = pres.shape[0]
     16311        MODdimvs = {'time':dimt, 'pres':dimz, 'lat':dimy, 'lon': dimx}
     16312        CFdimvs = {'time': dimt, 'pres': dimz, 'lat': dimy, 'lon': dimx}
     16313        unstaggerDIM = 'lon'
    1628816314    else:
    1628916315        ovar1 = onc.variables['p']
     
    1630116327        ovar1 = onc.variables['PSFC']
    1630216328        psfc = ovar1[:].astype('float64')
    16303     elif modname == 'LMDZ':
     16329    elif modname == 'LMDZ' or modname == 'cfLMDZ':
    1630416330        ovar1 = onc.variables['psol']
    1630516331        psfc = ovar1[:].astype('float64')
     
    1631716343        geop = np.zeros(tuple(unstg), dtype=np.float)
    1631816344        geop = 0.5*(geop0[:,1:dimz,:,:] + geop0[:,0:dimz-1,:,:]).astype('float64')
    16319     elif modname == 'LMDZ':
     16345    elif modname == 'LMDZ' or modname == 'cfLMDZ':
    1632016346        ovar1 = onc.variables['geop']
    1632116347        geop = ovar1[:].astype('float64')
     
    1632816354        ovar1 = onc.variables['HGT']
    1632916355        hgt = ovar1[0,:,:].astype('float64')
    16330     elif modname == 'LMDZ':
     16356    elif modname == 'LMDZ' or modname == 'cfLMDZ':
    1633116357        grav = 9.81
    1633216358        ovar1 = onc.variables['phis']
     
    1634016366        ovar1 = onc.variables['QVAPOR']
    1634116367        qv = ovar1[:].astype('float64')
    16342     elif modname == 'LMDZ':
     16368    elif modname == 'LMDZ' or modname == 'cfLMDZ':
    1634316369        ovar1 = onc.variables['ovap']
    1634416370        qv = ovar1[:].astype('float64')
     
    1635516381        ovar1 = onc.variables['T']
    1635616382        temp = ((ovar1[:]+300.)*(pres[:]/p0)**RCP).astype('float64')
    16357     elif modname == 'LMDZ':
     16383    elif modname == 'LMDZ' or modname == 'cfLMDZ':
    1635816384        ovar1 = onc.variables['temp']
    1635916385        temp = ovar1[:].astype('float64')
     
    1669916725    ncvars = ncf.variables.keys()
    1670016726
    16701 #    # CFing dimension-variables
    16702 #    CFvardims = {'time_counter': 'time', 'presnivs': 'pres'}
    16703 #    for varn in CFvardims.keys():
    16704 #        if gen.searchInlist(ncvars,varn):
    16705 #            # Making sure CF vardimension is not in the file
    16706 #            if not gen.searchInlist(ncvars,CFvardims[varn]):
    16707 #                newname = ncf.renameVariable(varn,CFvardims[varn])
    16708 
    16709 #    ncf.sync()
     16727    # CFing variable 'pres'
     16728    if gen.searchInlist(ncvars,'pres'):
     16729        print warnmsg
     16730        print fname + ": renaming variable 'pres' as 'p' !!"
     16731        newname = ncf.renameVariable('pres','p')
     16732    ncf.sync()
    1671016733
    1671116734    # CFing dimensions
     
    1671616739            if not gen.searchInlist(ncdims,CFdims[dimn]):
    1671716740                newname = ncf.renameDimension(dimn,CFdims[dimn])
    16718 
    1671916741    ncf.sync()
    1672016742
     
    1673216754
    1673316755    ncf.sync()
    16734 
    1673516756    ncf.close()
    1673616757
Note: See TracChangeset for help on using the changeset viewer.