Changeset 1711 in lmdz_wrf


Ignore:
Timestamp:
Dec 12, 2017, 11:48:07 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `var_rh': Function to compute relative humidity following 'Tetens' equation (T,P) ...'
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/diag_tools.py

    r1710 r1711  
    3636# var_cllmh: Fcuntion to compute cllmh on a 1D column
    3737# var_clt: Function to compute the total cloud fraction following 'newmicro.F90' from LMDZ using 1D vertical column values
     38# var_rh: Function to compute relative humidity following 'Tetens' equation (T,P) ...'
    3839# var_mslp: Fcuntion to compute mean sea-level pressure
    3940# var_td: Function to compute dew-point air temperature from temperature and pressure values
     
    12641265    return wd
    12651266
     1267####### Variables (as they arrive without dimensions staff)
     1268
     1269def var_rh(p, t, q):
     1270    """ Function to compute relative humidity following 'Tetens' equation (T,P) ...'
     1271      [t]= temperature (assuming [[t],z,y,x] in [K])
     1272      [p] = pressure field (assuming in [hPa])
     1273      [q] = mixing ratio in [kgkg-1]
     1274    """
     1275    fname = 'var_rh'
     1276
     1277    data1 = 10.*0.6112*np.exp(17.67*(t-273.16)/(t-29.65))
     1278    data2 = 0.622*data1/(0.01*p-(1.-0.622)*data1)
     1279
     1280    rh = q/data2
     1281
     1282    return rh
     1283
    12661284def var_td(t, p, qv):
    12671285    """ Function to compute dew-point air temperature from temperature and pressure values
     
    13291347        self.units = None
    13301348
    1331         if Cdiag == 'td':
     1349        if Cdiag == 'hur':
     1350            """ Computing dew-point temperature
     1351            """
     1352            vn = 'hur'
     1353            CF3Dvars = ['ta', 'plev', 'hus']
     1354            for v3D in CF3Dvars:
     1355                if not vars3D.has_key(v3D):
     1356                    print gen.errormsg
     1357                    print '  ' + fname + ": missing variable '" + v3D +              \
     1358                      "' attribution to compute '" + vn + "' !!"
     1359                    print '  Equivalence of 3D variables provided _______'
     1360                    gen.printing_dictionary(vars3D)
     1361                    quit(-1)
     1362                if not self.incvars.has_key(vars3D[v3D]):
     1363                    print gen.errormsg
     1364                    print '  ' + fname + ": missing variable '" + vars3D[v3D] +      \
     1365                      "' in input file to compute '" + vn + "' !!"
     1366                    print '  available variables:', self.incvars.keys()
     1367                    print '  looking for variables _______' 
     1368                    gen.printing_dictionary(vars3D)
     1369                    quit(-1)
     1370
     1371            ta = ncobj.variables[vars3D['ta']][:]
     1372            p = ncobj.variables[vars3D['plev']][:]
     1373            hus = ncobj.variables[vars3D['hus']][:]
     1374
     1375            if len(ta.shape) != len(p.shape):
     1376                p = gen.fill_Narray(p, ta*0., filldim=[0,2,3])
     1377
     1378            self.values = var_rh(ta, p, hus)
     1379            self.dims = [dictdims['time'], dictdims['plev'], dictdims['lat'],        \
     1380              dictdims['lon']]
     1381            self.units = '1'
     1382
     1383        elif Cdiag == 'td':
    13321384            """ Computing dew-point temperature
    13331385            """
     
    13531405            ta = ncobj.variables[vars3D['ta']][:]
    13541406            p = ncobj.variables[vars3D['plev']][:]
    1355             hur = ncobj.variables[vars3D['hus']][:]
     1407            hus = ncobj.variables[vars3D['hus']][:]
    13561408
    13571409            if len(ta.shape) != len(p.shape):
    13581410                p = gen.fill_Narray(p, ta*0., filldim=[0,2,3])
    13591411
    1360             self.values = var_td(ta, p, hur)
     1412            self.values = var_td(ta, p, hus)
    13611413            self.dims = [dictdims['time'], dictdims['plev'], dictdims['lat'],        \
    13621414              dictdims['lon']]
Note: See TracChangeset for help on using the changeset viewer.