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")]])
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)
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)
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 = create_volume_source(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)
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)
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)
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 = create_volume_source(dd, field=self.field) tf = vol.transfer_function tf.grey_opacity = True sc.add_source(vol) sc.save(f"test_plane_{self.field[1]}.png", sigma_clip=6.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 = [256, 256] cam.position = self.ds.arr(np.array([0.6, 0.5, 0.5]), "code_length") vol = create_volume_source(self.ds, field=self.field) tf = vol.transfer_function tf.grey_opacity = True sc.add_source(vol) sc.save(f"test_stereospherical_{self.field[1]}.png", sigma_clip=6.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)
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.render() sc.save('test_plane_%s.png' % self.field[1], sigma_clip=6.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 = create_volume_source(dd, field=self.field) tf = vol.transfer_function tf.grey_opacity = True sc.add_source(vol) sc.save(f"test_fisheye_{self.field[1]}.png", sigma_clip=6.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.render() sc.save('test_fisheye_%s.png' % self.field[1], sigma_clip=6.0)
#sc.add_source(so_enuc) sc.add_source(so_pos_vrad) sc.add_source(so_neg_vrad) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = args.resolution sc.camera.north_vector = yt.YTArray(args.camera_north, 'cm') sc.camera.position = ds.domain_center + yt.YTArray(args.camera_position, 'cm') * args.rup sc.camera.zoom(args.zoom) # Annotate domain - draw boundaries if args.drawdomain: sc.annotate_domain(ds, color=[1, 1, 1, 0.01]) # Annotate by drawing grids if args.drawgrids: sc.annotate_grids(ds, alpha=0.01) # Annotate by drawing axes triad if args.drawaxes: sc.annotate_axes(alpha=0.01) # Render sc.render() sc.save('{}_rendering_rad-vel.png'.format(args.infile), sigma_clip=3)
# Add sources to scene sc.add_source(so) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = args.resolution sc.camera.north_vector = yt.YTArray(args.camera_north, 'cm') sc.camera.position = ds.domain_center + yt.YTArray(args.camera_position, 'cm') * args.rup sc.camera.zoom(args.zoom) # Annotate domain - draw boundaries if args.drawdomain: sc.annotate_domain(ds, color=[1, 1, 1, 0.01]) # Annotate by drawing grids if args.drawgrids: sc.annotate_grids(ds, alpha=0.01) # Annotate by drawing axes triad if args.drawaxes: sc.annotate_axes(alpha=0.01) # Render sc.render() sc.save('{}_rendering_{}.png'.format(args.infile, field_short_name), sigma_clip=3)
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)
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)
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")]])
# Add sources to scene sc.add_source(so_pos_enuc) sc.add_source(so_neg_enuc) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = 2048 sc.camera.north_vector = [0, 0, 1] sc.camera.position = ds.domain_center + [1.0, 1.0, 1.0] * ds.domain_width * args.rup/5.12e8 #sc.camera.zoom(2.5*args.zoom) # Annotate domain - draw boundaries if args.drawdomain: sc.annotate_domain(ds, color=[1, 1, 1, 0.2]) # Annotate by drawing grids if args.drawgrids: sc.annotate_grids(ds, alpha=0.2) # Annotate by drawing axes triad if args.drawaxes: sc.annotate_axes(alpha=0.2) # Render sc.render() sc.save('{}_rendering_enucdot.png'.format(args.infile))
# Add sources to scene sc.add_source(so) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = args.resolution sc.camera.north_vector = yt.YTArray(args.camera_north, 'cm') sc.camera.position = ds.domain_center + yt.YTArray(args.camera_position, 'cm') * args.rup sc.camera.zoom(args.zoom) # Annotate domain - draw boundaries if args.drawdomain: sc.annotate_domain(ds, color=[1, 1, 1, 0.01]) # Annotate by drawing grids if args.drawgrids: sc.annotate_grids(ds, alpha=0.01) # Annotate by drawing axes triad if args.drawaxes: sc.annotate_axes(alpha=0.01) # Render sc.render() sc.save('{}_rendering_abs_ye_asym.png'.format(args.infile), sigma_clip=3)
# Add sources to scene #sc.add_source(so_enuc) sc.add_source(so_pos_vrad) sc.add_source(so_neg_vrad) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = 800 sc.camera.north_vector = [0, 0, 1] sc.camera.position = ds.domain_center + [1.0, 1.0, 1.0] * ds.domain_width * args.rup/5.12e8 sc.camera.zoom(2.5*args.zoom) # Annotate domain - draw boundaries if args.drawdomain: sc.annotate_domain(ds, color=[1, 1, 1, 0.01]) # Annotate by drawing grids if args.drawgrids: sc.annotate_grids(ds, alpha=0.01) # Annotate by drawing axes triad if args.drawaxes: sc.annotate_axes(alpha=0.01) # Render sc.render() sc.save('{}_rendering_rad-vel.png'.format(args.infile), sigma_clip=6)
def doit(plotfile): ds = yt.load(plotfile) ds.periodicity = (True, True, True) cm = "coolwarm" field = ('boxlib', 'density') ds._get_field_info(field).take_log = True sc = Scene() # add a volume: select a sphere vol = VolumeSource(ds, field=field) sc.add_source(vol) # transfer function vals = [-1, 0, 1, 2, 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 < 4: 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 = Camera(ds, lens_type="perspective") cam.resolution = (1280, 720) 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.camera = cam #sc.annotate_axes() #sc.annotate_domain(ds) pid = plotfile.split("plt")[1] sc.render() sc.save("wdmerger_{}.png".format(pid), sigma_clip=6.0) sc.save_annotated("wdmerger_annotated_{}.png".format(pid), text_annotate=[[(0.05, 0.05), "t = {:.3f}".format(float(ds.current_time.d)), dict(horizontalalignment="left")], [(0.5,0.95), "Castro simulation of merging white dwarfs", dict(color="y", fontsize="24", horizontalalignment="center")]])
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")]])
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)
exit() # Add sources to scene sc.add_source(so) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = args.resolution sc.camera.north_vector = yt.YTArray(args.camera_north, 'cm') sc.camera.position = ds.domain_center + yt.YTArray(args.camera_position, 'cm') * args.rup sc.camera.zoom(args.zoom) # Annotate domain - draw boundaries if args.drawdomain: sc.annotate_domain(ds, color=[1, 1, 1, 0.01]) # Annotate by drawing grids if args.drawgrids: sc.annotate_grids(ds, alpha=0.01) # Annotate by drawing axes triad if args.drawaxes: sc.annotate_axes(alpha=0.01) # Render sc.render() sc.save('{}_rendering_{}.png'.format(args.infile, field_short_name), sigma_clip=3)
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")]])
# so_neg_vrad.set_field(field) # so_neg_vrad.bounds = bounds # so_neg_vrad.set_log(True) # so_neg_vrad.tfh.grey_opacity = False # Add sources to scene sc.add_source(so_enuc) sc.add_source(so_pos_vrad) sc.add_source(so_neg_vrad) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = 2048 sc.camera.north_vector = [0, 0, 1] sc.camera.position = ds.domain_center + [1.0, 1.0, 1.0] * ds.domain_width * 1.0/5.12 sc.camera.zoom(2.5) # Annotate domain - draw boundaries #sc.annotate_domain(ds, color=[1, 1, 1, 0.01]) # Annotate by drawing grids #sc.annotate_grids(ds, alpha=0.01) # Annotate by drawing axes triad #sc.annotate_axes(alpha=0.01) # Render sc.render() sc.save('{}_rendering.png'.format(args.infile), sigma_clip=6)
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") ]])
# Add sources to scene sc.add_source(so_pos_enuc) sc.add_source(so_neg_enuc) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = args.resolution sc.camera.north_vector = yt.YTArray(args.camera_north, 'cm') sc.camera.position = ds.domain_center + yt.YTArray(args.camera_position, 'cm') * args.rup sc.camera.zoom(args.zoom) # Annotate domain - draw boundaries if args.drawdomain: sc.annotate_domain(ds, color=[1, 1, 1, 0.01]) # Annotate by drawing grids if args.drawgrids: sc.annotate_grids(ds, alpha=0.01) # Annotate by drawing axes triad if args.drawaxes: sc.annotate_axes(alpha=0.01) # Render sc.render() sc.save('{}_rendering_enucdot.png'.format(args.infile), sigma_clip=3)
exit() # Add sources to scene sc.add_source(so) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = args.resolution sc.camera.north_vector = yt.YTArray(args.camera_north, 'cm') sc.camera.position = ds.domain_center + yt.YTArray(args.camera_position, 'cm') * args.rup sc.camera.zoom(args.zoom) # Annotate domain - draw boundaries if args.drawdomain: sc.annotate_domain(ds, color=[1, 1, 1, 0.01]) # Annotate by drawing grids if args.drawgrids: sc.annotate_grids(ds, alpha=0.01) # Annotate by drawing axes triad if args.drawaxes: sc.annotate_axes(alpha=0.01) # Render sc.render() sc.save('{}_rendering_abs_ye_asym.png'.format(args.infile), sigma_clip=3)
# 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. cam.set_width(ds.domain_width * 0.5) sc.add_source(vol) sc.render() sc.save('lens_plane-parallel.png', sigma_clip=6.0) # Perspective lens cam = sc.add_camera(ds, lens_type='perspective') cam.resolution = [250, 250] # Standing at (x=0.2, y=0.5, z=0.5), we look at the area of x>0.2 (with some open angle # specified by camera width) along the positive x direction. cam.position = ds.arr([0.2, 0.5, 0.5], 'code_length') 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 the final projection, while width[2] specifies the distance between the # camera and the final image. cam.set_width(ds.domain_width * 0.5) sc.add_source(vol) sc.render() sc.save('lens_perspective.png', sigma_clip=6.0)
cam = sc.add_camera(ds, lens_type='spherical') cam.resolution = [4096, 2048] #cam.resolution = [2048, 1024] # cam.resolution = [1600, 1600] # cam.positon = c cam.position = hc cam.switch_orientation(normal_vector=L, north_vector=north) # cam.lens.disparity = ds.domain_width[0] * 1.e-3 sc.add_source(vol) sc.render() # arbitrary output file name # subject to change sc.save('spherical_rendering_frame' + str(sys.argv[2]) + '.png', sigma_clip=0) # the following lines are legacy from earlier development # snapshots = list(enumerate(cam.zoomin(3.0, 1, clip_ratio=0.0))) # snapshots[0][1].write_png('test_rendering_zoomed.png') #frame = 0 #for i, snapshot in enumerate(cam.zoomin(10.0, 5)): # snapshot.write_png('camera_movement_%04i.png' % frame) # frame += 1 # Now let's add some isocontours, and take a snapshot, saving the image # to a file. # im = cam.snapshot('test_rendering_frame' + str(sys.argv[2]) + '.png')
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")]])
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")]])
# Add sources to scene sc.add_source(so_circum_vel) # Add camera to scene sc.add_camera() # Set camera properties sc.camera.focus = ds.domain_center sc.camera.resolution = args.resolution sc.camera.north_vector = [0, 0, 1] sc.camera.position = ds.domain_center + [ 1.0, 1.0, 1.0 ] * ds.domain_width * args.rup / 5.12e8 sc.camera.zoom(2.5 * args.zoom) # Annotate domain - draw boundaries if args.drawdomain: sc.annotate_domain(ds, color=[1, 1, 1, 0.01]) # Annotate by drawing grids if args.drawgrids: sc.annotate_grids(ds, alpha=0.01) # Annotate by drawing axes triad if args.drawaxes: sc.annotate_axes(alpha=0.01) # Render sc.render() sc.save('{}_rendering_circum-vel.png'.format(args.infile), sigma_clip=6)
def doit(plotfile): ds = yt.load(plotfile) ds.periodicity = (True, True, True) field = ('boxlib', 'Hnuc') ds._get_field_info(field).take_log = True 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 = [14, 14.5, 15, 15.5, 16] sigma = 0.1 tf = yt.ColorTransferFunction((min(vals), max(vals))) tf.clear() cm = "viridis" for v in vals: if v < 15.5: alpha = 0.1 else: alpha = 0.75 tf.sample_colormap(v, sigma**2, alpha=alpha, colormap=cm) 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(0.5 * ds.domain_width) cam.zoom(1.5) 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("{}_Hnuc".format(plotfile), sigma_clip=4.0) sc.save_annotated( "{}_Hnuc_annotated.png".format(plotfile), text_annotate=[[(0.05, 0.05), "t = {}".format(ds.current_time.d), dict(horizontalalignment="left")], [(0.5, 0.95), "MAESTROeX simulation of ECSN convection", dict(color="y", fontsize="24", horizontalalignment="center")]])