streamlines1.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """Streamlines originating from a set of seed points in space
  2. subjected to a vectorial field defined on a small set of points."""
  3. from vedo import *
  4. import pandas as pd
  5. data = "https://raw.githubusercontent.com/plotly/datasets/master/vortex.csv"
  6. df = pd.read_csv(data)
  7. pts = np.c_[df['x'], df['y'], df['z']]
  8. wind = np.c_[df['u'], df['v'], df['w']]
  9. vpts = Points(pts, r=10)
  10. vpts.pointdata["Wind"] = wind
  11. # Convert points to a volume to create a domain for the streamlines
  12. vol = vpts.tovolume(kernel='shepard', n=4, dims=(20,20,20))
  13. vol_pts = vol.coordinates
  14. iwind = vol.pointdata["Wind"] # interpolated wind
  15. arrs = Arrows(vol_pts, vol_pts + iwind*0.5, alpha=0.2)
  16. # Subsample the points to use as seed points
  17. seeds = vpts.clone().subsample(0.2)
  18. # Compute stream lines with Runge-Kutta integration
  19. # vol.pointdata.select("Wind") # in case there are other vectors
  20. streamlines = vol.compute_streamlines(seeds.points)
  21. streamlines.pointdata["wind_intensity"] = mag(streamlines.pointdata["Wind"])
  22. streamlines.cmap("Reds").add_scalarbar()
  23. print(streamlines)
  24. show(seeds, arrs, streamlines, __doc__, axes=1, viewup='z').close()
  25. # Create a tube around the streamlines
  26. streamtubes = Tubes(streamlines, r=0.01, vary_radius_by_scalar=True)
  27. streamtubes.cmap("Reds").add_scalarbar()
  28. print(streamtubes)
  29. show(streamtubes, __doc__, axes=1, viewup='z').close()