Source

yt_map / run.py

Full commit
from yt.mods import *
pf = load("/home/mturk/Research/data/JHK-DD0030/galaxy0030")
proj = pf.h.proj(2, "Density")
TS = 256
import tempfile
from yt.visualization.image_writer import apply_colormap
from yt.utilities.amr_utils import write_png_to_file

# We say 256 pixels for each tile, and we have 

import bottle
bottle.debug(True)

mi = na.log10(proj["Density"].min())
ma = na.log10(proj["Density"].max())

@bottle.route("/map/:L/:x/:y.png")
def map(L, x, y):
    dd = TS / (512.0*2**int(L))
    relx = int(x) * dd
    rely = int(y) * dd
    DW = (pf.domain_left_edge + pf.domain_right_edge)/2.0
    xp = pf.domain_left_edge[0] + relx * DW[0]
    yp = pf.domain_left_edge[1] + rely * DW[1]
    frb = FixedResolutionBuffer(proj, (xp, xp+dd*DW[0], yp, yp+dd*DW[1]), (256, 256))
    tf = tempfile.TemporaryFile()
    to_plot = apply_colormap(na.log10(frb["Density"]), color_bounds = (mi, ma))
    print dd, relx, rely,
    print xp, xp+dd*DW[0],
    print yp, yp+dd*DW[1],
    print frb["Density"].max(),
    print frb["Density"].min()
    write_png_to_file(to_plot, tf)
    tf.seek(0)
    return tf.read()

@bottle.route("/")
@bottle.route("/index.html")
def index():
    return open("index.html").read()

@bottle.route("/static/:name")
def static(name):
    return open(name).read()
    return open("index.html").read()
#bottle.run(server='rocket')
bottle.run()