#################### # Testing if __name__ == "__main__": Npnts = 50 pnts = np.random.random((Npnts, 2)) vals = np.random.random(Npnts) mt = tri.Triangulation(pnts[:, 0], pnts[:, 1]) import pylab pylab.figure() # tricontour: ax1 = pylab.subplot(2, 2, 1) tri.tricontourf(pylab.gca(), mt, vals) pylab.axis("equal") pylab.title("tri.Triangulation: tricontour") # delaunay - linear interpolation ax2 = pylab.subplot(2, 2, 2, sharex=ax1, sharey=ax1) d = tri_to_delaunay(mt) lin_interp = d.linear_interpolator(vals) lin_field = lin_interp[0.0:1.0:100j, 0.0:1.0:100j] pylab.imshow(lin_field, origin="lower", extent=[0, 1, 0, 1], interpolation="nearest") pylab.title("delaunay.Triangulation: linear interp") # delaunay - nearest neighbors interpolation pylab.subplot(2, 2, 3, sharex=ax1, sharey=ax1) d = tri_to_delaunay(mt) nn_interp = d.nn_interpolator(vals)
Npnts = 5000 pnts = np.random.random((Npnts, 2)) mt = tri.Triangulation(pnts[:, 0], pnts[:, 1]) # fabricate some data: point_vals = (pnts[:, 0] - 0.5)**2 + (pnts[:, 1] - 0.5)**2 # make an island by masking a few triangles island = ((mt.x[mt.triangles].mean(axis=1) - 0.75)**2 + (mt.y[mt.triangles].mean(axis=1) - 0.75)**2) < 0.03 mt.set_mask(island) import pylab pylab.figure() contour = tri.tricontourf(pylab.gca(), mt, point_vals) pylab.axis('equal') from shapely import geometry import wkb2shp geoms = [] vals = [] # tuples of vmin,vmax for colli, coll in enumerate(contour.collections): vmin, vmax = contour.levels[colli:colli + 2] for p in coll.get_paths(): p.simplify_threshold = 0.0 polys = p.to_polygons()
Npnts = 5000 pnts = np.random.random((Npnts,2)) mt = tri.Triangulation( pnts[:,0],pnts[:,1]) # fabricate some data: point_vals = (pnts[:,0]-0.5)**2 + (pnts[:,1]-0.5)**2 # make an island by masking a few triangles island = ((mt.x[mt.triangles].mean(axis=1) - 0.75)**2 + (mt.y[mt.triangles].mean(axis=1) - 0.75)**2) < 0.03 mt.set_mask( island ) import pylab pylab.figure() contour=tri.tricontourf(pylab.gca(),mt , point_vals) pylab.axis('equal') from shapely import geometry import wkb2shp geoms = [] vals = [] # tuples of vmin,vmax for colli,coll in enumerate(contour.collections): vmin,vmax = contour.levels[colli:colli+2] for p in coll.get_paths(): p.simplify_threshold = 0.0 polys = p.to_polygons()