Path: blob/main/doc/source/cookbook/amrkdtree_downsampling.py
928 views
# Using AMRKDTree Homogenized Volumes to examine large datasets1# at lower resolution.23# In this example we will show how to use the AMRKDTree to take a simulation4# with 8 levels of refinement and only use levels 0-3 to render the dataset.56# Currently this cookbook is flawed in that the data that is covered by the7# higher resolution data gets masked during the rendering. This should be8# fixed by changing either the data source or the code in9# yt/utilities/amr_kdtree.py where data is being masked for the partitioned10# grid. Right now the quick fix is to create a data_collection, but this11# will only work for patch based simulations that have ds.index.grids.1213# We begin by loading up yt, and importing the AMRKDTree14import numpy as np1516import yt17from yt.utilities.amr_kdtree.api import AMRKDTree1819# Load up a dataset and define the kdtree20ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")21im, sc = yt.volume_render(ds, ("gas", "density"), fname="v0.png")22sc.camera.set_width(ds.arr(100, "kpc"))23render_source = sc.get_source()24kd = render_source.volume2526# Print out specifics of KD Tree27print("Total volume of all bricks = %i" % kd.count_volume())28print("Total number of cells = %i" % kd.count_cells())2930new_source = ds.all_data()31new_source.max_level = 332kd_low_res = AMRKDTree(ds, data_source=new_source)33print(kd_low_res.count_volume())34print(kd_low_res.count_cells())3536# Now we pass this in as the volume to our camera, and render the snapshot37# again.3839render_source.set_volume(kd_low_res)40render_source.set_field(("gas", "density"))41sc.save("v1.png", sigma_clip=6.0)4243# This operation was substantially faster. Now lets modify the low resolution44# rendering until we find something we like.4546tf = render_source.transfer_function47tf.clear()48tf.add_layers(494,500.01,51col_bounds=[-27.5, -25.5],52alpha=np.ones(4, dtype="float64"),53colormap="RdBu_r",54)55sc.save("v2.png", sigma_clip=6.0)5657# This looks better. Now let's try turning on opacity.5859tf.grey_opacity = True60sc.save("v3.png", sigma_clip=6.0)61#62## That seemed to pick out some interesting structures. Now let's bump up the63## opacity.64#65tf.clear()66tf.add_layers(674,680.01,69col_bounds=[-27.5, -25.5],70alpha=10.0 * np.ones(4, dtype="float64"),71colormap="RdBu_r",72)73tf.add_layers(744,750.01,76col_bounds=[-27.5, -25.5],77alpha=10.0 * np.ones(4, dtype="float64"),78colormap="RdBu_r",79)80sc.save("v4.png", sigma_clip=6.0)81#82## This looks pretty good, now lets go back to the full resolution AMRKDTree83#84render_source.set_volume(kd)85sc.save("v5.png", sigma_clip=6.0)8687# This looks great!888990