Paste #1482

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from yt.mods import *
import yt.utilities.amr_utils as au
import yt.visualization.image_writer as iw

use_random_box = False

pf = load("JHK-DD0030/galaxy0030"); w = 0.01

dd = pf.h.all_data()
min_rho, max_rho = na.log10(dd.quantities["Extrema"]("Density")[0])
tf = ColorTransferFunction((min_rho - 0.1, max_rho + 0.1))
#tf.add_layers(10)
tf.alpha.y = na.mgrid[0:1:tf.nbins*1j]
v, c = pf.h.find_max("Density")
L = [0.0, 0.0, 1.0]
cam = pf.h.camera([0.5, 0.5, 0.5], L, w, (512, 512), tf, use_kd = False)

if use_random_box:
    x = 5e-2 * (na.random.random(1000) - 0.5) + 0.5
    y = 5e-2 * (na.random.random(1000) - 0.5) + 0.5
    z = 5e-2 * (na.random.random(1000) - 0.5) + 0.5
    cc = random.random(3000).reshape((1000,3)).astype("float64")
else:
    si = (dd["creation_time"] > 0)
    x = dd["particle_position_x"][si][::10]
    y = dd["particle_position_y"][si][::10]
    z = dd["particle_position_z"][si][::10]
    age = dd["ParticleAge"][si]
    age = (age - age.min())/(age.max() - age.min())
    cc = iw.map_to_colors(age, "hot").squeeze()[:,:3].astype("float64") / 255.0

skc = au.star_kdtree_container()
skc.add_points(x, y, z, cc)
skc.coeff = 1e-2
skc.sigma = 0.5 * pf.h.get_smallest_dx()
cam.volume.initialize_source()
for b in cam.volume.bricks: b.set_star_tree(skc)

ss = cam.snapshot("hi.png")