コード例 #1
0
def test_get_voronoi_latlon():
    """
    LatlonGridRemap.get_voronoi(): nlat=180, nlon=360 (regular)
    """
    from cube_remap import LatlonGridRemap
    from util.convert_coord.cart_ll import latlon2xyz

    nlat, nlon = 180, 360
    ll = LatlonGridRemap(nlat, nlon, "regular")

    ret = ll.get_voronoi(1)
    expect = [
        (-1.5707963267948966, 0),
        (-1.5447610285607269, 0.026179938779914945),
        (-1.5447610285607269, 0.008726646259971647),
    ]
    expect_xyz = [latlon2xyz(*latlon) for latlon in expect]
    aa_equal(expect_xyz, ret, 10)

    ret = ll.get_voronoi(nlon)
    expect = [
        (-1.5447610285607269, -0.00872664625997164),
        (-1.5447610285607269, 0.008726646259971647),
        (-1.5274041630712807, 0.008726646259971647),
        (-1.5274041630712807, -0.00872664625997164),
    ]
    expect_xyz = [latlon2xyz(*latlon) for latlon in expect]
    aa_equal(expect_xyz, ret, 10)
コード例 #2
0
def plot_ll_voronoi_polygon():
    """
    LatlonGridRemap.get_voronoi(): Plot with cube_basemap.py
    """
    from time import sleep
    from cube_remap import LatlonGridRemap
    from util.convert_coord.cs_ll import xyp2latlon, xyz2latlon
    from util.plot.cube_basemap import PlotSphere, draw_points, draw_polygon

    nlat, nlon = 90, 180
    ll_obj = LatlonGridRemap(nlat, nlon)
    print "nlat=%d, nlon=%d" % (nlat, nlon)

    # plot
    ps = PlotSphere(-90, 0, figsize=(15, 15), interact=True, draw_map=True)

    for idx in xrange(nlon, 2 * nlon + 1):
        lat0, lon0 = ll_obj.latlons[idx]
        # ll_vts = ll_obj.get_voronoi(idx)
        ll_vts = [xyz2latlon(*xyz) for xyz in ll_obj.get_voronoi(idx)]

        draw_points(ps.bmap, ll_vts)
        poly = draw_polygon(ps.bmap, ll_vts)
        poly.update(dict(fc="r"))

    ps.show(True)
コード例 #3
0
def test_ll_voronoi_area():
    """
    LatlonGridRemap.get_voronoi(): check the sphere area
    """
    from cube_remap import LatlonGridRemap
    from util.geometry.sphere import area_polygon
    from math import fsum, pi
    from util.convert_coord.cart_ll import latlon2xyz

    nlat, nlon = 90, 180
    # nlat, nlon = 180, 360
    # nlat, nlon = 360, 720
    # nlat, nlon = 720, 1440
    ll_obj = LatlonGridRemap(nlat, nlon)

    area_list = list()
    for idx in xrange(ll_obj.nsize):
        # latlons = ll_obj.get_voronoi(idx)
        # xyzs = [latlon2xyz(*latlon) for latlon in latlons]
        xyzs = ll_obj.get_voronoi(idx)
        area_list.append(area_polygon(xyzs))

    aa_equal(fsum(area_list), 4 * pi, 12)

    """
コード例 #4
0
def test_get_voronoi_latlon():
    '''
    LatlonGridRemap.get_voronoi(): nlat=180, nlon=360 (regular)
    '''
    from cube_remap import LatlonGridRemap

    nlat, nlon = 180, 360
    ll = LatlonGridRemap(nlat, nlon, 'regular')

    ret = ll.get_voronoi(1)
    expect = [(-1.5707963267948966, 0                   ), \
              (-1.5447610285607269, 0.026179938779914945), \
              (-1.5447610285607269, 0.008726646259971647)]
    aa_equal(expect, ret, 10)

    ret = ll.get_voronoi(nlon)
    expect = [(-1.5447610285607269,-0.00872664625997164), \
              (-1.5447610285607269, 0.008726646259971647), \
              (-1.5274041630712807, 0.008726646259971647), \
              (-1.5274041630712807,-0.00872664625997164)]
    aa_equal(expect, ret, 10)