コード例 #1
0
def test_get_surround_idxs_2():
    '''
    LatlonGridRemap.get_surround_idxs(): nlat=192, nlon=384 (gaussian)
    '''
    from cube_remap import LatlonGridRemap


    nlat, nlon = 192, 384
    tx = 1e-5
    ll = LatlonGridRemap(nlat, nlon, 'gaussian')

    # Near south pole
    lat0 = ll.tmp_lats[1]
    lon0 = ll.tmp_lons[7]
    ret_idxs = ll.get_surround_idxs(lat0-tx,lon0+tx)
    equal(ret_idxs, (7,-1,-1,-1))

    # Near north pole
    lat0 = ll.tmp_lats[-2]
    lon0 = ll.tmp_lons[-2]
    ret_idxs = ll.get_surround_idxs(lat0+tx,lon0+tx)
    equal(ret_idxs, (nlat*nlon-1,-1,-1,-1))

    # First box
    lat0 = ll.tmp_lats[1]
    lon0 = ll.tmp_lons[0]
    ret_idxs = ll.get_surround_idxs(lat0+tx,lon0+tx)
    a_equal(ret_idxs, [0,1,nlon,nlon+1])

    # Last box
    lat0 = ll.tmp_lats[-2]
    lon0 = ll.tmp_lons[-2]
    ret_idxs = ll.get_surround_idxs(lat0-tx,lon0+tx)
    a_equal(ret_idxs, [(nlat-1)*nlon-1, (nlat-2)*nlon, nlat*nlon-1, (nlat-1)*nlon])

    # Near Meridian
    lat0 = ll.tmp_lats[1]
    lon0 = ll.tmp_lons[-2]
    ret_idxs = ll.get_surround_idxs(lat0+tx,lon0+tx)
    a_equal(ret_idxs, [nlon-1,0,nlon*2-1,nlon])
コード例 #2
0
def test_get_surround_idxs():
    '''
    LatlonGridRemap.get_surround_idxs(): nlat=180, nlon=360 (regular)
    '''
    from cube_remap import LatlonGridRemap


    nlat, nlon = 180, 360
    tx = 1e-3
    ll = LatlonGridRemap(nlat, nlon, 'regular')

    # Near south pole
    lat0 = ll.tmp_lats[1]
    lon0 = ll.tmp_lons[7]
    ret_idxs = ll.get_surround_idxs(lat0-tx,lon0+tx)
    equal(ret_idxs, (7,-1,-1,-1))

    # Near north pole
    lat0 = ll.tmp_lats[-2]
    lon0 = ll.tmp_lons[-2]
    ret_idxs = ll.get_surround_idxs(lat0+tx,lon0+tx)
    equal(ret_idxs, (nlat*nlon-1,-1,-1,-1))

    # First box
    lat0 = ll.tmp_lats[1]
    lon0 = ll.tmp_lons[0]
    ret_idxs = ll.get_surround_idxs(lat0+tx,lon0+tx)
    a_equal(ret_idxs, [0,1,nlon,nlon+1])

    # Last box
    lat0 = ll.tmp_lats[-2]
    lon0 = ll.tmp_lons[-2]
    ret_idxs = ll.get_surround_idxs(lat0-tx,lon0+tx)
    a_equal(ret_idxs, [(nlat-1)*nlon-1, (nlat-2)*nlon, nlat*nlon-1, (nlat-1)*nlon])

    # Near Meridian
    lat0 = ll.tmp_lats[1]
    lon0 = ll.tmp_lons[-2]
    ret_idxs = ll.get_surround_idxs(lat0+tx,lon0+tx)
    a_equal(ret_idxs, [nlon-1,0,nlon*2-1,nlon])

    # Error cases
    lat, lon = -0.785398163397, 6.28318530718
    ret_idxs = ll.get_surround_idxs(lat,lon)
    a_equal(ret_idxs, [16199, 15840, 16559, 16200])