Source

adlerviz.2012 / zoom_popiii.py

Full commit
from yt.mods import *
from yt.utilities.amr_kdtree.api import *

def lin_ramp(val,mi,ma):
    val, mi, ma = 10.**val, 10.**mi, 10.**ma
    scale = (val-mi)/(ma-mi)
    if iterable(scale): 
        scale[scale<0.0]=0.0
    else:
        scale = max(scale,0.0)
    return scale

pf = load("../DD0087")

final_width = 100.0/pf['au']
# initial_width = 10.0/pf['pc']
initial_width = na.sqrt(3)
initial_width = 1.0/pf['pc']
initial_width = 2.0

#v,c = pf.h.find_max("Density")
c = na.array([0.49681812222843291, 0.49349863347742939, 0.49282695497822715])
v = na.log10(1.59666e-10)
min_v = -26.0

#sp = pf.h.sphere("max", (100.0, 'au'))
#L = sp.quantities["AngularMomentumVector"]()
L = [ 0.38855402,  0.23911532, -0.88985934]

def get_tf(offset, op_val=None):
    tmi, tma = min_v - 2.0, v + 2.0
    tf = ColorTransferFunction((min_v-3., v+3.), nbins=1024)
    alphas = 0.01
    cvals = range(-25, -10)
    cvals = na.linspace(-25.5, -11.5, 15) 
    alphas = na.logspace(-1., 0.5, len(cvals))

    # Add a smooth background
    tf.map_to_colormap(-28.0, v, colormap='kamae', scale = 1.0,
            scale_func=lin_ramp) 

    # Add isocontours
    for i,alpha in zip(cvals, alphas):
        tf.sample_colormap(i - offset, 0.01, alpha, "kamae", col_bounds=(min_v,v))

    # Add a more opaque iso at op_val
    if op_val is not None:
        tf.map_to_colormap(op_val-0.1, op_val+0.1, colormap="BuPu_r", scale=5.0, scale_func = None)
    return tf

tf = get_tf(0.0, -10.8)

tf.plot('tf.png')

Npix = 512
Nframes = 100 
Nrotate = 100
cam = pf.h.camera(c, L, initial_width, (Npix,Npix), tf, no_ghost=False)

try:
    cam.volume.load_kd_bricks()
except:
    cam.snapshot('frames/first_snap.png')
    cam.volume.store_kd_bricks()

frame = 0
for i, snapshot in enumerate(cam.zoomin(initial_width/final_width, Nframes)):
    write_bitmap(snapshot, "frames/zoom2_%04i.png" % (frame))
    frame += 1

for i, snapshot in enumerate(cam.rotation(2*na.pi, Nrotate)):
    write_bitmap(snapshot, "frames/zoom2_%04i.png" % frame)
    frame += 1

# # This is super cheesy, but I am not sure how to wrap this all in parallel
# # objects.
# f = (initial_width/final_width)**(1.0/Nframes)
# for i in xrange(Nframes):
#     # Now we apply an offset so that it looks a bit like it's moving
#     cam.zoom(f)
#     print cam.width[0]*pf['au']
#     snapshot = cam.snapshot()
#     write_bitmap(snapshot, "frames/zoom2_%04i.png" % (i))
# 
#