Changeset 1053 in lmdz_wrf


Ignore:
Timestamp:
Aug 27, 2016, 9:34:32 AM (9 years ago)
Author:
lfita
Message:

Adding `LMDZ' model in 'pinterp'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var.py

    r1050 r1053  
    1818## e.g. # nc_var.py -o LMDZ_toCF -f LMDZ/AR40/vas_histins_1-1.nc
    1919## e.g. # nc_var.py -o pinterp -f wrfout_d01_2001-11-11_00\:00\:00 -S 100000.:97500.:95000.:92500.:90000.:85000.:80000.:75000.:70000.:65000.:60000.:55000.:50000.:45000.:40000.:35000.:30000.:25000.:20000.:15000.:10000.:5000.:2500.:1000.:500.:250.,1,0 -v WRFt,WRFrh
     20## e.g. # nc_var.py -o pinterp -f /media/ExtDiskC_ext4/DATA/etudes/WRF_LMDZ/WaquaL_highres/short_copies/LMDZ/AR40/histins_19790101000000-19790304000000_short.nc -S 100000.:97500.:95000.:92500.:90000.:85000.:80000.:75000.:70000.:65000.:60000.:55000.:50000.:45000.:40000.:35000.:30000.:25000.:20000.:15000.:10000.:5000.:2500.:1000.:500.:250.,1,0 -v temp,ovap
    2021
    2122from optparse import OptionParser
  • trunk/tools/nc_var_tools.py

    r1050 r1053  
    1618716187
    1618816188    CFdims = ['time', 'pres', 'lat', 'lon']
     16189    # Just in case there are weird units, attribute value will be taken from input file
     16190    CFattrs = ['standard_name', 'long_name']
    1618916191
    1619016192    onc = NetCDFFile(ncfile, 'r')
     
    1620516207          'XLONG', 'XLAT', 'Times']
    1620616208        MODvardims = ['XLONG', 'XLAT', 'Times']
     16209    elif gen.searchInlist(dimsinfile,'presnivs'):
     16210        modname = 'LMDZ'
     16211        print warnmsg
     16212        print '  ' + fname + ": gessing that file '" + ncfile + "' comes from '" +   \
     16213          modname + "' !!"
     16214
     16215        # Variables to interpolate
     16216        MODdims = ['time_counter', 'presnivs', 'lat', 'lon']
     16217        newMODdims = ['time_counter', 'pres', 'lat', 'lon']
     16218        notCHK = []
     16219        MODvarrequired = ['pres', 'psol', 'geop', 'phis', 'temp', 'ovap', 'lon',     \
     16220          'lat', 'time_counter']
     16221        MODvardims = ['lon', 'lat', 'time_counter']
    1620716222
    1620816223    varns = gen.str_list(variables, ',')
     
    1622916244        if not gen.searchInlist(onc.variables, var):
    1623016245            print errormsg
    16231             print '  ' + fname + ": file '" + ncfile + "' does not have variable '" +\
    16232               var + "' !!"
     16246            print '  ' + fname + ": file '" + ncfile + "' does not have required " + \
     16247              "variable '" + var + "' !!"
    1623316248            quit(-1)
    1623416249
     
    1624916264        CFdimvs = {'time': dimt, 'bottom_top': dimz, 'lat': dimy, 'lon': dimx}
    1625016265        unstaggerDIM = 'west_east'
     16266    elif modname == 'LMDZ':
     16267        ovar1 = onc.variables['pres']
     16268        pres = ovar1[:].astype('float64')
     16269        dimx = pres.shape[3]
     16270        dimy = pres.shape[2]
     16271        dimz = pres.shape[1]
     16272        dimt = pres.shape[0]
     16273        MODdimvs = {'time_counter':dimt, 'presnivs':dimz, 'lat':dimy, 'lon': dimx}
     16274        CFdimvs = {'time': dimt, 'presnivs': dimz, 'lat': dimy, 'lon': dimx}
     16275        unstaggerDIM = 'lon'
    1625116276
    1625216277    # sfc pressure
    1625316278    if modname == 'WRF':
    1625416279        ovar1 = onc.variables['PSFC']
     16280        psfc = ovar1[:].astype('float64')
     16281    elif modname == 'LMDZ':
     16282        ovar1 = onc.variables['psol']
    1625516283        psfc = ovar1[:].astype('float64')
    1625616284
     
    1626416292        geop = np.zeros(tuple(unstg), dtype=np.float)
    1626516293        geop = 0.5*(geop0[:,1:dimz,:,:] + geop0[:,0:dimz-1,:,:]).astype('float64')
     16294    elif modname == 'LMDZ':
     16295        ovar1 = onc.variables['geop']
     16296        geop = ovar1[:].astype('float64')
    1626616297
    1626716298    # terrain height
     
    1626916300        ovar1 = onc.variables['HGT']
    1627016301        hgt = ovar1[0,:,:].astype('float64')
     16302    elif modname == 'LMDZ':
     16303        grav = 9.81
     16304        ovar1 = onc.variables['phis']
     16305        hgt = (ovar1[0,:,:]/grav).astype('float64')
    1627116306
    1627216307    # water vapour mixing ratio
    1627316308    if modname == 'WRF':
    1627416309        ovar1 = onc.variables['QVAPOR']
     16310        qv = ovar1[:].astype('float64')
     16311    elif modname == 'LMDZ':
     16312        ovar1 = onc.variables['ovap']
    1627516313        qv = ovar1[:].astype('float64')
    1627616314
     
    1628316321        ovar1 = onc.variables['T']
    1628416322        temp = ((ovar1[:]+300.)*(pres[:]/p0)**RCP).astype('float64')
     16323    elif modname == 'LMDZ':
     16324        ovar1 = onc.variables['temp']
     16325        temp = ovar1[:].astype('float64')
    1628516326
    1628616327    onewnc = NetCDFFile(ofile, 'w')
     
    1629116332        newdim = onewnc.createDimension('pres', len(interplevs))
    1629216333        newdim = onewnc.createDimension('Time', None)
     16334    elif modname == 'LMDZ':
     16335        newdim = onewnc.createDimension('lon', dimx)
     16336        newdim = onewnc.createDimension('lat', dimy)
     16337        newdim = onewnc.createDimension('pres', len(interplevs))
     16338        newdim = onewnc.createDimension('time_counter', None)
    1629316339
    1629416340# Creation of variable dimensions
     
    1635616402                newvarattr['long_name'] = varattrs[4].replace('|',' ')
    1635716403                newvarattr['units'] = varattrs[5]
    16358         elif not gen.searchInlist(MODvarrequired, vn) or vn == 'QVAPOR':
     16404            elif vn == 'pres':
     16405                varin = pres
     16406                isgeop = False
     16407                varattrs = gen.variables_values('pres')
     16408                CFvn = varattrs[0]
     16409                newvarattr['standard_name'] = varattrs[1]
     16410                newvarattr['long_name'] = varattrs[4].replace('|',' ')
     16411                newvarattr['units'] = varattrs[5]
     16412#        elif not gen.searchInlist(MODvarrequired, vn) or vn == 'QVAPOR':
     16413        else:
    1635916414            ovarin = onc.variables[vn]
    1636016415            varinf = variable_inf(ovarin)
     
    1639316448
    1639416449            for attrn in newvarattr.keys():
    16395                 attr = set_attribute(newvar, attrn, newvarattr[attrn])
     16450                if attrn != '_FillValue' and not gen.searchInlist(CFattrs, attrn):
     16451                    attr = set_attribute(newvar, attrn, newvarattr[attrn])
    1639616452            onewnc.sync()
    1639716453
Note: See TracChangeset for help on using the changeset viewer.