Exemplo n.º 1
0
def ezgetlalo(nij, grtyp, refparam, xyAxis, hasAxis, ij0, doCorners):
    """Get Lat-Lon of grid points centers and corners
        (lat, lon, clat, clon) = Fstdc.ezgetlalo((niS, njS), grtypS, (grrefS, ig1S, ig2S, ig3S, ig4S), (xsS, ysS), hasSrcAxis, (i0S, j0S), doCorners)
        @param ...TODO...
        @return tuple of (numpy.ndarray) with center lat/lon (lat, lon) and optionally corners lat/lon (clat, clon)
        @exception TypeError
        @exception Fstdc.error
    """
    try:
        gid = _getGridHandle(nij[0], nij[1], grtyp,
                             refparam[0], refparam[1], refparam[2],
                             refparam[3], refparam[4],
                             ij0[0], ij0[1], xyAxis[0], xyAxis[1])
    except:
        raise error("ezgetlalo: Invalid Grid Desc")
    try:    
        gridLaLo = _rmn.gdll(gid);
    except:
        raise error("ezgetlalo: Problem computing lat, lon in ezscint")
    if not doCorners:
        return (gridLaLo['lat'], gridLaLo['lon'])
    xyc  = _rmn.gdxyfll(gid, gridLaLo['lat'], gridLaLo['lon'])
    xc1  = xyc['x']
    yc1  = xyc['y']
    nij2 = (4, gridLaLo['lat'].shape[0], gridLaLo['lat'].shape[1])
    xc4  = _np.empty(nij2, dtype=_np.float32, order='FORTRAN')
    yc4  = _np.empty(nij2, dtype=_np.float32, order='FORTRAN')
    ## x = _np.arange(float(nij2[1]))
    ## y = _np.arange(float(nij2[2]))
    ## fx = interpolate.interp2d(x, y, xc1, kind='linear', copy=False)
    ## fy = interpolate.interp2d(x, y, yc1, kind='linear', copy=False)
    dij_corners = (
        (-0.5, -0.5),  #SW
        (-0.5, 0.5),  #NW
        ( 0.5, 0.5),  #NE
        ( 0.5, -0.5)   #SE
        )
    for icorner in range(4):
        di = dij_corners[icorner][0]
        dj = dij_corners[icorner][1]
        ## xnew = x.copy('FORTRAN') + dij_corners[icorner][0]
        ## ynew = y.copy('FORTRAN') + dij_corners[icorner][1]
        ## xc4[icorner, :, :] = fx(xnew, ynew)
        ## yc4[icorner, :, :] = fy(xnew, ynew)
        xc4[icorner, :, :] = xc1[:, :] + dij_corners[icorner][0]
        yc4[icorner, :, :] = yc1[:, :] + dij_corners[icorner][1]
    llc = _rmn.gdllfxy(gid, xc4, yc4)
    return (gridLaLo['lat'], gridLaLo['lon'], llc['lat'], llc['lon'])
Exemplo n.º 2
0
def ezgetlalo(nij, grtyp, refparam, xyAxis, hasAxis, ij0, doCorners):
    """Get Lat-Lon of grid points centers and corners
        (lat, lon, clat, clon) = Fstdc.ezgetlalo((niS, njS), grtypS, (grrefS, ig1S, ig2S, ig3S, ig4S), (xsS, ysS), hasSrcAxis, (i0S, j0S), doCorners)
        @param ...TODO...
        @return tuple of (numpy.ndarray) with center lat/lon (lat, lon) and optionally corners lat/lon (clat, clon)
        @exception TypeError
        @exception Fstdc.error
    """
    try:
        gid = _getGridHandle(nij[0], nij[1], grtyp,
                             refparam[0], refparam[1], refparam[2],
                             refparam[3], refparam[4],
                             ij0[0], ij0[1], xyAxis[0], xyAxis[1])
    except:
        raise error("ezgetlalo: Invalid Grid Desc")
    try:    
        gridLaLo = _rmn.gdll(gid);
    except:
        raise error("ezgetlalo: Problem computing lat, lon in ezscint")
    if not doCorners:
        return (gridLaLo['lat'], gridLaLo['lon'])
    xyc  = _rmn.gdxyfll(gid, gridLaLo['lat'], gridLaLo['lon'])
    xc1  = xyc['x']
    yc1  = xyc['y']
    nij2 = (4, gridLaLo['lat'].shape[0], gridLaLo['lat'].shape[1])
    xc4  = _np.empty(nij2, dtype=_np.float32, order='FORTRAN')
    yc4  = _np.empty(nij2, dtype=_np.float32, order='FORTRAN')
    ## x = _np.arange(float(nij2[1]))
    ## y = _np.arange(float(nij2[2]))
    ## fx = interpolate.interp2d(x, y, xc1, kind='linear', copy=False)
    ## fy = interpolate.interp2d(x, y, yc1, kind='linear', copy=False)
    dij_corners = (
        (-0.5, -0.5),  #SW
        (-0.5, 0.5),  #NW
        ( 0.5, 0.5),  #NE
        ( 0.5, -0.5)   #SE
        )
    for icorner in xrange(4):
        di = dij_corners[icorner][0]
        dj = dij_corners[icorner][1]
        ## xnew = x.copy('FORTRAN') + dij_corners[icorner][0]
        ## ynew = y.copy('FORTRAN') + dij_corners[icorner][1]
        ## xc4[icorner, :, :] = fx(xnew, ynew)
        ## yc4[icorner, :, :] = fy(xnew, ynew)
        xc4[icorner, :, :] = xc1[:, :] + dij_corners[icorner][0]
        yc4[icorner, :, :] = yc1[:, :] + dij_corners[icorner][1]
    llc = _rmn.gdllfxy(gid, xc4, yc4)
    return (gridLaLo['lat'], gridLaLo['lon'], llc['lat'], llc['lon'])
Exemplo n.º 3
0
 def test_ezgkdef_fmem_gdllfxy(self):
     gp = self.getGridParams_ZE()
     gid1 = rmn.ezgdef_fmem(gp['ni'],gp['nj'],gp['grtyp'],gp['grref'],
                            gp['ig1ref'],gp['ig2ref'],gp['ig3ref'],gp['ig4ref'],
                            gp['ax'],gp['ay'])
     self.assertTrue(gid1>=0)
     xx = np.array([1.,2.],dtype=np.float32,order='FORTRAN')
     yy = np.array([1.,3.],dtype=np.float32,order='FORTRAN')
     llpts = rmn.gdllfxy(gid1, xx, yy)
     self.assertEqual(llpts['x'].shape,xx.shape)
     self.assertEqual(llpts['y'].shape,xx.shape)
     self.assertTrue(abs(llpts['lon'][0]-gp['ax'][0,0])<self.epsilon)
     self.assertTrue(abs(llpts['lat'][0]-gp['ay'][0,0])<self.epsilon)
     self.assertTrue(abs(llpts['lon'][1]-gp['ax'][1,0])<self.epsilon)
     self.assertTrue(abs(llpts['lat'][1]-gp['ay'][0,2])<self.epsilon)
     rmn.gdrls(gid1)
Exemplo n.º 4
0
 def test_ezgkdef_fmem_gdllfxy(self):
     gp = self.getGridParams_ZE()
     gid1 = rmn.ezgdef_fmem(gp['ni'],gp['nj'],gp['grtyp'],gp['grref'],
                            gp['ig1ref'],gp['ig2ref'],gp['ig3ref'],gp['ig4ref'],
                            gp['ax'],gp['ay'])
     self.assertTrue(gid1>=0)
     xx = np.array([1.,2.],dtype=np.float32,order='FORTRAN')
     yy = np.array([1.,3.],dtype=np.float32,order='FORTRAN')
     llpts = rmn.gdllfxy(gid1, xx, yy)
     self.assertEqual(llpts['x'].shape,xx.shape)
     self.assertEqual(llpts['y'].shape,xx.shape)
     self.assertTrue(abs(llpts['lon'][0]-gp['ax'][0,0])<self.epsilon)
     self.assertTrue(abs(llpts['lat'][0]-gp['ay'][0,0])<self.epsilon)
     self.assertTrue(abs(llpts['lon'][1]-gp['ax'][1,0])<self.epsilon)
     self.assertTrue(abs(llpts['lat'][1]-gp['ay'][0,2])<self.epsilon)
     rmn.gdrls(gid1)
Exemplo n.º 5
0
def gdllfxy(xin, yin, nij, grtyp, refparam, xyAxis, hasAxis, ij0):
    """Get (latitude, longitude) pairs cooresponding to (x, y) grid coordinates
    (lat, lon) = Fstdc.gdllfxy(xin, yin,
        (ni, nj), grtyp, (grref, ig1, ig2, ig3, ig4), (xs, ys), hasAxis, (i0, j0))
    @param xin, yin: input coordinates (as float32 numpy array)
    @param (ni, nj) .. (i0, j0): Grid definition parameters
    @return (lat, lon): Computed latitude and longitude coordinates
    """
    try:
        gid = _getGridHandle(nij[0], nij[1], grtyp,
                             refparam[0], refparam[1], refparam[2],
                             refparam[3], refparam[4],
                             ij0[0], ij0[1], xyAxis[0], xyAxis[1])
    except:
        raise error("gdllfxy: Invalid Grid Desc")
    try:
        ll  = _rmn.gdllfxy(gid, xin, yin)
    except:
        raise error("gdllfxy: Problem computing lat, lon coor")
    return (ll['lat'], ['lon'])
Exemplo n.º 6
0
def gdllfxy(xin, yin, nij, grtyp, refparam, xyAxis, hasAxis, ij0):
    """Get (latitude, longitude) pairs cooresponding to (x, y) grid coordinates
    (lat, lon) = Fstdc.gdllfxy(xin, yin,
        (ni, nj), grtyp, (grref, ig1, ig2, ig3, ig4), (xs, ys), hasAxis, (i0, j0))
    @param xin, yin: input coordinates (as float32 numpy array)
    @param (ni, nj) .. (i0, j0): Grid definition parameters
    @return (lat, lon): Computed latitude and longitude coordinates
    """
    try:
        gid = _getGridHandle(nij[0], nij[1], grtyp,
                             refparam[0], refparam[1], refparam[2],
                             refparam[3], refparam[4],
                             ij0[0], ij0[1], xyAxis[0], xyAxis[1])
    except:
        raise error("gdllfxy: Invalid Grid Desc")
    try:
        ll  = _rmn.gdllfxy(gid, xin, yin)
    except:
        raise error("gdllfxy: Problem computing lat, lon coor")
    return (ll['lat'], ['lon'])