[yt-users] Problem with zlim setting in yt slices

Fen Zhao fenzhao at stanford.edu
Tue Sep 15 12:34:23 PDT 2009


Hi all,

I've recently been having problems setting the colorbar max and min in
yt, and would appreciate some help figuring out what the problem might
be.  Full python code attached at the end, but the important parts
are:

        pf=lagos.EnzoStaticOutput(thefile)
	pc = PlotCollection(pf, center=[c1, c2, c3])


	plot1=pc.add_slice("B", 0)
	plot2=pc.add_slice("Density", 0)
	plot3=pc.add_slice("Velocity_Vorticity1", 0)
	plot3.set_log_field(False)
	plot3.set_zlim(-200, 500)
	thefile2=(output % ind) +"large"
	pc.save(thefile2)

	plot1.set_width(haloradius*2,1)
	plot2.set_width(haloradius*2,1)
	plot3.set_width(haloradius*2,1)
	plot3.set_log_field(False)
	plot3.set_zlim(-200, 500)
	thefile2=(output  % ind) + "halo"
	pc.save(thefile2)


Neither the "large" or "halo" have the colorbar set correctly.

Cheers,
Fen



Context of code:


import sys
sys.path = ["/usr/work/mturk/local-testing/lib/python2.5/site-packages/"] + \
           sys.path

from yt.config import ytcfg; ytcfg["lagos","serialize"] = "False"
from yt.mods import *

#import yt.lagos as lagos
#import yt.raven as raven
#import os.path

def write_out_binned_vals(plot, fn):
	vals = plot.vals
	x = plot.x_bins
	y = plot.y_bins
	print "Opening",fn, vals.shape, x.shape, y.shape
	f=open(fn,"w")
	for i in range(x.shape[0]):
		for j in range(y.shape[0]):
			print i,j
			f.write("%0.5e\t%0.5e\t%0.5e\n" % (x[i],y[j],vals[i,j]))
	f.close()

#ind=71
#inputDir="/a/wain027/g.ki.ki01/fenzhao/data/nobackup/vorticity/correct"
inputDir="/lustre/ki/orange/fenzhao/vorticity/try2"
outputDir="/a/wain027/g.ki.ki01/fenzhao/data/nobackup/vorticity/analysis/slices/data/images/other"
outputName="lustreversion"

start=40
end=40

ind=start

while ind<=end:
	thefile= inputDir + "/star_%04i.dir/star_%04i" % (ind,ind)
	output= outputDir + "/" + outputName+ "%04i"

	pf=lagos.EnzoStaticOutput(thefile)

	timeUnits=pf["years"]
	DensityUnits=pf["Density"]
	LengthUnits=pf["cm"]
	VelocityUnits=pf["x-velocity"]

	newred=pf["CosmologyCurrentRedshift"]
	a=1/(1+newred)

	k=1.3806503e-16
	c=2.99792e10
	e=4.8032068e-10
	me=9.1093897e-28
	mh=1.66053886e-24

	pressure=k*(DensityUnits/mh)
	density=DensityUnits/mh
	graddensity=density/LengthUnits
	gradpressure=pressure/LengthUnits
	bbunits=(c/e)*graddensity*gradpressure/(density**2)

	vorticityUnits=VelocityUnits/LengthUnits
	alpha=mh*c/e/(1+1e-4)

	def Vorticity(field,data):
		return (((data["Velocity_Vorticity1"]**2)+(data["Velocity_Vorticity2"]**2)+(data["
Velocity_Vorticity3"]**2))**0.5)*vorticityUnits
	lagos.add_field("Vorticity", units=r"\rm{s}^{-1}",function=Vorticity)


	import numpy as na
	def B(field, data):
		return na.clip(alpha*(data["Vorticity"]),1e-30,1e30)
	lagos.add_field("B", units=r"\rm{Gauss}", function=B)


	haloradius=0.013

	halo = pf.h.sphere([0.5, 0.5, 0.5], haloradius*2.0)
	v, i, c1, c2, c3, gi = halo.quantities["MaxLocation"]("Density",
lazy_reader=True)


	
	pc = PlotCollection(pf, center=[c1, c2, c3])


	plot1=pc.add_slice("B", 0)
	plot2=pc.add_slice("Density", 0)
	plot3=pc.add_slice("Velocity_Vorticity1", 0)
	plot3.set_log_field(False)
	plot3.set_zlim(-200, 500)
	thefile2=(output % ind) +"large"
	pc.save(thefile2)

	plot1.set_width(haloradius*2,1)
	plot2.set_width(haloradius*2,1)
	plot3.set_width(haloradius*2,1)
	plot3.set_log_field(False)
	plot3.set_zlim(-200, 500)
	thefile2=(output  % ind) + "halo"
	pc.save(thefile2)

	ind=ind+1



#plot=pc.add_slice("B", 0)



More information about the yt-users mailing list