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)
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)
Example #3
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)