Exemple #1
0
def doit(plotfile):

    ds = yt.load(plotfile)
    ds.periodicity = (True, True, True)

    field = ('boxlib', 'radial_velocity')
    ds._get_field_info(field).take_log = False

    sc = Scene()

    # add a volume: select a sphere
    center = (0, 0, 0)
    R = (5.e8, 'cm')

    dd = ds.sphere(center, R)

    vol = VolumeSource(dd, field=field)
    vol.use_ghost_zones = True

    sc.add_source(vol)

    # transfer function
    vals = [-5.e6, -2.5e6, -1.25e6, 1.25e6, 2.5e6, 5.e6]
    sigma = 3.e5

    tf = yt.ColorTransferFunction((min(vals), max(vals)))

    tf.clear()
    cm = "coolwarm"
    for v in vals:
        tf.sample_colormap(v, sigma**2, colormap=cm)  #, alpha=0.2)

    sc.get_source(0).transfer_function = tf

    cam = sc.add_camera(ds, lens_type="perspective")
    cam.resolution = (1280, 720)
    cam.position = 1.5 * ds.arr(np.array([5.e8, 5.e8, 5.e8]), 'cm')

    # look toward the center -- we are dealing with an octant
    center = ds.domain_left_edge
    normal = (center - cam.position)
    normal /= np.sqrt(normal.dot(normal))

    cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
    cam.set_width(ds.domain_width)

    #sc.annotate_axes()
    #sc.annotate_domain(ds)

    sc.render()
    sc.save("subchandra_test.png", sigma_clip=6.0)
    sc.save_annotated(
        "subchandra_test_annotated.png",
        text_annotate=[[(0.05, 0.05), "t = {}".format(ds.current_time.d),
                        dict(horizontalalignment="left")],
                       [(0.5, 0.95),
                        "Maestro simulation of He convection on a white dwarf",
                        dict(color="y",
                             fontsize="24",
                             horizontalalignment="center")]])
Exemple #2
0
    def test_points_vr(self):
        ds = fake_random_ds(64)
        dd = ds.sphere(ds.domain_center, 0.45 * ds.domain_width[0])
        ds.field_info[ds.field_list[0]].take_log = False

        sc = Scene()
        cam = sc.add_camera(ds)
        cam.resolution = (512, 512)
        vr = VolumeSource(dd, field=ds.field_list[0])
        vr.transfer_function.clear()
        vr.transfer_function.grey_opacity = False
        vr.transfer_function.map_to_colormap(0.0,
                                             1.0,
                                             scale=10.,
                                             colormap="Reds")
        sc.add_source(vr)

        cam.set_width(1.8 * ds.domain_width)
        cam.lens.setup_box_properties(cam)

        # DRAW SOME POINTS
        npoints = 1000
        vertices = np.random.random([npoints, 3])
        colors = np.random.random([npoints, 4])
        colors[:, 3] = 0.10

        points_source = PointSource(vertices, colors=colors)
        sc.add_source(points_source)
        im = sc.render()
        im.write_png("points.png")
        return im
Exemple #3
0
    def test_composite_vr(self):
        ds = fake_random_ds(64)
        dd = ds.sphere(ds.domain_center, 0.45 * ds.domain_width[0])
        ds.field_info[ds.field_list[0]].take_log = False

        sc = Scene()
        cam = sc.add_camera(ds)
        cam.resolution = (512, 512)
        vr = VolumeSource(dd, field=ds.field_list[0])
        vr.transfer_function.clear()
        vr.transfer_function.grey_opacity = True
        vr.transfer_function.map_to_colormap(0.0, 1.0, scale=10.0, colormap="Reds")
        sc.add_source(vr)

        cam.set_width(1.8 * ds.domain_width)
        cam.lens.setup_box_properties(cam)

        # Create Arbitrary Z-buffer
        empty = cam.lens.new_image(cam)
        z = np.empty(empty.shape[:2], dtype="float64")
        # Let's put a blue plane right through the center
        z[:] = cam.width[2] / 2.0
        empty[:, :, 2] = 1.0  # Set blue to 1's
        empty[:, :, 3] = 1.0  # Set alpha to 1's
        zbuffer = ZBuffer(empty, z)
        zsource = OpaqueSource()
        zsource.set_zbuffer(zbuffer)
        sc.add_source(zsource)

        im = sc.render()
        im.write_png("composite.png")
Exemple #4
0
 def test_perspective_lens(self):
     sc = Scene()
     cam = sc.add_camera(self.ds, lens_type="perspective")
     cam.position = self.ds.arr(np.array([1.0, 1.0, 1.0]), "code_length")
     vol = VolumeSource(self.ds, field=self.field)
     tf = vol.transfer_function
     tf.grey_opacity = True
     sc.add_source(vol)
     sc.save("test_perspective_%s.png" % self.field[1], sigma_clip=6.0)
Exemple #5
0
 def test_stereoperspective_lens(self):
     sc = Scene()
     cam = sc.add_camera(self.ds, lens_type="stereo-perspective")
     cam.resolution = [256, 128]
     cam.position = self.ds.arr(np.array([0.7, 0.7, 0.7]), "code_length")
     vol = VolumeSource(self.ds, field=self.field)
     tf = vol.transfer_function
     tf.grey_opacity = True
     sc.add_source(vol)
     sc.save(f"test_stereoperspective_{self.field[1]}.png", sigma_clip=6.0)
Exemple #6
0
 def test_spherical_lens(self):
     sc = Scene()
     cam = sc.add_camera(self.ds, lens_type="spherical")
     cam.resolution = [256, 128]
     cam.position = self.ds.arr(np.array([0.6, 0.5, 0.5]), "code_length")
     vol = VolumeSource(self.ds, field=self.field)
     tf = vol.transfer_function
     tf.grey_opacity = True
     sc.add_source(vol)
     sc.save("test_spherical_%s.png" % self.field[1], sigma_clip=6.0)
Exemple #7
0
 def test_plane_lens(self):
     dd = self.ds.sphere(self.ds.domain_center, self.ds.domain_width[0] / 10)
     sc = Scene()
     cam = sc.add_camera(dd, lens_type="plane-parallel")
     cam.set_width(self.ds.domain_width * 1e-2)
     v, c = self.ds.find_max("density")
     vol = VolumeSource(dd, field=self.field)
     tf = vol.transfer_function
     tf.grey_opacity = True
     sc.add_source(vol)
     sc.save("test_plane_%s.png" % self.field[1], sigma_clip=6.0)
Exemple #8
0
 def test_stereoperspective_lens(self):
     sc = Scene()
     cam = sc.add_camera(self.ds, lens_type='stereo-perspective')
     cam.resolution = [1024, 512]
     cam.position = self.ds.arr(np.array([0.7, 0.7, 0.7]), 'code_length')
     vol = VolumeSource(self.ds, field=self.field)
     tf = vol.transfer_function
     tf.grey_opacity = True
     sc.add_source(vol)
     sc.render()
     sc.save('test_stereoperspective_%s.png' % self.field[1], sigma_clip=6.0)
Exemple #9
0
 def test_spherical_lens(self):
     sc = Scene()
     cam = sc.add_camera(self.ds, lens_type='spherical')
     cam.resolution = [512, 256]
     cam.position = self.ds.arr(np.array([0.6, 0.5, 0.5]), 'code_length')
     vol = VolumeSource(self.ds, field=self.field)
     tf = vol.transfer_function
     tf.grey_opacity = True
     sc.add_source(vol)
     sc.render()
     sc.save('test_spherical_%s.png' % self.field[1], sigma_clip=6.0)
Exemple #10
0
def doit(plotfile):

    ds = yt.load(plotfile)
    ds.periodicity = (True, True, True)

    cm = "coolwarm"

    field = ('boxlib', 'radial_velocity')
    ds._get_field_info(field).take_log = False

    sc = Scene()

    # add a volume: select a sphere
    #center = (0, 0, 0)
    #R = (5.e8, 'cm')

    #dd = ds.sphere(center, R)

    vol = VolumeSource(ds, field=field)
    sc.add_source(vol)

    # transfer function
    vals = [-5.e5, -2.5e5, -1.25e5, 1.25e5, 2.5e5, 5.e5]
    sigma = 3.e4

    tf = yt.ColorTransferFunction((min(vals), max(vals)))

    tf.clear()
    cm = "coolwarm"
    for v in vals:
        tf.sample_colormap(v, sigma**2, colormap=cm)  #, alpha=0.2)

    sc.get_source(0).transfer_function = tf

    cam = sc.add_camera(ds, lens_type="perspective")
    cam.resolution = (1080, 1080)
    cam.position = 1.0 * ds.domain_right_edge

    # look toward the center -- we are dealing with an octant
    center = ds.domain_left_edge
    normal = (center - cam.position)
    normal /= np.sqrt(normal.dot(normal))

    cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
    cam.set_width(ds.domain_width)

    sc.camera = cam
    #sc.annotate_axes(alpha=0.05)
    #sc.annotate_domain(ds, color=np.array([0.05, 0.05, 0.05, 0.05]))
    #sc.annotate_grids(ds, alpha=0.05)

    sc.render()
    sc.save("{}_radvel".format(plotfile), sigma_clip=4.0)
Exemple #11
0
 def test_stereospherical_lens(self):
     w = (self.ds.domain_width).in_units("code_length")
     w = self.ds.arr(w, "code_length")
     sc = Scene()
     cam = sc.add_camera(self.ds, lens_type="stereo-spherical")
     cam.resolution = [512, 512]
     cam.position = self.ds.arr(np.array([0.6, 0.5, 0.5]), "code_length")
     vol = VolumeSource(self.ds, field=self.field)
     tf = vol.transfer_function
     tf.grey_opacity = True
     sc.add_source(vol)
     sc.save("test_stereospherical_%s.png" % self.field[1], sigma_clip=6.0)
Exemple #12
0
 def test_fisheye_lens(self):
     dd = self.ds.sphere(self.ds.domain_center, self.ds.domain_width[0] / 10)
     sc = Scene()
     cam = sc.add_camera(dd, lens_type="fisheye")
     cam.lens.fov = 360.0
     cam.set_width(self.ds.domain_width)
     v, c = self.ds.find_max("density")
     cam.set_position(c - 0.0005 * self.ds.domain_width)
     vol = VolumeSource(dd, field=self.field)
     tf = vol.transfer_function
     tf.grey_opacity = True
     sc.add_source(vol)
     sc.save("test_fisheye_%s.png" % self.field[1], sigma_clip=6.0)
Exemple #13
0
    def test_composite_vr(self):
        ds = fake_random_ds(64)
        dd = ds.sphere(ds.domain_center, 0.45 * ds.domain_width[0])
        ds.field_info[ds.field_list[0]].take_log = False

        sc = Scene()
        cam = sc.add_camera(ds)
        cam.resolution = (512, 512)
        vr = VolumeSource(dd, field=ds.field_list[0])
        vr.transfer_function.clear()
        vr.transfer_function.grey_opacity = True
        vr.transfer_function.map_to_colormap(0.0,
                                             1.0,
                                             scale=3.0,
                                             colormap="Reds")
        sc.add_source(vr)

        cam.set_width(1.8 * ds.domain_width)
        cam.lens.setup_box_properties(cam)

        # DRAW SOME LINES
        npoints = 100
        vertices = np.random.random([npoints, 2, 3])
        colors = np.random.random([npoints, 4])
        colors[:, 3] = 0.10

        box_source = BoxSource(ds.domain_left_edge,
                               ds.domain_right_edge,
                               color=[1.0, 1.0, 1.0, 1.0])
        sc.add_source(box_source)

        LE = ds.domain_left_edge + np.array([0.1, 0., 0.3
                                             ]) * ds.domain_left_edge.uq
        RE = ds.domain_right_edge - np.array([0.1, 0.2, 0.3
                                              ]) * ds.domain_left_edge.uq
        color = np.array([0.0, 1.0, 0.0, 0.10])
        box_source = BoxSource(LE, RE, color=color)
        sc.add_source(box_source)

        line_source = LineSource(vertices, colors)
        sc.add_source(line_source)

        im = sc.render()
        im = ImageArray(im.d)
        im.write_png("composite.png")
        return im
Exemple #14
0
    def test_rotation(self):
        ds = fake_random_ds(32)
        ds2 = fake_random_ds(32)
        dd = ds.sphere(ds.domain_center, ds.domain_width[0] / 2)
        dd2 = ds2.sphere(ds2.domain_center, ds2.domain_width[0] / 2)

        im, sc = volume_render(dd, field=('gas', 'density'))
        im.write_png('test.png')

        vol = sc.get_source(0)
        tf = vol.transfer_function
        tf.clear()
        mi, ma = dd.quantities.extrema('density')
        mi = np.log10(mi)
        ma = np.log10(ma)
        mi_bound = ((ma - mi) * (0.10)) + mi
        ma_bound = ((ma - mi) * (0.90)) + mi
        tf.map_to_colormap(mi_bound, ma_bound, scale=0.01, colormap='Blues_r')

        vol2 = VolumeSource(dd2, field=('gas', 'density'))
        sc.add_source(vol2)

        tf = vol2.transfer_function
        tf.clear()
        mi, ma = dd2.quantities.extrema('density')
        mi = np.log10(mi)
        ma = np.log10(ma)
        mi_bound = ((ma - mi) * (0.10)) + mi
        ma_bound = ((ma - mi) * (0.90)) + mi
        tf.map_to_colormap(mi_bound, ma_bound, scale=0.01, colormap='Reds_r')
        sc.render()
        for suffix in ['png', 'eps', 'ps', 'pdf']:
            fname = 'test_scene.{}'.format(suffix)
            sc.save(fname, sigma_clip=6.0)
            assert_fname(fname)

        nrot = 2
        for i in range(nrot):
            sc.camera.pitch(2 * np.pi / nrot)
            sc.render()
            sc.save('test_rot_%04i.png' % i, sigma_clip=6.0)
Exemple #15
0
    def test_rotation(self):
        ds = fake_random_ds(32)
        ds2 = fake_random_ds(32)
        dd = ds.sphere(ds.domain_center, ds.domain_width[0] / 2)
        dd2 = ds2.sphere(ds2.domain_center, ds2.domain_width[0] / 2)

        im, sc = volume_render(dd, field=("gas", "density"))
        im.write_png("test.png")

        vol = sc.get_source(0)
        tf = vol.transfer_function
        tf.clear()
        mi, ma = dd.quantities.extrema("density")
        mi = np.log10(mi)
        ma = np.log10(ma)
        mi_bound = ((ma - mi) * (0.10)) + mi
        ma_bound = ((ma - mi) * (0.90)) + mi
        tf.map_to_colormap(mi_bound, ma_bound, scale=0.01, colormap="Blues_r")

        vol2 = VolumeSource(dd2, field=("gas", "density"))
        sc.add_source(vol2)

        tf = vol2.transfer_function
        tf.clear()
        mi, ma = dd2.quantities.extrema("density")
        mi = np.log10(mi)
        ma = np.log10(ma)
        mi_bound = ((ma - mi) * (0.10)) + mi
        ma_bound = ((ma - mi) * (0.90)) + mi
        tf.map_to_colormap(mi_bound, ma_bound, scale=0.01, colormap="Reds_r")
        fname = "test_scene.pdf"
        sc.save(fname, sigma_clip=6.0)
        assert_fname(fname)

        fname = "test_rot.png"
        sc.camera.pitch(np.pi)
        sc.save(fname, sigma_clip=6.0)
        assert_fname(fname)
def _pos_radial_velocity(field, data):
    return np.maximum(data[('boxlib','radial_velocity')], 1.0e-99)
@derived_field(name='neg_radial_velocity', units='cm/s')
def _neg_radial_velocity(field, data):
    return np.maximum(-data[('boxlib','radial_velocity')], 1.0e-99)

# Open Dataset
ds = yt.load(args.infile)
core = ds.sphere(ds.domain_center, (args.rup, 'cm'))

# Create Scene
sc = Scene()

# Create Sources
#so_enuc = VolumeSource(core, ('boxlib','enucdot'))
so_pos_vrad = VolumeSource(core, 'pos_radial_velocity')
so_neg_vrad = VolumeSource(core, 'neg_radial_velocity')

# Assign Transfer Functions to Sources
# tfh_en = TransferFunctionHelper(ds)
# tfh_en.set_field(('boxlib','enucdot'))
# tfh_en.set_log(True)
# tfh_en.set_bounds()
# tfh_en.build_transfer_function()
# tfh_en.tf.add_layers(10, colormap='black_green', w=0.01)
# tfh_en.grey_opacity = False
# tfh_en.plot('{}_tfun_enuc.png'.format(args.infile), profile_field=('boxlib','enucdot'))
# so_enuc.transfer_function = tfh_en.tf

mag_vel_bounds = np.array([1.0e4, 1.0e6])
mag_vel_sigma  = 0.08
Exemple #17
0
def test_orientation():
    ds = fake_vr_orientation_test_ds()

    sc = Scene()

    vol = VolumeSource(ds, field=('gas', 'density'))
    sc.add_source(vol)

    tf = vol.transfer_function
    tf = ColorTransferFunction((0.1, 1.0))
    tf.sample_colormap(1.0, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.8, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.6, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.3, 0.01, colormap="coolwarm")

    n_frames = 1
    orientations = [[-0.3, -0.1, 0.8]]

    theta = np.pi / n_frames
    decimals = 12
    test_name = "vr_orientation"

    for lens_type in ['plane-parallel', 'perspective']:
        frame = 0

        cam = sc.add_camera(ds, lens_type=lens_type)
        cam.resolution = (1000, 1000)
        cam.position = ds.arr(np.array([-4., 0., 0.]), 'code_length')
        cam.switch_orientation(normal_vector=[1., 0., 0.],
                               north_vector=[0., 0., 1.])
        cam.set_width(ds.domain_width * 2.)
        desc = '%s_%04d' % (lens_type, frame)
        test1 = VRImageComparisonTest(sc, ds, desc, decimals)
        test1.answer_name = test_name
        yield test1

        for i in range(n_frames):
            frame += 1
            center = ds.arr([0, 0, 0], 'code_length')
            cam.yaw(theta, rot_center=center)
            desc = 'yaw_%s_%04d' % (lens_type, frame)
            test2 = VRImageComparisonTest(sc, ds, desc, decimals)
            test2.answer_name = test_name
            yield test2

        for i in range(n_frames):
            frame += 1
            theta = np.pi / n_frames
            center = ds.arr([0, 0, 0], 'code_length')
            cam.pitch(theta, rot_center=center)
            desc = 'pitch_%s_%04d' % (lens_type, frame)
            test3 = VRImageComparisonTest(sc, ds, desc, decimals)
            test3.answer_name = test_name
            yield test3

        for i in range(n_frames):
            frame += 1
            theta = np.pi / n_frames
            center = ds.arr([0, 0, 0], 'code_length')
            cam.roll(theta, rot_center=center)
            desc = 'roll_%s_%04d' % (lens_type, frame)
            test4 = VRImageComparisonTest(sc, ds, desc, decimals)
            test4.answer_name = test_name
            yield test4

    center = [0.5, 0.5, 0.5]
    width = [1.0, 1.0, 1.0]

    for i, orientation in enumerate(orientations):
        image = off_axis_projection(ds,
                                    center,
                                    orientation,
                                    width,
                                    512,
                                    "density",
                                    no_ghost=False)

        def offaxis_image_func(filename_prefix):
            return image.write_image(filename_prefix)

        test5 = GenericImageTest(ds, offaxis_image_func, decimals)
        test5.prefix = "oap_orientation_{}".format(i)
        test5.answer_name = test_name
        yield test5
Exemple #18
0
ds = yt.load(args.infile)
core = ds.sphere(ds.domain_center, (args.rup, 'cm'))

# Load urca-specific fields
ushell_fields = UrcaShellFields()
ushell_fields.setup(ds)

# Get the field from the dataset
field, field_short_name = DatasetHelpers.get_field(ds, args.field)
assert (field)

# Create Scene
sc = Scene()

# Create Sources
so = VolumeSource(core, field)

bounds = np.array([args.minimum, args.maximum])
log_min = np.log10(args.minimum)
log_max = np.log10(args.maximum)
sigma = args.sigma

nlayers = args.num_layers
if args.alpha_ones:
    alphavec = np.ones(nlayers)
else:
    alphavec = np.logspace(-3, 0, num=nlayers, endpoint=True)

tfh = TransferFunctionHelper(ds)
tfh.set_field(field)
print(field)
import yt
from yt.visualization.volume_rendering.api import Scene, VolumeSource

filePath = "Sedov_3d/sedov_hdf5_chk_0003"
ds = yt.load(filePath)
ds.periodicity = (True, True, True)

sc = Scene()

# set up camera
cam = sc.add_camera(ds, lens_type='perspective')
cam.resolution = [400, 400]

cam.position = ds.arr([1, 1, 1], 'cm')
cam.switch_orientation()

# add rendering of density field
dens = VolumeSource(ds, field='dens')
dens.use_ghost_zones = True
sc.add_source(dens)
sc.save('density.png', sigma_clip=6)

# add rendering of x-velocity field
vel = VolumeSource(ds, field='velx')
vel.use_ghost_zones = True
sc.add_source(vel)
sc.save('density_any_velocity.png', sigma_clip=6)
parser.add_argument('-dd', '--drawdomain', action='store_true', help='If supplied, draw the boundaries of the domain.')
parser.add_argument('-dg', '--drawgrids', action='store_true', help='If supplied, draw the grids.')
parser.add_argument('-da', '--drawaxes', action='store_true', help='If supplied, draw an axes triad.')
parser.add_argument('-alpha_ones', '--alpha_ones', action='store_true', help='If supplied, set the transfer function values to ones.')
parser.add_argument('-res', '--resolution', type=int, default=2048, help='Resolution for output plot.')
args = parser.parse_args()

# Open Dataset
ds = yt.load(args.infile)
core = ds.sphere(ds.domain_center, (args.rup, 'cm'))

# Create Scene
sc = Scene()

# Create Sources
so_circum_vel = VolumeSource(core, ('boxlib', 'circum_velocity'))

mag_vel_bounds = np.array([1.0e1, 1.0e6])
mag_vel_sigma  = 0.08

nlayers = 6
if args.alpha_ones:
    alphavec = np.ones(nlayers)
else:
    alphavec = np.logspace(-5,0,nlayers)

tfh = TransferFunctionHelper(ds)
tfh.set_field(('boxlib', 'circum_velocity'))
tfh.set_log(True)
tfh.grey_opacity = False
tfh.set_bounds(mag_vel_bounds)
Exemple #21
0
def doit(plotfile):

    ds = yt.load(plotfile)
    ds.periodicity = (True, True, True)

    field = ('boxlib', 'radial_velocity')
    ds._get_field_info(field).take_log = False
        
    sc = Scene()


    # add a volume: select a sphere
    center = (0, 0, 0)
    R = (5.e8, 'cm')

    dd = ds.sphere(center, R)

    vol = VolumeSource(dd, field=field)
    vol.use_ghost_zones = True

    sc.add_source(vol)


    # transfer function
    vals = [-5.e6, -2.5e6, -1.25e6, 1.25e6, 2.5e6, 5.e6]
    sigma = 3.e5

    tf =  yt.ColorTransferFunction((min(vals), max(vals)))

    tf.clear()
    cm = "coolwarm"
    for v in vals:
        tf.sample_colormap(v, sigma**2, colormap=cm) #, alpha=0.2)

    sc.get_source(0).transfer_function = tf

    cam = sc.add_camera(ds, lens_type="perspective")        
    cam.resolution = (1280, 720)
    cam.position = 1.5*ds.arr(np.array([5.e8, 5.e8, 5.e8]), 'cm')
    
    # look toward the center -- we are dealing with an octant
    center = ds.domain_left_edge
    normal = (center - cam.position)
    normal /= np.sqrt(normal.dot(normal))

    cam.switch_orientation(normal_vector=normal,
                           north_vector=[0., 0., 1.])
    cam.set_width(ds.domain_width)

    #sc.annotate_axes()
    #sc.annotate_domain(ds)

    sc.render()
    sc.save("subchandra_test.png", sigma_clip=6.0)
    sc.save_annotated("subchandra_test_annotated.png", 
                      text_annotate=[[(0.05, 0.05), 
                                      "t = {}".format(ds.current_time.d),
                                      dict(horizontalalignment="left")],
                                     [(0.5,0.95), 
                                      "Maestro simulation of He convection on a white dwarf",
                                      dict(color="y", fontsize="24",
                                           horizontalalignment="center")]])
Exemple #22
0
def doit(plotfile):

    ds = yt.load(plotfile)
    ds.periodicity = (True, True, True)

    field = ('gas', 'velocity_z')
    ds._get_field_info(field).take_log = False

    sc = Scene()

    # add a volume: select a sphere
    #center = (0, 0, 0)
    #R = (5.e8, 'cm')

    #dd = ds.sphere(center, R)

    vol = VolumeSource(ds, field=field)
    vol.use_ghost_zones = True

    sc.add_source(vol)

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

    tf = yt.ColorTransferFunction((min(vals), max(vals)))

    tf.clear()
    cm = "coolwarm"
    for v in vals:
        tf.sample_colormap(v, sigma**2, colormap=cm)  #, alpha=0.2)

    sc.get_source(0).transfer_function = tf

    cam = sc.add_camera(ds, lens_type="perspective")
    cam.resolution = (1920, 1080)

    center = 0.5 * (ds.domain_left_edge + ds.domain_right_edge)

    cam.position = [
        2.5 * ds.domain_right_edge[0], 2.5 * ds.domain_right_edge[1],
        center[2] + 0.25 * ds.domain_right_edge[2]
    ]

    # look toward the center -- we are dealing with an octant
    normal = (center - cam.position)
    normal /= np.sqrt(normal.dot(normal))

    cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
    cam.set_width(ds.domain_width)

    sc.camera = cam
    #sc.annotate_axes(alpha=0.05)
    #sc.annotate_domain(ds, color=np.array([0.05, 0.05, 0.05, 0.05]))
    #sc.annotate_grids(ds, alpha=0.05)

    sc.render()
    sc.save("{}_radvel".format(plotfile), sigma_clip=4.0)
    sc.save_annotated(
        "{}_radvel_annotated.png".format(plotfile),
        sigma_clip=4.0,
        text_annotate=[[(0.05, 0.05), "t = {}".format(ds.current_time.d),
                        dict(horizontalalignment="left")],
                       [(0.5, 0.95),
                        "Maestro simulation of convection in a mixed H/He XRB",
                        dict(color="y",
                             fontsize="24",
                             horizontalalignment="center")]])
Exemple #23
0
def vol_render_density(outfile, ds):
    """Volume render the density given a yt dataset."""

    import numpy as np
    import yt
    import matplotlib
    matplotlib.use('agg')
    from yt.visualization.volume_rendering.api import Scene, VolumeSource
    import matplotlib.pyplot as plt

    ds.periodicity = (True, True, True)

    field = ('boxlib', 'density')
    ds._get_field_info(field).take_log = True

    sc = Scene()

    # Add a volume: select a sphere

    vol = VolumeSource(ds, field=field)
    vol.use_ghost_zones = True

    sc.add_source(vol)

    # Transfer function

    vals = [-1, 0, 1, 2, 3, 4, 5, 6, 7]
    sigma = 0.1

    tf = yt.ColorTransferFunction((min(vals), max(vals)))

    tf.clear()

    cm = "spectral"

    for v in vals:
        if v < 3:
            alpha = 0.1
        else:
            alpha = 0.5
        tf.sample_colormap(v, sigma**2, colormap=cm, alpha=alpha)

    sc.get_source(0).transfer_function = tf

    cam = sc.add_camera(ds, lens_type="perspective")
    cam.resolution = (1920, 1080)

    center = 0.5 * (ds.domain_left_edge + ds.domain_right_edge)
    width = ds.domain_width

    # Set the camera so that we're looking down on the xy plane from a 45
    # degree angle. We reverse the y-coordinate since yt seems to use the
    # opposite orientation convention to us (where the primary should be
    # on the left along the x-axis). We'll scale the camera position based
    # on a zoom factor proportional to the width of the domain.

    zoom_factor = 0.75

    cam_position = np.array([
        center[0], center[1] - zoom_factor * width[1],
        center[2] + zoom_factor * width[2]
    ])

    cam.position = zoom_factor * ds.arr(cam_position, 'cm')

    # Set the normal vector so that we look toward the center.

    normal = (center - cam.position)
    normal /= np.sqrt(normal.dot(normal))

    cam.switch_orientation(normal_vector=normal, north_vector=[0.0, 0.0, 1.0])
    cam.set_width(width)

    # Render the image.

    sc.render()

    # Save the image without annotation.

    sc.save(outfile, sigma_clip=6.0)

    # Save the image with a colorbar.

    sc.save_annotated(outfile.replace(".png", "_colorbar.png"), sigma_clip=6.0)

    # Save the image with a colorbar and the current time.

    sc.save_annotated(outfile.replace(".png", "_colorbar_time.png"),
                      sigma_clip=6.0,
                      text_annotate=[[
                          (0.05, 0.925),
                          "t = {:.2f} s".format(float(ds.current_time.d)),
                          dict(horizontalalignment="left", fontsize="20")
                      ]])
Exemple #24
0
def doit(plotfile, fname):

    ds = yt.load(plotfile)

    cm = "gist_rainbow"

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

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

        fmt = None

        cm = "coolwarm"

    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"

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

    # hack periodicity
    ds.periodicity = (True, True, True)

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

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

    print mi, ma

    # setup the scene and camera
    sc = Scene()
    cam = Camera(ds, lens_type="perspective")

    # Set up the camera parameters: center, looking direction, width, resolution
    center = (ds.domain_right_edge + ds.domain_left_edge) / 2.0
    xmax, ymax, zmax = ds.domain_right_edge

    # this shows something face on
    c = np.array([-8.0 * xmax, center[1], center[2]])

    # the normal vector should be pointing back through the center
    L = center.d - c
    L = L / np.sqrt((L**2).sum())

    north_vector = [0.0, 0.0, 1.0]

    cam.position = ds.arr(c)
    cam.switch_orientation(normal_vector=L, north_vector=north_vector)

    cam.set_width(ds.domain_width * 4)

    cam.resolution = (720, 720)

    # create the volume source
    vol = VolumeSource(ds, field=field)

    # Instantiate the ColorTransferfunction.
    tf = vol.transfer_function
    tf = ColorTransferFunction((mi, ma))
    #tf.grey_opacity=True

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

    sc.camera = cam
    sc.add_source(vol)
    sc.render("test_perspective.png", clip_ratio=6.0)
Exemple #25
0
def doit(plotfile):

    ds = yt.load(plotfile)
    ds.periodicity = (True, True, True)

    field = ('boxlib', 'radial_velocity')
    ds._get_field_info(field).take_log = False
        
    sc = Scene()


    # add a volume: select a sphere
    #center = (0, 0, 0)
    #R = (5.e8, 'cm')

    #dd = ds.sphere(center, R)

    vol = VolumeSource(ds, field=field)
    vol.use_ghost_zones = True

    sc.add_source(vol)


    # transfer function
    vals = [-5.e6, -2.5e6, -1.25e6, 1.25e6, 2.5e6, 5.e6]
    sigma = 3.e5

    tf =  yt.ColorTransferFunction((min(vals), max(vals)))

    tf.clear()
    cm = "coolwarm"
    for v in vals:
        tf.sample_colormap(v, sigma**2, colormap=cm) #, alpha=0.2)

    sc.get_source(0).transfer_function = tf

    cam = sc.add_camera(ds, lens_type="perspective")        
    cam.resolution = (1080, 1080)
    cam.position = 1.0*ds.domain_right_edge
    
    # look toward the center -- we set this depending on whether the plotfile
    # indicates it was an octant
    try: octant = ds.parameters["octant"]
    except: octant = True

    if octant:
        center = ds.domain_left_edge
    else:
        center = 0.5*(ds.domain_left_edge + ds.domain_right_edge)

    # unit vector connecting center and camera
    normal = (center - cam.position)
    normal /= np.sqrt(normal.dot(normal))

    cam.switch_orientation(normal_vector=normal,
                           north_vector=[0., 0., 1.])
    cam.set_width(ds.domain_width)

    #sc.annotate_axes(alpha=0.05)
    #sc.annotate_domain(ds, color=np.array([0.05, 0.05, 0.05, 0.05]))
    #sc.annotate_grids(ds, alpha=0.05)

    sc.render()
    sc.save("{}_radvel".format(plotfile), sigma_clip=6.0)
    sc.save_annotated("{}_radvel_annotated.png".format(plotfile), 
                      text_annotate=[[(0.05, 0.05), 
                                      "t = {}".format(ds.current_time.d),
                                      dict(horizontalalignment="left")],
                                     [(0.5,0.95), 
                                      "Maestro simulation of He convection on a white dwarf",
                                      dict(color="y", fontsize="24",
                                           horizontalalignment="center")]])
Exemple #26
0
parser.add_argument('-res',
                    '--resolution',
                    type=int,
                    default=2048,
                    help='Resolution for output plot.')
args = parser.parse_args()

# Open Dataset
ds = yt.load(args.infile)
core = ds.sphere(ds.domain_center, (args.rup, 'cm'))

# Create Scene
sc = Scene()

# Create Sources
so_circum_vel = VolumeSource(core, ('boxlib', 'circum_velocity'))

mag_vel_bounds = np.array([1.0e1, 1.0e6])
mag_vel_sigma = 0.08

nlayers = 6
if args.alpha_ones:
    alphavec = np.ones(nlayers)
else:
    alphavec = np.logspace(-5, 0, nlayers)

tfh = TransferFunctionHelper(ds)
tfh.set_field(('boxlib', 'circum_velocity'))
tfh.set_log(True)
tfh.grey_opacity = False
tfh.set_bounds(mag_vel_bounds)
def doit(plotfile):

    ds = yt.load(plotfile)
    ds.periodicity = (True, True, True)

    field = ('boxlib', 'density')
    ds._get_field_info(field).take_log = True

    sc = Scene()

    # add a volume: select a sphere
    vol = VolumeSource(ds, field=field)
    vol.use_ghost_zones = True

    sc.add_source(vol)

    # transfer function
    vals = [-1, 0, 1, 2, 3, 4, 5, 6, 7]
    #vals = [0.1, 1.0, 10, 100., 1.e4, 1.e5, 1.e6, 1.e7]
    sigma = 0.1

    tf = yt.ColorTransferFunction((min(vals), max(vals)))

    tf.clear()
    cm = "coolwarm"
    cm = "spectral"
    for v in vals:
        if v < 3:
            alpha = 0.1
        else:
            alpha = 0.5
        tf.sample_colormap(v, sigma**2, colormap=cm, alpha=alpha)

    sc.get_source(0).transfer_function = tf

    # for spherical, youtube recommends an "equirectangular" aspect ratio
    # (2:1), suggested resolution of 8192 x 4096
    # see: https://support.google.com/youtube/answer/6178631?hl=en
    #
    # also see: http://yt-project.org/docs/dev/cookbook/complex_plots.html#various-lens-types-for-volume-rendering
    # the 2:1 is 2*pi in phi and pi in theta
    cam = sc.add_camera(ds, lens_type="spherical")
    #cam.resolution = (8192, 4096)
    cam.resolution = (4096, 2048)

    # look toward the +x initially
    cam.focus = ds.arr(np.array([ds.domain_left_edge[0], 0.0, 0.0]), 'cm')

    # center of the domain -- eventually we might want to do the
    # center of mass
    cam.position = ds.arr(np.array([0.0, 0.0, 0.0]), 'cm')

    # define up
    cam.north_vector = np.array([0., 0., 1.])

    normal = (cam.focus - cam.position)
    normal /= np.sqrt(normal.dot(normal))

    cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])

    # there is no such thing as a camera width -- the entire volume is rendered
    #cam.set_width(ds.domain_width)

    #sc.annotate_axes()
    #sc.annotate_domain(ds)

    pid = plotfile.split("plt")[1]
    sc.render()
    sc.save("wdmerger_{}_spherical.png".format(pid), sigma_clip=6.0)
Exemple #28
0
# Workaround
@derived_field(name='abs_ye_asymmetry', units='')
def _abs_ye_asymmetry(field, data):
    return np.absolute(data['electron_fraction_asymmetry'])


# Open Dataset
ds = yt.load(args.infile)
core = ds.sphere(ds.domain_center, (args.rup, 'cm'))

# Create Scene
sc = Scene()

# Create Sources
so = VolumeSource(core, 'abs_ye_asymmetry')

bounds = np.array([args.ye_asym_minimum, args.ye_asym_maximum])
log_min = np.log10(args.ye_asym_minimum)
log_max = np.log10(args.ye_asym_maximum)
sigma = args.ye_sigma

nlayers = args.num_layers
if args.alpha_ones:
    alphavec = np.ones(nlayers)
else:
    alphavec = np.logspace(-3, 0, num=nlayers, endpoint=True)

tfh = TransferFunctionHelper(ds)
tfh.set_field('abs_ye_asymmetry')
tfh.set_log(False)
Exemple #29
0
args = parser.parse_args()

# Workaround
@derived_field(name='abs_ye_asymmetry', units='')
def _abs_ye_asymmetry(field, data):
    return np.absolute(data['electron_fraction_asymmetry'])

# Open Dataset
ds = yt.load(args.infile)
core = ds.sphere(ds.domain_center, (args.rup, 'cm'))

# Create Scene
sc = Scene()

# Create Sources
so = VolumeSource(core, 'abs_ye_asymmetry')

bounds = np.array([args.ye_asym_minimum, args.ye_asym_maximum])
log_min = np.log10(args.ye_asym_minimum)
log_max = np.log10(args.ye_asym_maximum)
sigma  = args.ye_sigma

nlayers = args.num_layers
if args.alpha_ones:
    alphavec = np.ones(nlayers)
else:
    alphavec = np.logspace(-3, 0, num=nlayers, endpoint=True)

tfh = TransferFunctionHelper(ds)
tfh.set_field('abs_ye_asymmetry')
tfh.set_log(False)
Exemple #30
0
@derived_field(name='pos_radial_velocity', units='cm/s')
def _pos_radial_velocity(field, data):
    return np.maximum(data[('boxlib','radial_velocity')], 1.0e-99)
@derived_field(name='neg_radial_velocity', units='cm/s')
def _neg_radial_velocity(field, data):
    return np.maximum(-data[('boxlib','radial_velocity')], 1.0e-99)

# Open Dataset
ds = yt.load(args.infile)
core = ds.sphere(ds.domain_center, (0.25e8, 'cm'))

# Create Scene
sc = Scene()

# Create Sources
so_enuc = VolumeSource(core, ('boxlib','enucdot'))
so_pos_vrad = VolumeSource(core, 'pos_radial_velocity')
so_neg_vrad = VolumeSource(core, 'neg_radial_velocity')

# Assign Transfer Functions to Sources
tfh_en = TransferFunctionHelper(ds)
tfh_en.set_field(('boxlib','enucdot'))
tfh_en.set_log(True)
tfh_en.set_bounds()
tfh_en.build_transfer_function()
tfh_en.tf.add_layers(10, colormap='black_green', w=0.01)
tfh_en.grey_opacity = False
tfh_en.plot('{}_tfun_enuc.png'.format(args.infile), profile_field=('boxlib','enucdot'))
so_enuc.transfer_function = tfh_en.tf

# tfh = TransferFunctionHelper(ds)
@derived_field(name='pos_enucdot', units='erg/(g*s)')
def _pos_radial_velocity(field, data):
    return np.maximum(data[('boxlib','enucdot')], yt.YTQuantity(1.0e-99, 'erg/(g*s)'))
@derived_field(name='neg_enucdot', units='erg/(g*s)')
def _neg_radial_velocity(field, data):
    return np.maximum(-data[('boxlib','enucdot')], yt.YTQuantity(1.0e-99, 'erg/(g*s)'))

# Open Dataset
ds = yt.load(args.infile)
core = ds.sphere(ds.domain_center, (args.rup, 'cm'))

# Create Scene
sc = Scene()

# Create Sources
so_pos_enuc = VolumeSource(core, 'pos_enucdot')
so_neg_enuc = VolumeSource(core, 'neg_enucdot')

# Get maximum values for alpha settings
pos_maxv = np.ceil(np.log10(core.max('pos_enucdot')))
neg_maxv = np.ceil(np.log10(core.max('neg_enucdot')))
rat_neg_pos = 10.0**(neg_maxv-pos_maxv)

# Assign Transfer Functions to Sources
mag_enuc_sigma  = 0.1

tfh = TransferFunctionHelper(ds)
tfh.set_field('pos_enucdot')
mag_enuc_bounds = np.array([10.0**-(pos_maxv-3), 10.0**pos_maxv])
tfh.set_log(True)
tfh.grey_opacity = False
Exemple #32
0
from yt.visualization.volume_rendering.api import Scene, VolumeSource
import numpy as np

field = ("gas", "density")

# normal_vector points from camera to the center of tbe final projection.
# Now we look at the positive x direction.
normal_vector = [1., 0., 0.]
# north_vector defines the "top" direction of the projection, which is
# positive z direction here.
north_vector = [0., 0., 1.]

# Follow the simple_volume_rendering cookbook for the first part of this.
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
sc = Scene()
vol = VolumeSource(ds, field=field)
tf = vol.transfer_function
tf.grey_opacity = True

# Plane-parallel lens
cam = sc.add_camera(ds, lens_type='plane-parallel')
# Set the resolution of tbe final projection.
cam.resolution = [250, 250]
# Set the location of the camera to be (x=0.2, y=0.5, z=0.5)
# For plane-parallel lens, the location info along the normal_vector (here
# is x=0.2) is ignored.
cam.position = ds.arr(np.array([0.2, 0.5, 0.5]), 'code_length')
# Set the orientation of the camera.
cam.switch_orientation(normal_vector=normal_vector, north_vector=north_vector)
# Set the width of the camera, where width[0] and width[1] specify the length and
# height of final projection, while width[2] in plane-parallel lens is not used.
Exemple #33
0
@derived_field(name='neg_radial_velocity', units='cm/s')
def _neg_radial_velocity(field, data):
    return np.maximum(-data[('boxlib', 'radial_velocity')],
                      yt.YTQuantity(1.0e-99, 'cm/s'))


# Open Dataset
ds = yt.load(args.infile)
core = ds.sphere(ds.domain_center, (args.rup, 'cm'))

# Create Scene
sc = Scene()

# Create Sources
#so_enuc = VolumeSource(core, ('boxlib','enucdot'))
so_pos_vrad = VolumeSource(core, 'pos_radial_velocity')
so_neg_vrad = VolumeSource(core, 'neg_radial_velocity')

# Assign Transfer Functions to Sources
# tfh_en = TransferFunctionHelper(ds)
# tfh_en.set_field(('boxlib','enucdot'))
# tfh_en.set_log(True)
# tfh_en.set_bounds()
# tfh_en.build_transfer_function()
# tfh_en.tf.add_layers(10, colormap='black_green', w=0.01)
# tfh_en.grey_opacity = False
# tfh_en.plot('{}_tfun_enuc.png'.format(args.infile), profile_field=('boxlib','enucdot'))
# so_enuc.transfer_function = tfh_en.tf

mag_vel_bounds = np.array([args.velocity_minimum, args.velocity_maximum])
mag_vel_sigma = args.velocity_sigma
Exemple #34
0
def doit(plotfile):

    ds = yt.load(plotfile)
    ds.periodicity = (True, True, True)

    field = ('gas', 'velocity_z')
    ds._get_field_info(field).take_log = False
        
    sc = Scene()


    # add a volume: select a sphere
    #center = (0, 0, 0)
    #R = (5.e8, 'cm')

    #dd = ds.sphere(center, R)

    vol = VolumeSource(ds, field=field)
    vol.use_ghost_zones = True

    sc.add_source(vol)


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

    tf =  yt.ColorTransferFunction((min(vals), max(vals)))

    tf.clear()
    cm = "coolwarm"
    for v in vals:
        tf.sample_colormap(v, sigma**2, colormap=cm) #, alpha=0.2)

    sc.get_source(0).transfer_function = tf

    cam = sc.add_camera(ds, lens_type="perspective")        
    cam.resolution = (1920, 1080)

    center = 0.5*(ds.domain_left_edge + ds.domain_right_edge)

    cam.position = [2.5*ds.domain_right_edge[0],
                    2.5*ds.domain_right_edge[1],
                    center[2]+0.25*ds.domain_right_edge[2]]
    
    # look toward the center -- we are dealing with an octant
    normal = (center - cam.position)
    normal /= np.sqrt(normal.dot(normal))

    cam.switch_orientation(normal_vector=normal,
                           north_vector=[0., 0., 1.])
    cam.set_width(ds.domain_width)

    sc.camera = cam
    #sc.annotate_axes(alpha=0.05)
    #sc.annotate_domain(ds, color=np.array([0.05, 0.05, 0.05, 0.05]))
    #sc.annotate_grids(ds, alpha=0.05)

    sc.render()
    sc.save("{}_radvel".format(plotfile), sigma_clip=4.0)
    sc.save_annotated("{}_radvel_annotated.png".format(plotfile),
                      sigma_clip=4.0, 
                      text_annotate=[[(0.05, 0.05), 
                                      "t = {}".format(ds.current_time.d),
                                      dict(horizontalalignment="left")],
                                     [(0.5,0.95), 
                                      "Maestro simulation of convection in a mixed H/He XRB",
                                      dict(color="y", fontsize="24",
                                           horizontalalignment="center")]])
Exemple #35
0
import yt
from yt.visualization.volume_rendering.api import Scene, VolumeSource

filePath = "Sedov_3d/sedov_hdf5_chk_0003"
ds = yt.load(filePath)
ds.periodicity = (True, True, True)

sc = Scene()

# set up camera
cam = sc.add_camera(ds, lens_type="perspective")
cam.resolution = [400, 400]

cam.position = ds.arr([1, 1, 1], "cm")
cam.switch_orientation()

# add rendering of density field
dens = VolumeSource(ds, field="dens")
dens.use_ghost_zones = True
sc.add_source(dens)
sc.save("density.png", sigma_clip=6)

# add rendering of x-velocity field
vel = VolumeSource(ds, field="velx")
vel.use_ghost_zones = True
sc.add_source(vel)
sc.save("density_any_velocity.png", sigma_clip=6)
Exemple #36
0
# initialize the yt-specific data structure (ds)
# for more info read:
# http://yt-project.org/docs/dev/reference/api/generated/yt.frontends.stream.data_structures.load_uniform_grid.html?highlight=load_uniform_grid

# please note here the length unit should be different for three axis
# i used the unit for z-axis here for all three
# since yt's unit system only support one uniform unit for the 3-D space
ds = yt.load_uniform_grid(data,
                          dom.shape,
                          length_unit=0.20800511,
                          bbox=bbox,
                          nprocs=64)

# initialize the yt scene
sc = Scene()
vol = VolumeSource(ds, field=field)

# camera position
#hc = ds.arr([hx, hy, hz], 'cm') # hydrogen location
hc = ds.arr([19.13987520, 19.13987520, 82.13300000], 'cm')  # hydrogen location

# Find the bounds in log space of for your field
dd = ds.all_data()
mi, ma = dd.quantities.extrema(field)
if use_log:
    mi, ma = np.log10(mi), np.log10(ma)

# instantiating the ColorTransferfunction
tf = yt.ColorTransferFunction((mi, ma))
'''
tfh = TransferFunctionHelper(ds)
Exemple #37
0
def doit(plotfile):

    ds = yt.load(plotfile)
    ds.periodicity = (True, True, True)

    field = ('boxlib', 'density')
    ds._get_field_info(field).take_log = True

    sc = Scene()

    # add a volume: select a sphere
    vol = VolumeSource(ds, field=field)
    vol.use_ghost_zones = True

    sc.add_source(vol)

    # transfer function
    vals = [-1, 0, 1, 2, 3, 4, 5, 6, 7]
    #vals = [0.1, 1.0, 10, 100., 1.e4, 1.e5, 1.e6, 1.e7]
    sigma = 0.1

    tf = yt.ColorTransferFunction((min(vals), max(vals)))

    tf.clear()
    cm = "coolwarm"
    cm = "spectral"
    for v in vals:
        if v < 3:
            alpha = 0.1
        else:
            alpha = 0.5
        tf.sample_colormap(v, sigma**2, colormap=cm, alpha=alpha)

    sc.get_source(0).transfer_function = tf

    cam = sc.add_camera(ds, lens_type="perspective")
    cam.resolution = (1920, 1080)
    cam.position = 1.5 * ds.arr(np.array([0.0, 5.e9, 5.e9]), 'cm')

    # look toward the center -- we are dealing with an octant
    center = 0.5 * (ds.domain_left_edge + ds.domain_right_edge)
    normal = (center - cam.position)
    normal /= np.sqrt(normal.dot(normal))

    cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
    cam.set_width(ds.domain_width)

    #sc.annotate_axes()
    #sc.annotate_domain(ds)

    pid = plotfile.split("plt")[1]
    sc.render()
    sc.save("wdmerger_{}_new.png".format(pid), sigma_clip=6.0)
    sc.save_annotated(
        "wdmerger_annotated_{}_new.png".format(pid),
        text_annotate=
        [[(0.05, 0.05), "t = {:.3f} s".format(float(ds.current_time.d)),
          dict(horizontalalignment="left")],
         [(0.5, 0.95),
          "Castro simulation of merging white dwarfs (0.6 $M_\odot$ + 0.9 $M_\odot$)",
          dict(color="y", fontsize="22", horizontalalignment="center")],
         [(0.95, 0.05), "M. Katz et al.",
          dict(color="w", fontsize="16", horizontalalignment="right")]])