Exemple #1
0
    def test_multiple_fields(self):
        im, sc = yt.volume_render(self.ds)

        volume_source = sc.get_source(0)
        volume_source.set_field(("gas", "velocity_x"))
        volume_source.set_weight_field(("gas", "density"))
        sc.render()
Exemple #2
0
    def test_multiple_fields(self):
        im, sc = yt.volume_render(self.ds)

        volume_source = sc.get_source(0)
        volume_source.set_field(('gas', 'velocity_x'))
        volume_source.set_weight_field(('gas', 'density'))
        sc.render()
Exemple #3
0
    def test_rotation_volume_rendering(self):
        im, sc = yt.volume_render(self.ds)

        angle = 2 * np.pi
        frames = 4
        for i in range(frames):
            sc.camera.yaw(angle / frames)
            sc.render()
Exemple #4
0
    def test_modify_transfer_function(self):
        im, sc = yt.volume_render(self.ds)

        volume_source = sc.get_source(0)
        tf = volume_source.transfer_function
        tf.clear()
        tf.grey_opacity = True
        tf.add_layers(3, colormap='RdBu')
        sc.render()
Exemple #5
0
    def test_rotation_volume_rendering(self):
        im, sc = yt.volume_render(self.ds)

        sc.camera.yaw(np.pi)
        sc.render()
 def test_simple_vr(self):
     ds = fake_random_ds(32)
     im, sc = yt.volume_render(ds, fname="test.png", sigma_clip=4.0)
     return im, sc
from arepo import *
import numpy as np
import matplotlib.pyplot as plt
import yt
from yt.units import parsec, Msun

# Specification of the simulation
path = "/hits/universe/GigaGalaxy/level4_MHD_new/halo_L2/output/snapdir_127"
#snap = "/snapshot_063.hdf5"
#subSnap = "/fof_subhalo_tab_063.hdf5"

ds = yt.load(path)

##############################################################################################
# VOLUME RENDERING
##############################################################################################
field = 'gas', 'density'
im, sc = yt.volume_render(ds, field=field, fname="v0.png", sigma_clip=6.0)

sc.camera.set_width(ds.arr(0.1, 'code_length'))
tf = sc.get_source(0).transfer_function
tf.clear()
tf.add_layers(4,
              0.01,
              col_bounds=[-27.5, -25.5],
              alpha=np.logspace(-3, 0, 4),
              colormap='RdBu_r')
sc.render()
sc.save("v1.png", sigma_clip=6.0)
Exemple #8
0
import yt
import numpy as np

ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")

# We start by building a default volume rendering scene

im, sc = yt.volume_render(ds,
                          field=("gas", "density"),
                          fname="v0.png",
                          sigma_clip=6.0)

sc.camera.set_width(ds.arr(0.1, 'code_length'))
tf = sc.get_source().transfer_function
tf.clear()
tf.add_layers(4,
              0.01,
              col_bounds=[-27.5, -25.5],
              alpha=np.logspace(-3, 0, 4),
              colormap='RdBu_r')
sc.render()
sc.save("v1.png", sigma_clip=6.0)

# In this case, the default alphas used (np.logspace(-3,0,Nbins)) does not
# accentuate the outer regions of the galaxy. Let's start by bringing up the
# alpha values for each contour to go between 0.1 and 1.0

tf = sc.get_source().transfer_function
tf.clear()
tf.add_layers(4,
              0.01,
# This shows how to save ImageArray objects, such as those returned from
# volume renderings, to pngs with varying backgrounds.

# First we use the simple_volume_rendering.py recipe from above to generate
# a standard volume rendering.

import yt
import numpy as np

ds = yt.load("Enzo_64/DD0043/data0043")
im, sc = yt.volume_render(ds, 'density')
im.write_png("original.png", sigma_clip=8.0)

# Our image array can now be transformed to include different background
# colors.  By default, the background color is black.  The following
# modifications can be used on any image array.

# write_png accepts a background keyword argument that defaults to 'black'.
# Other choices include:
# black (0.,0.,0.,1.)
# white (1.,1.,1.,1.)
# None  (0.,0.,0.,0.) <-- Transparent!
# any rgba list/array: [r,g,b,a], bounded by 0..1

# We include the sigma_clip=8 keyword here to bring out more contrast between
# the background and foreground, but it is entirely optional.

im.write_png('black_bg.png', background='black', sigma_clip=8.0)
im.write_png('white_bg.png', background='white', sigma_clip=8.0)
im.write_png('green_bg.png', background=[0., 1., 0., 1.], sigma_clip=8.0)
im.write_png('transparent_bg.png', background=None, sigma_clip=8.0)
Exemple #10
0
import yt

ds = yt.load("RD0023/RD0023")
sc = yt.create_scene(ds)

im, sc = yt.volume_render(ds)
cam = sc.camera
sc.camera.resolution = (800, 800)
for i in cam.iter_zoom(100.0, 10):
    source = sc.sources['source_00']
    sc.add_source(source)
    tf = yt.ColorTransferFunction((-31, -26))
    tf.add_layers(5, w=0.01)
    source.set_transfer_function(tf)
    sc.render()
    sc.save("zoom_%04i.png" % i)

    #sc.camera.set_width(ds.quan(1, 'Mpc'))
#sc.show()
#sc.show(sigma_clip=4)
#sc.save('render_001',sigma_clip=4)
# Currently this cookbook is flawed in that the data that is covered by the
# higher resolution data gets masked during the rendering.  This should be
# fixed by changing either the data source or the code in
# yt/utilities/amr_kdtree.py where data is being masked for the partitioned
# grid.  Right now the quick fix is to create a data_collection, but this
# will only work for patch based simulations that have ds.index.grids.

# We begin by loading up yt, and importing the AMRKDTree
import numpy as np

import yt
from yt.utilities.amr_kdtree.api import AMRKDTree

# Load up a dataset and define the kdtree
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
im, sc = yt.volume_render(ds, ("gas", "density"), fname="v0.png")
sc.camera.set_width(ds.arr(100, "kpc"))
render_source = sc.get_source()
kd = render_source.volume

# Print out specifics of KD Tree
print("Total volume of all bricks = %i" % kd.count_volume())
print("Total number of cells = %i" % kd.count_cells())

new_source = ds.all_data()
new_source.max_level = 3
kd_low_res = AMRKDTree(ds, data_source=new_source)
print(kd_low_res.count_volume())
print(kd_low_res.count_cells())

# Now we pass this in as the volume to our camera, and render the snapshot
Exemple #12
0
                                                   data_source=ad)
z_projected_angular_momentum_x.set_cmap(field="angular_momentum_x", cmap='bwr')
z_projected_angular_momentum_x.save("z_projected_angular_momentum_x.png")

#Velocity along z direction of z-velocity
z_projected_z_velocity = yt.ProjectionPlot(ds, "z", "velocity_z")
z_projected_z_velocity.set_cmap(field="velocity_z", cmap='bwr')
z_projected_z_velocity.save("z_velocity_density_plot.png")

#Basic Probability Density Plots

plot_1D_PDF_Density = yt.ProfilePlot(ad, "density", "ones", weight_field=None)
plot_1D_PDF_Density.save("1D_PDF_Density.png")

#3d Render Plot for visualization of data.
im, sc = yt.volume_render(ds, field=('gas', 'density'))
source = sc[0]
# Set the bounds of the transfer function - EWR edited
source.tfh.set_bounds((1e-22, 1e-19))
# set that the transfer function should be evaluated in log space
source.tfh.set_log(True)
# Make underdense regions appear opaque
source.tfh.grey_opacity = True
# save the image, flooring especially bright pixels for better contrast
sc.save('data.0060.3d.hdf5_Render_density_fixed.png', sigma_clip=6.0)
##############################################################################

#Analysis of Data Section

# This creates a projection weighting by density
vz = ad.integrate('velocity_z', weight='density', axis='z')
Exemple #13
0
def doit(plotfile, fname):

    ds = yt.load(plotfile)

    if fname == "vz":
        field = ('gas', 'velocity_z')
        use_log = False
        
        vals = [-1.e7, -5.e6, 5.e6, 1.e7]
        sigma = 5.e5

        fmt = None

    elif fname == "magvel":
        field = ('gas', 'velocity_magnitude')
        use_log = True
        
        vals = [1.e5, 3.16e5, 1.e6, 3.16e6, 1.e7]
        sigma = 0.1

    elif fname == "enucdot":
        field = ('boxlib', 'enucdot')
        use_log = True

        vals = [1.e16, 3.162e16, 1.e17, 3.162e17, 1.e18]
        vals = list(10.0**numpy.array([16.5, 17.0, 17.5, 18.0, 18.5]))
        sigma = 0.05

        fmt = "%.3g"
    

    dd = ds.all_data()

    mi = min(vals)
    ma = max(vals)
    
    if use_log:
        mi, ma = np.log10(mi), np.log10(ma)
        
    # this is hackish, but there seems to be no better way to set whether
    # you are rendering logs
    ds._get_field_info("density").take_log = use_log

    print mi, ma

    # Instantiate the ColorTransferfunction.
    tf =  vr.ColorTransferFunction((mi, ma))
    cm = "gist_rainbow"

    for v in vals:
        if (use_log):
            print v, math.log10(v)
            tf.sample_colormap(math.log10(v), sigma**2, colormap=cm) #, alpha=0.2)
        else:
            tf.sample_colormap(v, sigma**2, colormap=cm) #, alpha=0.2)


    # an attempt to get around the periodic assumption -- suggested by Nathan
    #root_dds = pf.domain_width/pf.domain_dimensions
    #half_w = pf.domain_width/2.# - root_dds
    #half_w[2] -= root_dds[2]
    #reg = pf.region(pf.domain_center, pf.domain_center-half_w, pf.domain_center+half_w)


    # alternate attempt
    ds.periodicity = (True, True, True)

    # Create a camera object
    # Set up the camera parameters: center, looking direction, width, resolution
    c = (ds.domain_right_edge + ds.domain_left_edge)/2.0
    L = np.array([0.0, -1.0, -1.0])

    north_vector=[0.0,0.0,1.0]



    im, sc = yt.volume_render(ds, [field])

    source = sc.get_source(0)
    source.set_transfer_function(tf)
    source.transfer_function.grey_opacity=True

    # note: this needs to come AFTER the set_transfer_function(), or
    # else we get an AttributeError
    #sc.annotate_domain(ds)

    cam = sc.camera

    cam.resolution = (720,720)
    cam.set_width(3.0*ds.domain_width)
    cam.focus = c

    # we cannot seem to switch views and get an image...
    #cam.switch_view(north_vector=north_vector)
    #cam.switch_view(normal_vector=L)
    #cam.switch_orientation(L, north_vector)

    # make an image
    im = sc.render("test.png")
Exemple #14
0
# Currently this cookbook is flawed in that the data that is covered by the
# higher resolution data gets masked during the rendering.  This should be
# fixed by changing either the data source or the code in
# yt/utilities/amr_kdtree.py where data is being masked for the partitioned
# grid.  Right now the quick fix is to create a data_collection, but this
# will only work for patch based simulations that have ds.index.grids.

# We begin by loading up yt, and importing the AMRKDTree
import numpy as np

import yt
from yt.utilities.amr_kdtree.api import AMRKDTree

# Load up a dataset and define the kdtree
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
im, sc = yt.volume_render(ds, "density", fname="v0.png")
sc.camera.set_width(ds.arr(100, "kpc"))
render_source = sc.get_source()
kd = render_source.volume

# Print out specifics of KD Tree
print("Total volume of all bricks = %i" % kd.count_volume())
print("Total number of cells = %i" % kd.count_cells())

new_source = ds.all_data()
new_source.max_level = 3
kd_low_res = AMRKDTree(ds, data_source=new_source)
print(kd_low_res.count_volume())
print(kd_low_res.count_cells())

# Now we pass this in as the volume to our camera, and render the snapshot
Exemple #15
0
import yt

# This shows how to save ImageArray objects, such as those returned from
# volume renderings, to pngs with varying backgrounds.

# First we use the simple_volume_rendering.py recipe from above to generate
# a standard volume rendering.

ds = yt.load("Enzo_64/DD0043/data0043")
im, sc = yt.volume_render(ds, "density")
im.write_png("original.png", sigma_clip=8.0)

# Our image array can now be transformed to include different background
# colors.  By default, the background color is black.  The following
# modifications can be used on any image array.

# write_png accepts a background keyword argument that defaults to 'black'.
# Other choices include:
# black (0.,0.,0.,1.)
# white (1.,1.,1.,1.)
# None  (0.,0.,0.,0.) <-- Transparent!
# any rgba list/array: [r,g,b,a], bounded by 0..1

# We include the sigma_clip=8 keyword here to bring out more contrast between
# the background and foreground, but it is entirely optional.

im.write_png("black_bg.png", background="black", sigma_clip=8.0)
im.write_png("white_bg.png", background="white", sigma_clip=8.0)
im.write_png("green_bg.png", background=[0.0, 1.0, 0.0, 1.0], sigma_clip=8.0)
im.write_png("transparent_bg.png", background=None, sigma_clip=8.0)
Exemple #16
0
 def test_simple_volume_rendering(self):
     im, sc = yt.volume_render(self.ds, sigma_clip=4.0)
Exemple #17
0
# Currently this cookbook is flawed in that the data that is covered by the
# higher resolution data gets masked during the rendering.  This should be
# fixed by changing either the data source or the code in
# yt/utilities/amr_kdtree.py where data is being masked for the partitioned
# grid.  Right now the quick fix is to create a data_collection, but this
# will only work for patch based simulations that have ds.index.grids.

# We begin by loading up yt, and importing the AMRKDTree
import numpy as np

import yt
from yt.utilities.amr_kdtree.api import AMRKDTree

# Load up a dataset and define the kdtree
ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
im, sc = yt.volume_render(ds, 'density', fname='v0.png')
sc.camera.set_width(ds.arr(100, 'kpc'))
render_source = sc.get_source(0)
kd = render_source.volume

# Print out specifics of KD Tree
print("Total volume of all bricks = %i" % kd.count_volume())
print("Total number of cells = %i" % kd.count_cells())

new_source = ds.all_data()
new_source.max_level = 3
kd_low_res = AMRKDTree(ds, data_source=new_source)
print(kd_low_res.count_volume())
print(kd_low_res.count_cells())

# Now we pass this in as the volume to our camera, and render the snapshot
Exemple #18
0
import yt

# Load the dataset.
ds = yt.load("Enzo_64/DD0043/data0043")

# Create a volume rendering, which will determine data bounds, use the first
# acceptable field in the field_list, and set up a default transfer function.

# This will save a file named 'data0043_Render_density.png' to disk.
im, sc = yt.volume_render(ds, field=("gas", "density"))
Exemple #19
0
def doit(plotfile, fname):

    ds = yt.load(plotfile)

    if fname == "vz":
        field = ('gas', 'velocity_z')
        use_log = False

        vals = [-1.e7, -5.e6, 5.e6, 1.e7]
        sigma = 5.e5

        fmt = None

    elif fname == "magvel":
        field = ('gas', 'velocity_magnitude')
        use_log = True

        vals = [1.e5, 3.16e5, 1.e6, 3.16e6, 1.e7]
        sigma = 0.1

    elif fname == "enucdot":
        field = ('boxlib', 'enucdot')
        use_log = True

        vals = [1.e16, 3.162e16, 1.e17, 3.162e17, 1.e18]
        vals = list(10.0**numpy.array([16.5, 17.0, 17.5, 18.0, 18.5]))
        sigma = 0.05

        fmt = "%.3g"

    dd = ds.all_data()

    mi = min(vals)
    ma = max(vals)

    if use_log:
        mi, ma = np.log10(mi), np.log10(ma)

    # this is hackish, but there seems to be no better way to set whether
    # you are rendering logs
    ds._get_field_info("density").take_log = use_log

    print mi, ma

    # Instantiate the ColorTransferfunction.
    tf = vr.ColorTransferFunction((mi, ma))
    cm = "gist_rainbow"

    for v in vals:
        if (use_log):
            print v, math.log10(v)
            tf.sample_colormap(math.log10(v), sigma**2,
                               colormap=cm)  #, alpha=0.2)
        else:
            tf.sample_colormap(v, sigma**2, colormap=cm)  #, alpha=0.2)

    # an attempt to get around the periodic assumption -- suggested by Nathan
    #root_dds = pf.domain_width/pf.domain_dimensions
    #half_w = pf.domain_width/2.# - root_dds
    #half_w[2] -= root_dds[2]
    #reg = pf.region(pf.domain_center, pf.domain_center-half_w, pf.domain_center+half_w)

    # alternate attempt
    ds.periodicity = (True, True, True)

    # Create a camera object
    # Set up the camera parameters: center, looking direction, width, resolution
    c = (ds.domain_right_edge + ds.domain_left_edge) / 2.0
    L = np.array([0.0, -1.0, -1.0])

    north_vector = [0.0, 0.0, 1.0]

    im, sc = yt.volume_render(ds, [field])

    source = sc.get_source(0)
    source.set_transfer_function(tf)
    source.transfer_function.grey_opacity = True

    # note: this needs to come AFTER the set_transfer_function(), or
    # else we get an AttributeError
    #sc.annotate_domain(ds)

    cam = sc.camera

    cam.resolution = (720, 720)
    cam.set_width(3.0 * ds.domain_width)
    cam.focus = c

    # we cannot seem to switch views and get an image...
    #cam.switch_view(north_vector=north_vector)
    #cam.switch_view(normal_vector=L)
    #cam.switch_orientation(L, north_vector)

    # make an image
    im = sc.render("test.png")