Plotting slices and volume rendering with yt


In [1]:
import numpy as np
import matplotlib.pyplot as plt
import nugridpy.utils as utils
from ppmpy import ppm
import os
import yt

dir_repo = '/data/ASDR'
dir_project = 'H-core-M25'
run = 'M35-1536'
dump = 425

path = os.path.join(dir_repo,dir_project,run)
moms = ppm.MomsDataSet(os.path.join(path,'myavsbq'),dump)


249 .aaa files found in '/data/ASDR/H-core-M25/M35-1536/myavsbq/.
Dump numbers range from 3 to 437.
Warning: Some dumps are missing!
The PPMstar grid is being constructed, this can take a moment

In [2]:
x,y,z = moms.get_cgrid()

res = moms.moms_resolution    # should be 384
vor_matrix = moms.get(6,dump)

In [3]:
data = dict(vorticity=vor_matrix)
bbox = np.array([[np.min(x),np.max(x)], [np.min(y),np.max(y)], [np.min(z),np.max(z)]])
ds = yt.load_uniform_grid(data=data, domain_dimensions=[res,res,res], length_unit='Mm', bbox=bbox)

slc = yt.SlicePlot(ds, normal='z', fields='vorticity', center='c', width=(np.diff(x)[0][0][0]*res, 'Mm'))
slc.set_log('vorticity', False)


yt : [INFO     ] 2018-12-01 11:49:18,153 Parameters: current_time              = 0.0
yt : [INFO     ] 2018-12-01 11:49:18,153 Parameters: domain_dimensions         = [384 384 384]
yt : [INFO     ] 2018-12-01 11:49:18,154 Parameters: domain_left_edge          = [-2493.48950195 -2493.48950195 -2493.48950195]
yt : [INFO     ] 2018-12-01 11:49:18,156 Parameters: domain_right_edge         = [2493.48950195 2493.48950195 2493.48950195]
yt : [INFO     ] 2018-12-01 11:49:18,157 Parameters: cosmological_simulation   = 0.0
yt : [INFO     ] 2018-12-01 11:49:18,639 xlim = -2500.031250 2500.031250
yt : [INFO     ] 2018-12-01 11:49:18,640 ylim = -2500.031250 2500.031250
yt : [INFO     ] 2018-12-01 11:49:18,641 xlim = -2500.031250 2500.031250
yt : [INFO     ] 2018-12-01 11:49:18,642 ylim = -2500.031250 2500.031250
yt : [INFO     ] 2018-12-01 11:49:18,644 Making a fixed resolution buffer of (('stream', 'vorticity')) 800 by 800
DEBUG:matplotlib.colorbar:locator: <matplotlib.colorbar._ColorbarLogLocator object at 0x7f26aa422d68>
DEBUG:matplotlib.colorbar:Using auto colorbar locator on colorbar
DEBUG:matplotlib.colorbar:locator: <matplotlib.colorbar._ColorbarLogLocator object at 0x7f26aa422d68>
DEBUG:matplotlib.colorbar:Setting pcolormesh
DEBUG:matplotlib.font_manager:findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to DejaVu Sans ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXGeneral:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to STIXGeneral ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXGeneral.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXGeneral:style=italic:variant=normal:weight=normal:stretch=normal:size=10.0 to STIXGeneral ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXGeneralItalic.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXGeneral:style=normal:variant=normal:weight=bold:stretch=normal:size=10.0 to STIXGeneral ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXGeneralBol.ttf') with score of 0.000000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXNonUnicode:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to STIXNonUnicode ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXNonUni.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXNonUnicode:style=italic:variant=normal:weight=normal:stretch=normal:size=10.0 to STIXNonUnicode ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXNonUniIta.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXNonUnicode:style=normal:variant=normal:weight=bold:stretch=normal:size=10.0 to STIXNonUnicode ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXNonUniBol.ttf') with score of 0.000000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXSizeOneSym:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to STIXSizeOneSym ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizOneSymReg.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXSizeTwoSym:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to STIXSizeTwoSym ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizTwoSymReg.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXSizeThreeSym:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to STIXSizeThreeSym ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizThreeSymReg.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXSizeFourSym:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to STIXSizeFourSym ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizFourSymReg.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=STIXSizeFiveSym:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to STIXSizeFiveSym ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizFiveSymReg.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=cmsy10:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to cmsy10 ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/cmsy10.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=cmr10:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to cmr10 ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/cmr10.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=cmtt10:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to cmtt10 ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/cmtt10.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=cmmi10:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to cmmi10 ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/cmmi10.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=cmb10:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to cmb10 ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/cmb10.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=cmss10:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to cmss10 ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/cmss10.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=cmex10:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to cmex10 ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/cmex10.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=DejaVu Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to DejaVu Sans ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=DejaVu Sans:style=italic:variant=normal:weight=normal:stretch=normal:size=10.0 to DejaVu Sans ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans-Oblique.ttf') with score of 0.150000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=DejaVu Sans:style=normal:variant=normal:weight=bold:stretch=normal:size=10.0 to DejaVu Sans ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans-Bold.ttf') with score of 0.000000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=DejaVu Sans Mono:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to DejaVu Sans Mono ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono.ttf') with score of 0.050000.
DEBUG:matplotlib.font_manager:findfont: Matching :family=DejaVu Sans Display:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to DejaVu Sans Display ('/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansDisplay.ttf') with score of 0.050000.
DEBUG:matplotlib.ticker:vmin 3.4225983382013617e-09 vmax 0.0002213875704910497
DEBUG:matplotlib.ticker:ticklocs array([1.e-10, 1.e-09, 1.e-08, 1.e-07, 1.e-06, 1.e-05, 1.e-04, 1.e-03,
       1.e-02])
DEBUG:matplotlib.colorbar:locator: <matplotlib.colorbar._ColorbarAutoLocator object at 0x7f26aa419ef0>
DEBUG:matplotlib.colorbar:Using auto colorbar locator on colorbar
DEBUG:matplotlib.colorbar:locator: <matplotlib.colorbar._ColorbarAutoLocator object at 0x7f26aa419ef0>
DEBUG:matplotlib.colorbar:Setting pcolormesh
DEBUG:matplotlib.colorbar:locator: <matplotlib.colorbar._ColorbarAutoLocator object at 0x7f26aa329da0>
DEBUG:matplotlib.colorbar:Using auto colorbar locator on colorbar
DEBUG:matplotlib.colorbar:locator: <matplotlib.colorbar._ColorbarAutoLocator object at 0x7f26aa329da0>
DEBUG:matplotlib.axes._base:update_title_pos
DEBUG:matplotlib.font_manager:findfont returning /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXGeneral.ttf
DEBUG:matplotlib.axes._base:update_title_pos
Out[3]:


In [4]:
sc = yt.create_scene(ds, 'vorticity')
source = sc[0]
source.set_log(False)


Out[4]:
<Volume Source>:YTRegion (UniformGridData): , center=[0. 0. 0.] cm, left_edge=[-2.4934895e+11 -2.4934895e+11 -2.4934895e+11] cm, right_edge=[2.4934895e+11 2.4934895e+11 2.4934895e+11] cm transfer_function:None

In [5]:
bounds = (0,1.8e-4)
tf = yt.ColorTransferFunction(x_bounds=bounds)
tf.add_gaussian(location=3.e-5, width=1.e-10, height=[0.5,1,1,0.03])   # [r,g,b,alpha]

# apply our transfer function to the source
source.tfh.tf = tf    # tfh is TransferFunctionHelper
source.tfh.bounds = bounds
source.tfh.plot(profile_field='vorticity')


DEBUG:matplotlib.axes._base:update_title_pos
Out[5]:

In [6]:
sc.camera.resolution = (1024,1024)
sc.camera.position=[1,1,1.5]
sc.show(sigma_clip=4.0)


yt : [INFO     ] 2018-12-01 11:50:13,033 Rendering scene (Can take a while).
yt : [INFO     ] 2018-12-01 11:50:13,038 Creating volume

In [9]:
sc2 = yt.create_scene(ds, 'vorticity')
sc2.show(sigma_clip=4.0)


yt : [INFO     ] 2018-12-01 11:54:42,155 Rendering scene (Can take a while).
yt : [INFO     ] 2018-12-01 11:54:42,158 Creating volume
yt : [INFO     ] 2018-12-01 11:54:45,462 Creating transfer function
yt : [INFO     ] 2018-12-01 11:54:45,463 Calculating data bounds. This may take a while.  Set the TransferFunctionHelper.bounds to avoid this.

In [8]:
sc2[0].tfh.plot(profile_field='vorticity')


DEBUG:matplotlib.axes._base:update_title_pos
DEBUG:matplotlib.ticker:vmin 3.4883105293204083e-09 vmax 0.0003656207991298287
DEBUG:matplotlib.ticker:ticklocs array([1.e-10, 1.e-09, 1.e-08, 1.e-07, 1.e-06, 1.e-05, 1.e-04, 1.e-03,
       1.e-02])
DEBUG:matplotlib.ticker:vmin 3.4883105293204083e-09 vmax 0.0003656207991298287
DEBUG:matplotlib.ticker:ticklocs [2e-10, 3e-10, 4e-10, 5e-10, 6e-10, 7.000000000000001e-10, 8e-10, 9e-10, 2e-09, 3.0000000000000004e-09, 4e-09, 5e-09, 6.000000000000001e-09, 7.000000000000001e-09, 8e-09, 9.000000000000001e-09, 2e-08, 3.0000000000000004e-08, 4e-08, 5e-08, 6.000000000000001e-08, 7e-08, 8e-08, 9e-08, 2e-07, 3e-07, 4e-07, 5e-07, 6e-07, 7e-07, 8e-07, 9e-07, 2e-06, 3e-06, 4e-06, 4.9999999999999996e-06, 6e-06, 7e-06, 8e-06, 9e-06, 2e-05, 3.0000000000000004e-05, 4e-05, 5e-05, 6.000000000000001e-05, 7.000000000000001e-05, 8e-05, 9e-05, 0.0002, 0.00030000000000000003, 0.0004, 0.0005, 0.0006000000000000001, 0.0007, 0.0008, 0.0009000000000000001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009000000000000001, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09]
DEBUG:matplotlib.ticker:vmin 3.4883105293204083e-09 vmax 0.0003656207991298287
DEBUG:matplotlib.ticker:ticklocs array([1.e-10, 1.e-09, 1.e-08, 1.e-07, 1.e-06, 1.e-05, 1.e-04, 1.e-03,
       1.e-02])
DEBUG:matplotlib.ticker:vmin 3.4883105293204083e-09 vmax 0.0003656207991298287
DEBUG:matplotlib.ticker:ticklocs [2e-10, 3e-10, 4e-10, 5e-10, 6e-10, 7.000000000000001e-10, 8e-10, 9e-10, 2e-09, 3.0000000000000004e-09, 4e-09, 5e-09, 6.000000000000001e-09, 7.000000000000001e-09, 8e-09, 9.000000000000001e-09, 2e-08, 3.0000000000000004e-08, 4e-08, 5e-08, 6.000000000000001e-08, 7e-08, 8e-08, 9e-08, 2e-07, 3e-07, 4e-07, 5e-07, 6e-07, 7e-07, 8e-07, 9e-07, 2e-06, 3e-06, 4e-06, 4.9999999999999996e-06, 6e-06, 7e-06, 8e-06, 9e-06, 2e-05, 3.0000000000000004e-05, 4e-05, 5e-05, 6.000000000000001e-05, 7.000000000000001e-05, 8e-05, 9e-05, 0.0002, 0.00030000000000000003, 0.0004, 0.0005, 0.0006000000000000001, 0.0007, 0.0008, 0.0009000000000000001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009000000000000001, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09]
DEBUG:matplotlib.ticker:vmin 0.07025388046931823 vmax 140.50776093863647
DEBUG:matplotlib.ticker:ticklocs array([1.e-03, 1.e-02, 1.e-01, 1.e+00, 1.e+01, 1.e+02, 1.e+03, 1.e+04])
DEBUG:matplotlib.ticker:vmin 0.07025388046931823 vmax 140.50776093863647
DEBUG:matplotlib.ticker:ticklocs [0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009000000000000001, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 200.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 2000.0, 3000.0, 4000.0, 5000.0, 6000.0, 7000.0, 8000.0, 9000.0, 20000.0, 30000.0, 40000.0, 50000.0, 60000.0, 70000.0, 80000.0, 90000.0]
DEBUG:matplotlib.ticker:vmin 0.07025388046931823 vmax 140.50776093863647
DEBUG:matplotlib.ticker:ticklocs array([1.e-03, 1.e-02, 1.e-01, 1.e+00, 1.e+01, 1.e+02, 1.e+03, 1.e+04])
DEBUG:matplotlib.ticker:vmin 0.07025388046931823 vmax 140.50776093863647
DEBUG:matplotlib.ticker:ticklocs [0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009000000000000001, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 200.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 2000.0, 3000.0, 4000.0, 5000.0, 6000.0, 7000.0, 8000.0, 9000.0, 20000.0, 30000.0, 40000.0, 50000.0, 60000.0, 70000.0, 80000.0, 90000.0]
Out[8]:

In [ ]:


In [ ]: