Guest User

Untitled

a guest
May 19th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. # Minimum working example
  2.  
  3. import h5py
  4. import yt
  5. import numpy as np
  6. from yt.visualization.volume_rendering.transfer_function_helper import TransferFunctionHelper
  7. from yt.visualization.volume_rendering.api import Scene, VolumeSource
  8.  
  9. # Load data using uniform grid
  10. ds = h5py.File('/Volumes/triton/Data/ModelChallenge/R2349/rhybrid.h5')
  11. data = {k:v[:] for k,v in ds.items() if 'number_density' in k}
  12. bbox = np.array([[-4,4],[-4,4],[-4,4]])
  13. ds = yt.load_uniform_grid(data, data['H_p1_number_density'].shape, bbox=bbox)
  14.  
  15. # Create slice plots to see that the data has been correctly loaded
  16. p = yt.SlicePlot(ds, 'y',['H_p1_number_density', 'O2_p1_number_density'])
  17. p.set_zlim('H_p1_number_density', 1e-4,1000)
  18. p.set_zlim('O2_p1_number_density', 1e-4,1000)
  19. p.show()
  20.  
  21. # Start volume rendering------------------
  22.  
  23. # Initiatize scene and camera, try to make the vr look like sliceplots
  24. sc = Scene()
  25.  
  26. cam = sc.add_camera(ds, lens_type='perspective')
  27. cam.position = ds.arr([0,8,0], 'code_length')
  28. cam.focus = ds.arr([0,0,0], 'code_length')
  29. cam.north_vector = [1,0,0]
  30.  
  31.  
  32. # Create H+ data source, make a good transfer function and add it to the scene
  33. source = VolumeSource(ds.all_data(), 'H_p1_number_density')
  34.  
  35. tfh = TransferFunctionHelper(ds)
  36. tfh.set_field('H_p1_number_density')
  37. tfh.set_log(True)
  38. tfh.set_bounds((0.8,50))
  39. tfh.build_transfer_function()
  40. tfh.grey_opacity = True
  41. tfh.tf.add_layers(10, colormap='viridis')
  42.  
  43. source.set_transfer_function(tfh.tf)
  44. sc.add_source(source)
  45.  
  46.  
  47. # Create an O2+ data source, make a transfer function, and add it
  48. source = VolumeSource(ds.all_data(), 'O2_p1_number_density')
  49.  
  50. tfh = TransferFunctionHelper(ds)
  51. tfh.set_field('O2_p1_number_density')
  52. tfh.set_log(True)
  53. tfh.grey_opacity = True
  54. tfh.set_bounds((0.01,300))
  55. tfh.build_transfer_function()
  56. tfh.tf.add_layers(10, colormap='viridis')
  57. tfh.tf.map_to_colormap(-2.0,10.0, colormap='viridis', scale=0.4)
  58. source.set_transfer_function(tfh.tf)
  59. sc.add_source(source)
  60.  
  61.  
  62. # Render/show scene
  63. sc.render()
  64. sc.show(sigma_clip=6.0)
Advertisement
Add Comment
Please, Sign In to add comment