def test_splat(): """Tests functionality of off_axis_projection and write_projection.""" # Perform I/O in safe place instead of yt main dir tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) N = 16 Np = int(1e2) image = np.zeros([N,N,4]) xs = np.random.random(Np) ys = np.random.random(Np) cbx = yt.visualization.color_maps.mcm.RdBu cs = cbx(np.random.random(Np)) add_rgba_points_to_image(image, xs, ys, cs) before_hash = image.copy() fn = 'tmp.png' yt.write_bitmap(image, fn) yield assert_equal, os.path.exists(fn), True os.remove(fn) yield assert_equal, before_hash, image os.chdir(curdir) # clean up shutil.rmtree(tmpdir)
def test_splat(): """Tests functionality of off_axis_projection and write_projection.""" # Perform I/O in safe place instead of yt main dir tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) N = 16 Np = int(1e2) image = np.zeros([N, N, 4]) xs = np.random.random(Np) ys = np.random.random(Np) cbx = yt.visualization.color_maps.mcm.RdBu cs = cbx(np.random.random(Np)) add_rgba_points_to_image(image, xs, ys, cs) before_hash = image.copy() fn = 'tmp.png' yt.write_bitmap(image, fn) yield assert_equal, os.path.exists(fn), True os.remove(fn) yield assert_equal, before_hash, image os.chdir(curdir) # clean up shutil.rmtree(tmpdir)
def test_splat(): # Perform I/O in safe place instead of yt main dir tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) prng = np.random.RandomState(0x4D3D3D3) N = 16 Np = int(1e2) image = np.zeros([N, N, 4]) xs = prng.random_sample(Np) ys = prng.random_sample(Np) cbx = yt.visualization.color_maps.mcm.RdBu cs = cbx(prng.random_sample(Np)) add_rgba_points_to_image(image, xs, ys, cs) before_hash = image.copy() fn = "tmp.png" yt.write_bitmap(image, fn) assert_equal(os.path.exists(fn), True) os.remove(fn) assert_equal(before_hash, image) os.chdir(curdir) # clean up shutil.rmtree(tmpdir)
def add_image(self, width=None, height=None): import ipywidgets width = width or self.width height = height or self.height # We will initialize it if self.scene is not None: value = yt.write_bitmap(self.scene.image[:, :, :3], None) else: value = yt.write_bitmap(np.zeros((width, height, 3)), None) self.image_widget = ipywidgets.Image(width=width, height=height, value=value) return self.image_widget
def __call__(self, scene, camera, callbacks): camera.compute_matrices() scene.set_camera(camera) scene.render() arr = scene._retrieve_framebuffer() write_bitmap(arr, "test.png")
def _snap_image(rc): image = rc.run() img = yt.write_bitmap(image, None) content = base64.b64encode(img).decode("ascii") extra.append(extras.png(content)) extra.append(extras.html("<br clear='all'/>"))
import yt import yt_idv ds = yt.load_sample("IsolatedGalaxy") dd = ds.all_data() rc = yt_idv.render_context("osmesa", width=1024, height=1024) rc.add_scene(dd, "density", no_ghost=True) image = rc.run() yt.write_bitmap(image, "step1.png") rc.scene.camera.move_forward(1.5) image = rc.run() yt.write_bitmap(image, "step2.png")
bbox = np.array([center-width/2, center+width/2]) ds = yt.load(filename, midx_filename=midx, bounding_box = bbox, ) ds.domain_left_edge = ds.domain_left_edge.astype(np.float64) ds.domain_right_edge = ds.domain_right_edge.astype(np.float64) ds.domain_width = ds.domain_width.astype(np.float64) ds.domain_center = ds.domain_center.astype(np.float64) ad = ds.all_data() Npix = 1024 image = np.zeros([Npix, Npix, 4], dtype='float64') cbx = yt.visualization.color_maps.mcm.RdBu col_field = ad['particle_velocity_z'] # Calculate image coordinates ix and iy based on what your view width is # ix = (ad['particle_position_x'] - ds.domain_left_edge[0])/ds.domain_width[0] iy = (ad['particle_position_y'] - ds.domain_left_edge[1])/ds.domain_width[1] # col_field = (col_field - col_field.min()) / (col_field.mean() + 4*col_field.std() - col_field.min()) add_rgba_points_to_image(image, ix.astype('float64'), iy.astype('float64'), cbx(col_field)) # yt.write_bitmap(enhance(image), 'zoom-output/zoom{:0>4d}.png'.format(rank)) print 'Splatted %i particles' % ad['particle_position_x'].size
def snap(self, template=r"snap_%04i.png"): yt.write_bitmap(self.scene.image[:, :, :3], template % self.snap_count) self.snap_count += 1
center = np.array([-2505805.31114929, -3517306.7572399, -1639170.70554688]) + np.array([0, 0, offset]) width = 50.0e3 # 5 Mpc bbox = np.array([center-width/2, center+width/2]) ds = yt.load(filename, midx_filename=midx, bounding_box = bbox, ) ds.domain_left_edge = ds.domain_left_edge.astype(np.float64) ds.domain_right_edge = ds.domain_right_edge.astype(np.float64) ds.domain_width = ds.domain_width.astype(np.float64) ds.domain_center = ds.domain_center.astype(np.float64) ad = ds.all_data() Npix = 1024 image = np.zeros([Npix, Npix, 4], dtype='float64') cbx = yt.visualization.color_maps.mcm.RdBu col_field = ad['particle_velocity_z'] # Calculate image coordinates ix and iy based on what your view width is ix = (ad['particle_position_x'] - ds.domain_left_edge[0])/ds.domain_width[0] iy = (ad['particle_position_y'] - ds.domain_left_edge[1])/ds.domain_width[1] col_field = (col_field - col_field.min()) / (col_field.mean() + 4*col_field.std() - col_field.min()) add_rgba_points_to_image(image, ix.astype('float64'), iy.astype('float64'), cbx(col_field)) yt.write_bitmap(enhance(image), 'splat{:0>4d}.png'.format(rank)) print 'Splatted %i particles' % ad['particle_position_x'].size
ds = yt.load( filename, midx_filename=midx, bounding_box=bbox, ) ds.domain_left_edge = ds.domain_left_edge.astype(np.float64) ds.domain_right_edge = ds.domain_right_edge.astype(np.float64) ds.domain_width = ds.domain_width.astype(np.float64) ds.domain_center = ds.domain_center.astype(np.float64) ad = ds.all_data() Npix = 1024 image = np.zeros([Npix, Npix, 4], dtype='float64') cbx = yt.visualization.color_maps.mcm.RdBu col_field = ad['particle_velocity_z'] # Calculate image coordinates ix and iy based on what your view width is ix = (ad['particle_position_x'] - ds.domain_left_edge[0]) / ds.domain_width[0] iy = (ad['particle_position_y'] - ds.domain_left_edge[1]) / ds.domain_width[1] col_field = (col_field - col_field.min()) / ( col_field.mean() + 4 * col_field.std() - col_field.min()) add_rgba_points_to_image(image, ix.astype('float64'), iy.astype('float64'), cbx(col_field)) yt.write_bitmap(enhance(image), 'splat{:0>4d}.png'.format(rank)) print 'Splatted %i particles' % ad['particle_position_x'].size
import yt import yt_idv ds = yt.load_sample("IsolatedGalaxy") dd = ds.all_data() rc = yt_idv.render_context("egl", width=1024, height=1024) rc.add_scene(dd, "density", no_ghost=True) rc.scene.components[0].visible = False from yt_idv.scene_annotations.grid_outlines import GridOutlines # NOQA from yt_idv.scene_data.grid_positions import GridPositions # NOQA grids = ds.index.grids.tolist() gp = GridPositions(grid_list=grids) rc.scene.data_objects.append(gp) go = GridOutlines(data=gp) rc.scene.components.append(go) image = rc.run() yt.write_bitmap(image, "grid_outline.png")
filename, midx_filename=midx, bounding_box=bbox, ) ds.domain_left_edge = ds.domain_left_edge.astype(np.float64) ds.domain_right_edge = ds.domain_right_edge.astype(np.float64) ds.domain_width = ds.domain_width.astype(np.float64) ds.domain_center = ds.domain_center.astype(np.float64) ad = ds.all_data() Npix = 1024 image = np.zeros([Npix, Npix, 4], dtype='float64') cbx = yt.visualization.color_maps.mcm.RdBu col_field = ad['particle_velocity_z'] # Calculate image coordinates ix and iy based on what your view width is # ix = (ad['particle_position_x'] - ds.domain_left_edge[0]) / ds.domain_width[0] iy = (ad['particle_position_y'] - ds.domain_left_edge[1]) / ds.domain_width[1] # col_field = (col_field - col_field.min()) / ( col_field.mean() + 4 * col_field.std() - col_field.min()) add_rgba_points_to_image(image, ix.astype('float64'), iy.astype('float64'), cbx(col_field)) # yt.write_bitmap(enhance(image), 'zoom-output/zoom{:0>4d}.png'.format(rank)) print 'Splatted %i particles' % ad['particle_position_x'].size