issue_871a.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import numpy as np
  2. from vedo import settings, Plotter, Arrow, screenshot, \
  3. ScalarBar3D, Axes, mag, color_map, Assembly, Line
  4. settings.default_font = 'Theemim'
  5. settings.multi_samples=8
  6. filename = 'data/obs_xyz.dat'
  7. xyz = np.loadtxt(filename, dtype=np.float64)
  8. xyz = xyz[1:, :] - np.array([0, 20, 0])
  9. n_obs, n_col = xyz.shape
  10. # Read in the data
  11. num_field = np.loadtxt('data/tmp_field.txt', dtype=np.float64)
  12. amp = mag(num_field)
  13. # We need to create a few slices from the original arrays
  14. # First create a mask array to mark all receiver points with x = -10, 0, 10
  15. x_mark = [-19.5, -9.236842110, 1.026315790, 11.289473680, 19.5]
  16. y_mark = [-4.5, 4.5]
  17. mask = np.zeros(n_obs, dtype=bool)
  18. # We need to create a mask array to mark all receiver points with x being
  19. # any of x_mark and y being any of y_marko
  20. for x_m in x_mark:
  21. mask_local = np.abs(xyz[:, 0] - x_m) < 1e-6
  22. mask = np.logical_or(mask, mask_local)
  23. # Create an Arrows object for all the receivers where mask is True
  24. start = xyz[mask, :]
  25. orientation = num_field[mask, :]
  26. orientation = orientation / mag(orientation)[:, None] # normalize
  27. amp_mask = amp[mask]
  28. vrange = np.array([amp_mask.min(), amp_mask.max()])
  29. arrs = []
  30. for i in range(start.shape[0]):
  31. arr = Arrow(start[i], start[i] + orientation[i] * 4)
  32. color = color_map(
  33. amp_mask[i], "jet",
  34. vmin=vrange[0], vmax=vrange[1],
  35. )
  36. arr.color(color).lighting('off')
  37. arrs.append(arr)
  38. arrows = Assembly(arrs)
  39. # create a 2D scalarbar
  40. # scalarbar = ScalarBar(
  41. # vrange,
  42. # title='E (V/m)',
  43. # c="jet",
  44. # font_size=22,
  45. # pos=(0.7, 0.25),
  46. # size=(60,600),
  47. # )
  48. # create a dummy line to use as a 3D scalarbar
  49. pos = (-10, -14, -32)
  50. line = Line([0, 0], [1, 0]).cmap("jet", vrange * 1e6)
  51. scalarbar = ScalarBar3D(
  52. line,
  53. # c="white",
  54. title="E (:muV/m)",
  55. title_size=3,
  56. label_rotation=90,
  57. label_offset=.5,
  58. label_size=2,
  59. pos=pos,
  60. size=(1, 20),
  61. nlabels=5,
  62. )
  63. scalarbar.rotate_z(-90)
  64. size = (3920, 2160)
  65. plt = Plotter()
  66. axes = Axes(
  67. arrows,
  68. xtitle='Easting (m)',
  69. ytitle='Northing (m)',
  70. ztitle='Elevation (m)',
  71. xtitle_position=0.60,
  72. xlabel_size=0.018,
  73. xtitle_offset=0.15,
  74. ytitle_position=0.85,
  75. ylabel_rotation=-90,
  76. ylabel_size=0.02,
  77. ytitle_rotation=180,
  78. y_values_and_labels=[(-5, "-5"), (0, "0"), (5, "5")],
  79. axes_linewidth=4,
  80. xrange=arrows.xbounds(),
  81. yrange=arrows.ybounds(),
  82. zxgrid2=True,
  83. zshift_along_y=1,
  84. zaxis_rotation=-70,
  85. ztitle_size=0.02,
  86. ztitle_position=0.68,
  87. xyframe_line=True,
  88. grid_linewidth=2,
  89. )
  90. cam = dict(
  91. position=(-58.8911, -54.5234, 8.63461),
  92. focal_point=(-5.25549, -0.0457020, -23.8989),
  93. viewup=(0.248841, 0.304150, 0.919549),
  94. distance=83.0844,
  95. clipping_range=(34.8493, 143.093),
  96. )
  97. fig_name = 'data/electric_field.png'
  98. plt.show(arrows, axes, scalarbar, interactive=0, camera=cam)
  99. # screenshot(fig_name)
  100. plt.interactive().close()