コード例 #1
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)
コード例 #2
0
def plot_voronoi(ncf):
    from util.convert_coord.cs_ll import xyp2latlon, xyz2latlon
    from util.plot.cube_basemap import PlotSphere, draw_points, draw_polygon


    # Read a NetCDF file
    gpt_xyzs = ncf.variables['gridpoints'][:]
    voronoi_xyzs = ncf.variables['voronois'][:]
    address = ncf.variables['voronoi_address'][:]


    # Plot with basemap
    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(80):
    #for uid in xrange(24,25):
        #print uid
        ll_gpt = xyz2latlon(*gpt_xyzs[uid])
        draw_points(ps.bmap, [ll_gpt], s=30)

        start = address[uid]
        end = address[uid+1] if uid < ncf.up_size-1 else ncf.up_size
        xyz_vts = voronoi_xyzs[start:end,:]
        ll_vts = [xyz2latlon(*xyz) for xyz in xyz_vts]

        draw_points(ps.bmap, ll_vts, c='r')
        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)