コード例 #1
0
def test_cs_get_voronoi():
    '''
    CubeGridRemap.get_voronoi(): ne=30, some points
    '''
    from cube_remap import CubeGridRemap
    from scipy.spatial import voronoi_plot_2d
    import matplotlib.pyplot as plt

    ne, ngq = 30, 4
    rotated = False
    cube = CubeGridRemap(ne, ngq, rotated)

    uid = 0
    xy_vertices, vor = cube.get_voronoi(uid)
    expect = [( 4.54850726e-03, 3.80070853e-05), \
              ( 2.30716873e-03, 3.92011929e-03), \
              (-2.30716873e-03, 3.92011929e-03), \
              (-4.54850726e-03, 3.80070853e-05), \
              (-2.24133853e-03,-3.95812638e-03), \
              ( 2.24133853e-03,-3.95812638e-03)]
    aa_equal(expect, xy_vertices, 10)

    uid = 1
    xy_vertices, vor = cube.get_voronoi(uid)
    expect = [( 5.98890285e-03,-2.13793346e-03), \
              ( 5.01646021e-03, 3.93916864e-03), \
              (-2.27448976e-03, 3.93916864e-03), \
              (-4.54802687e-03,-7.61894981e-05), \
              (-7.97052613e-04,-6.32824066e-03), \
              ( 4.91440620e-03,-4.03563236e-03)]
    aa_equal(expect, xy_vertices, 10)
コード例 #2
0
def plot_cs_voronoi():
    '''
    CubeGridRemap.get_voronoi(): Plot
    '''
    from cube_remap import CubeGridRemap
    from scipy.spatial import voronoi_plot_2d
    import matplotlib.pyplot as plt

    #ne, ngq = 30, 4
    ne, ngq = 3, 4
    rotated = False
    cube = CubeGridRemap(ne, ngq, rotated)

    print 'ne=%d, ngq=%d'%(ne, ngq)

    for uid in xrange(20):
        xy_vertices, vor = cube.get_voronoi(uid)

        print ''
        print 'uid', uid
        print 'vor.vertices\n', vor.vertices
        print 'vor.ridge_points\n', vor.ridge_points
        print 'vor.ridge_vertices\n', vor.ridge_vertices
        print ''
        print 'xy_vertices\n', xy_vertices
        voronoi_plot_2d(vor)
        #plt.savefig('voronoi_%d.png'%uid)
        plt.show()
コード例 #3
0
def test_cs_voronoi_area():
    """
    CubeGridRemap.get_voronoi(): check the sphere area, ne=3
    """
    from cube_remap import CubeGridRemap
    from util.geometry.sphere import area_polygon
    from math import fsum, pi
    from util.convert_coord.cart_cs import xyp2xyz

    ne, ngq = 3, 4
    rotated = False
    cube = CubeGridRemap(ne, ngq, rotated)

    area_list = list()
    for uid in xrange(cube.up_size):
        # xy_vts, vor_obj = cube.get_voronoi_scipy(uid)
        # xyzs = [xyp2xyz(x,y,1) for x,y in xy_vts]
        # area_list.append( area_polygon(xyzs) )

        xyzs = cube.get_voronoi(uid)
        area_list.append(area_polygon(xyzs))

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

    """
コード例 #4
0
def plot_cs_voronoi_scipy():
    """
    CubeGridRemap.get_voronoi(): Plot with voronoi_plot_2d
    """
    from cube_remap import CubeGridRemap
    from scipy.spatial import voronoi_plot_2d
    import matplotlib.pyplot as plt

    # ne, ngq = 30, 4
    ne, ngq = 3, 4
    rotated = False
    cube = CubeGridRemap(ne, ngq, rotated)

    print "ne=%d, ngq=%d" % (ne, ngq)

    for uid in xrange(20):
        xy_vertices, vor = cube.get_voronoi(uid)

        print ""
        print "uid", uid
        print "vor.vertices\n", vor.vertices
        print "vor.ridge_points\n", vor.ridge_points
        print "vor.ridge_vertices\n", vor.ridge_vertices
        print ""
        print "xy_vertices\n", xy_vertices
        voronoi_plot_2d(vor)
        # plt.savefig('voronoi_%d.png'%uid)
        plt.show()
コード例 #5
0
def plot_cs_voronoi_polygon():
    """
    CubeGridRemap.get_voronoi(): Plot with cube_basemap.py
    """
    from time import sleep
    from cube_remap import CubeGridRemap
    from util.convert_coord.cs_ll import xyp2latlon, xyz2latlon
    from util.plot.cube_basemap import PlotSphere, draw_points, draw_polygon

    ne, ngq = 3, 4
    rotated = False
    cube = CubeGridRemap(ne, ngq, rotated)
    print "ne=%d, ngq=%d" % (ne, ngq)

    # plot
    ps = PlotSphere(0, 0, figsize=(15, 15), interact=True, draw_map=True)
    ps.draw_cube_panel(1)
    ps.draw_cube_panel(4)
    ps.draw_cube_panel(5)
    ps.draw_cube_elements(ne, 1)

    polys = list()
    for uid in xrange(1):
        lat0, lon0 = cube.latlons[uid]

        # xy_vts, vor_obj = cube.get_voronoi_scipy(uid)
        # ll_vts = [xyp2latlon(x,y,1,lat0,lon0) for x,y in xy_vts]

        xyz_vts = cube.get_voronoi(uid)
        ll_vts = [xyz2latlon(*xyz) for xyz in xyz_vts]
        print ll_vts

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

        polys.append(poly)
        # ps.draw()

        # polys[uid].set_facecolor('w')

    ps.show(True)
コード例 #6
0
def test_cs_get_voronoi_area():
    '''
    CubeGridRemap.get_voronoi(): check the sphere area, ne=3
    '''
    from cube_remap import CubeGridRemap
    from pkg.convert_coord.cart_cs import xyp2xyz
    from pkg.convert_coord.cart_rotate import xyz_rotate_reverse
    from area_sphere import area_polygon_sphere
    from math import fsum, pi

    ne, ngq = 3, 4
    rotated = False
    cube = CubeGridRemap(ne, ngq, rotated)

    area_list = list()
    for uid in xrange(cube.up_size):
        xy_list, vor = cube.get_voronoi(uid)
        xyzs = [xyp2xyz(x,y,1) for x,y in xy_list]
        area_list.append( area_polygon_sphere(xyzs) )

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