Changeset 780 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
May 27, 2016, 5:19:37 PM (9 years ago)
Author:
lfita
Message:

Adding `ijlonlat': Function to provide the imin,jmin imax,jmax of a lon,lat box

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r775 r780  
    1919
    2020####### Content
     21# ijlonlat: Function to provide the imin,jmin imax,jmax of a lon,lat box
    2122# PolyArea: Function to compute the area of the polygon following 'Shoelace formula'
    2223
     
    62456246    return 0.5*np.abs(np.dot(x,np.roll(y,1))-np.dot(y,np.roll(x,1)))
    62466247
     6248def ijlonlat(lon, lat, nlon, xlon, nlat, xlat):
     6249    """ Function to provide the imin,jmin imax,jmax of a lon,lat box
     6250      lon= 2D matrix with the longitudes
     6251      lat= 2D matrix with the latitudes
     6252      nlon, xlon= minimun, maximum of the longitudes for the lon,lat box
     6253      nlat, xlat= minimun, maximum of the latitudes for the lon,lat box
     6254    """
     6255    fname = 'ijlonlat'
     6256
     6257    if nlon < np.min(lon):
     6258        print errormsg
     6259        print '  ' + fname + ': minimum longitude:',nlon,'too small!!'
     6260        print '    smallest possible:',np.min(lon)
     6261        quit(-1)
     6262    if xlon > np.max(lon):
     6263        print errormsg
     6264        print '  ' + fname + ': maximum longitude:',xlon,'too large!!'
     6265        print '    largest possible:',np.max(lon)
     6266        quit(-1)
     6267    if nlat < np.min(lat):
     6268        print errormsg
     6269        print '  ' + fname + ': minimum laitude:',nlat,'too small!!'
     6270        print '    smallest possible:',np.min(lat)
     6271        quit(-1)
     6272    if xlat > np.max(lat):
     6273        print errormsg
     6274        print '  ' + fname + ': maximum latitude:',xlat,'too large!!'
     6275        print '    largest possible:',np.max(lat)
     6276        quit(-1)
     6277
     6278    nlonv = np.abs(lon - nlon)
     6279    xlonv = np.abs(lon - xlon)
     6280    nlatv = np.abs(lat - nlat)
     6281    xlatv = np.abs(lat - xlat)
     6282
     6283    ni0 = index_mat(nlonv,np.min(nlonv))[1]
     6284    xi0 = index_mat(xlonv,np.min(xlonv))[1] + 1
     6285    nj0 = index_mat(nlatv,np.min(nlatv))[0]
     6286    xj0 = index_mat(xlatv,np.min(xlatv))[0] + 1
     6287
     6288    if ni0 > xi0:
     6289        ni = xi0
     6290        xi = ni0
     6291    else:
     6292        ni = ni0
     6293        xi = xi0
     6294
     6295    if nj0 > xj0:
     6296        nj = xj0
     6297        xj = nj0
     6298    else:
     6299        nj = nj0
     6300        xj = xj0
     6301
     6302    return ni,xi,nj,xj
     6303
Note: See TracChangeset for help on using the changeset viewer.