Changeset 2277 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Dec 28, 2018, 4:03:45 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `reglonlatbnds': cellboundaries using lon, lat from a reglar lon/lat projection as intersection of their related parallels and meridians
Location:
trunk/tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/diag_tools.py

    r2274 r2277  
    3232# Forcompute_cellbnds: Function to compute cellboundaries using wind-staggered lon,
    3333#   lats as intersection of their related parallels and meridians
     34# Forcompute_cellbndsreg: Function to compute cellboundaries using lon, lat from a
     35#   reglar lon/lat projection as intersection of their related parallels and meridians
    3436# Forcompute_cllmh: Function to compute cllmh: low/medium/hight cloud fraction
    3537#   following newmicro.F90 from LMDZ via Fortran subroutine
     
    566568        print '    vlon shape:', vlon.shape
    567569        print '    vlat shape:', vlat.shape
     570        quit(-1)
     571   
     572    xbnds = xbndst.transpose()
     573    ybnds = ybndst.transpose()
     574
     575    return xbnds, ybnds, dims, vdims
     576
     577
     578def Forcompute_cellbndsreg(lon, lat, dimns, dimvns):
     579    """ Function to compute cellboundaries using lon, lat from a reglar lon/lat
     580      projection as intersection of their related parallels and meridians
     581    compute_cellbnds(ulon, ulat, vlon, vlat, dimns, dimvns)
     582      [ulon]= x-staggered longitudes (assuming [y,x+1])
     583      [ulat]= x-staggered latitudes (assuming [y,x+1])
     584      [vlon]= y-staggered longitudes (assuming [y+1,x])
     585      [vlat]= y-staggered latitudes (assuming [y+1,x])
     586      [dimns]= list of the name of the dimensions of [cldfra]
     587      [dimvns]= list of the name of the variables with the values of the
     588        dimensions of [ulon]
     589    """
     590    fname = 'Forcompute_cellbndsreg'
     591
     592    dims = dimns[:]
     593    vdims = dimvns[:]
     594
     595    if len(lon.shape) == 2:
     596        dy = lon.shape[0]
     597        dx = lon.shape[1]
     598
     599        lont = lon.transpose()
     600        latt = lat.transpose()
     601
     602        xbndst, ybndst = fdin.module_fordiagnostics.compute_cellbndsreg(lon=lont,    \
     603          lat=latt, dx=dx, dy=dy)
     604    else:
     605        print errormsg
     606        print '  ' + fname + ": wrong rank of variables !!"
     607        print '    2D matrices are expected and its found instead'
     608        print '    lon shape:', lon.shape
     609        print '    lat shape:', lat.shape
    568610        quit(-1)
    569611   
  • trunk/tools/diagnostics.inf

    r2274 r2277  
    2222hurs, TSrhs, psfc@t@q
    2323hurs, WRFrhs, PSFC@T2@Q2
     24lat_bnds, reglonlatbnds, lon@lat
     25lon_bnds, reglonlatbnds, lon@lat
    2426lat_bnds, WRFbnds, XLONG_U@XLAT_U@XLONG_V@XLAT_V
    2527lon_bnds, WRFbnds, XLONG_U@XLAT_U@XLONG_V@XLAT_V
  • trunk/tools/diagnostics.py

    r2276 r2277  
    101101
    102102# Variables not to check
    103 NONcheckingvars = ['accum', 'cllmh', 'deaccum', 'face', 'LONLATdxdy', 'TSrhs',       \
    104   'TStd', 'TSwds', 'TSwss',                                                          \
     103NONcheckingvars = ['accum', 'cllmh', 'deaccum', 'face', 'LONLATdxdy',                \
     104  'reglonlatbnds', 'TSrhs', 'TStd', 'TSwds', 'TSwss',                                \
    105105  'WRFbils',  'WRFbnds',                                                             \
    106106  'WRFclivi', 'WRFclwvi', 'WRFdens', 'WRFdx', 'WRFdxdy', 'WRFdxdywps', 'WRFdy',      \
     
    891891        ncvar.set_attributek(ovar, 'h_valley_newrange', hvalleyrange, 'F')
    892892
     893# cell_bnds: grid cell bounds from lon, lat from a reglar lon/lat projection  as
     894#   intersection of their related parallels and meridians
     895    elif diagn == 'reglonlatbnds':
     896           
     897        var00 = ncobj.variables[depvars[0]][:]
     898        var01 = ncobj.variables[depvars[1]][:]
     899
     900        var0, var1 = gen.lonlat2D(var00,var01)
     901
     902        dnamesvar = []
     903        dnamesvar.append('bnds')
     904        if (len(var00.shape) == 3):
     905            dnamesvar.append(ncobj.variables[depvars[0]].dimensions[1])
     906            dnamesvar.append(ncobj.variables[depvars[0]].dimensions[2])
     907        elif (len(var00.shape) == 2):
     908            dnamesvar.append(ncobj.variables[depvars[0]].dimensions[0])
     909            dnamesvar.append(ncobj.variables[depvars[0]].dimensions[1])
     910        elif (len(var00.shape) == 1):
     911            dnamesvar.append(ncobj.variables[depvars[0]].dimensions[0])
     912            dnamesvar.append(ncobj.variables[depvars[1]].dimensions[0])
     913        dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames)
     914
     915        cellbndsx, cellbndsy, diagoutd, diagoutvd = diag.Forcompute_cellbndsreg(var0,\
     916          var1, dnamesvar, dvnamesvar)
     917
     918        # Removing the nonChecking variable-dimensions from the initial list
     919        varsadd = []
     920        diagoutvd = list(dvnames)
     921        for nonvd in NONchkvardims:
     922            if gen.searchInlist(dvnames,nonvd): diagoutvd.remove(nonvd)
     923            varsadd.append(nonvd)
     924        # creation of bounds dimension
     925        newdim = newnc.createDimension('bnds', 4)
     926
     927        ncvar.insert_variable(ncobj, 'lon_bnds', cellbndsx, diagoutd, diagoutvd, newnc)
     928        ncvar.insert_variable(ncobj, 'lat_bnds', cellbndsy, diagoutd, diagoutvd, newnc)
     929
    893930# cell_bnds: grid cell bounds from XLONG_U, XLAT_U, XLONG_V, XLAT_V as intersection
    894931#   of their related parallels and meridians
  • trunk/tools/module_ForDiagnostics.f90

    r2274 r2277  
    1818! compute_cellbnds: Subroutine to compute cellboundaries using wind-staggered lon, lats as
    1919!   intersection of their related parallels and meridians
     20! compute_cellbndsreg: Subroutine to compute cellboundaries using lon, lat from a reglar lon/lat
     21!   projection as intersection of their related parallels and meridians
    2022! compute_cllmh4D3: Computation of low, medium and high cloudiness from a 4D CLDFRA and pressure being
    2123!   3rd dimension the z-dim
     
    11581160    END DO
    11591161
     1162  END SUBROUTINE compute_cellbnds
     1163
     1164  SUBROUTINE compute_cellbndsreg(dx, dy, lon, lat, xbnds, ybnds)
     1165! Subroutine to compute cellboundaries using lon, lat from a reglar lon/lat projection as intersection
     1166!   of their related parallels and meridians
     1167
     1168    IMPLICIT NONE
     1169
     1170    INTEGER, INTENT(in)                                  :: dx, dy
     1171    REAL(r_k), DIMENSION(dx, dy), INTENT(in)             :: lon, lat
     1172    REAL(r_k), DIMENSION(dx, dy, 4), INTENT(out)         :: xbnds, ybnds
     1173
     1174! Local
     1175    INTEGER                                              :: i,j,iv
     1176    INTEGER                                              :: ix,ex,iy,ey
     1177    CHARACTER(len=2), DIMENSION(4)                       :: Svertex
     1178    INTEGER, DIMENSION(4,2,2,2)                          :: indices
     1179    REAL(r_k), DIMENSION(2)                              :: ptintsct
     1180    REAL(r_k), DIMENSION(2,2)                            :: merid, paral
     1181    LOGICAL                                              :: intsct
     1182
     1183!!!!!!! Variables
     1184! dx, dy: un-staggered dimensions
     1185! lon, lat: longitudes and latitudes
     1186! xbnds, ybnds: x and y cell boundaries
     1187
     1188    fname = 'compute_cellbndsreg'
     1189
     1190    ! Indices to use indices[SW/NW/NE/SE, m/p, x/y, i/e]
     1191    Svertex = (/ 'SW', 'NW', 'NE', 'SE' /)
     1192
     1193    ! SW
     1194    indices(1,1,1,1) = 0
     1195    indices(1,1,1,2) = 0
     1196    indices(1,1,2,1) = -1
     1197    indices(1,1,2,2) = 0
     1198    indices(1,2,1,1) = -1
     1199    indices(1,2,1,2) = 0
     1200    indices(1,2,2,1) = -1
     1201    indices(1,2,2,2) = -1
     1202    ! NW
     1203    indices(2,1,1,1) = 0
     1204    indices(2,1,1,2) = 0
     1205    indices(2,1,2,1) = 0
     1206    indices(2,1,2,2) = 1
     1207    indices(2,2,1,1) = -1
     1208    indices(2,2,1,2) = 0
     1209    indices(2,2,2,1) = 1
     1210    indices(2,2,2,2) = 1
     1211    ! NE
     1212    indices(3,1,1,1) = 1
     1213    indices(3,1,1,2) = 1
     1214    indices(3,1,2,1) = 0
     1215    indices(3,1,2,2) = 1
     1216    indices(3,2,1,1) = 0
     1217    indices(3,2,1,2) = 1
     1218    indices(3,2,2,1) = 1
     1219    indices(3,2,2,2) = 1
     1220    ! SE
     1221    indices(4,1,1,1) = 1
     1222    indices(4,1,1,2) = 1
     1223    indices(4,1,2,1) = -1
     1224    indices(4,1,2,2) = 0
     1225    indices(4,2,1,1) = 0
     1226    indices(4,2,1,2) = 1
     1227    indices(4,2,2,1) = -1
     1228    indices(4,2,2,2) = -1
     1229
     1230    DO i=1,dx
     1231      DO j=1,dy
     1232        DO iv=1,4
     1233
     1234          ix = MAX(i+indices(iv,1,1,1),1)
     1235          !ex = MIN(i+indices(iv,1,1,2),dx)
     1236          ex = i+indices(iv,1,1,2)
     1237          iy = MAX(j+indices(iv,1,2,1),1)
     1238          ey = MIN(j+indices(iv,1,2,2),dy)
     1239 
     1240          merid(1,1) = lon(ix,iy)
     1241          merid(1,2) = lat(ix,iy)
     1242          merid(2,1) = lon(ex,ey)
     1243          merid(2,2) = lat(ex,ey)
     1244
     1245          ix = MAX(i+indices(iv,2,1,1),1)
     1246          ex = MIN(i+indices(iv,2,1,2),dx)
     1247          iy = MAX(j+indices(iv,2,2,1),1)
     1248          !ey = MIN(i+indices(iv,2,2,2),dy)
     1249          ey = j+indices(iv,2,2,2)
     1250          paral(1,1) = lon(ix,iy)
     1251          paral(1,2) = lat(ix,iy)
     1252          paral(2,1) = lon(ex,ey)
     1253          paral(2,2) = lat(ex,ey)
     1254
     1255          CALL intersection_2Dlines(merid, paral, intsct, ptintsct)
     1256          IF (.NOT.intsct) THEN
     1257            msg = 'not interection found for ' // Svertex(iv) // ' vertex'
     1258            CALL ErrMsg(msg, fname, -1)
     1259          END IF
     1260          xbnds(i,j,iv) = ptintsct(1)
     1261          ybnds(i,j,iv) = ptintsct(2)
     1262        END DO
     1263      END DO
     1264    END DO
     1265
    11601266  END SUBROUTINE
    11611267
Note: See TracChangeset for help on using the changeset viewer.