earth_model.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. """Visualization of a discretized Earth model"""
  2. import vedo
  3. vedo.settings.default_font = 'Kanopus'
  4. tet = vedo.TetMesh(vedo.dataurl+'earth_model.vtu')
  5. conductor = tet.clone().threshold('cell_scalars', above=0, below=4)
  6. # Crop the initial mesh
  7. box = vedo.Box([503500, 505000, 6414000, 6417000, -1830, 600])
  8. tet.cut_with_mesh(box, whole_cells=True)
  9. # We need to build a look up table for our color bar
  10. lut_table = [
  11. #value, color, alpha, category_label
  12. ( 0.0, 'black', 1, "Cond_0"),
  13. ( 1.0, 'cyan', 1, "Cond_1"),
  14. ( 2.0, 'skyblue', 1, "Cond_2"),
  15. ( 3.0, 'dodgerblue', 1, "Cond_3"),
  16. ( 4.0, 'blue', 1, "Cond_4"),
  17. ( 5.0, 'gray', 1, "Overburden"),
  18. ( 6.0, 'yellow', 1, "Layer^A"),
  19. ( 7.0, 'gold', 1, "Layer^B"),
  20. ( 9.0, 'red', 1, "Layer^C"),
  21. (11.0, 'powderblue', 1, "Layer^D"),
  22. (13.0, 'lime', 1, "Layer^E"),
  23. (15.0, 'seagreen', 1, "Layer^V"),
  24. ]
  25. lut = vedo.build_lut(lut_table, interpolate=1)
  26. msh = tet.tomesh(shrink=0.95, fill=True)
  27. msh.cmap(lut, 'cell_scalars', on='cells')
  28. msh.add_scalarbar3d(
  29. categories=lut_table,
  30. pos=(505700, 6417950, -1630),
  31. title='Units',
  32. title_size=1.25,
  33. label_size=1.5,
  34. size=[100, 2200],
  35. )
  36. # Put scalarbar vertical, tell camera to keep bounds into account
  37. # msh.scalarbar.rotate_x(90).rotate_z(60).use_bounds(True)
  38. # OR: use clone2d to create a 2D scalarbar from the 3D one
  39. msh.scalarbar = msh.scalarbar.clone2d(pos=[0.7,-0.95], size=0.3)
  40. # Create cmap for conductor
  41. cond = conductor.tomesh().cmap(lut, 'cell_scalars', on='cells')
  42. axes = vedo.Axes(
  43. msh + cond,
  44. xtitle='Easting (m)',
  45. ytitle='Northing (m)',
  46. ztitle='Elevation (m)',
  47. xtitle_position=0.65,
  48. ytitle_position=0.65,
  49. ztitle_position=0.65,
  50. ytitle_offset=-0.22,
  51. ztitle_offset= 0.06,
  52. ylabel_rotation=90,
  53. ylabel_offset=-1.5,
  54. zaxis_rotation=15,
  55. axes_linewidth=3,
  56. grid_linewidth=2,
  57. yshift_along_x=1,
  58. tip_size=0,
  59. yzgrid=True,
  60. xyframe_line=True,
  61. )
  62. vedo.show(msh, cond, axes, __doc__, size=(1305, 1020),
  63. roll=-80, azimuth=50, elevation=-10, zoom=1.2).close()