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

Sam Skillman samskillman at gmail.com
Tue Sep 15 14:02:13 PDT 2009


Hi Dave,

Do you have a field with negative and positive values?  I can get this
to work with only positive valued fields, but not negative.

Also, I have found that when adding a field that has negative or zero
values, it is helpful to define it as a take_log=False:

def _LinearDensity(field,data):
    return data['Density']
yt.lagos.add_field("LinearDensity", function=_LinearDensity,take_log=False)

Otherwise you can end up taking logs of 0 or negative numbers and it
can cause problems.  Dave, do you use the take_log=False in your case?

Sam

On Tue, Sep 15, 2009 at 2:34 PM, David Collins
<dcollins at physics.ucsd.edu> wrote:
> I've fought with this myself.  Here's what I've come up with that works.
>
>
> 1.)  This doesn't work
> pc=raven.PlotColleciton( ... )
> plot=pc.add_projection( ... )
> plot.set_zlim( a, b) # Doesn't work
> pc.save(filename)
>
> 2.) Calling set_zlim on the plot collection does work
> pc=raven.PlotColleciton( ... )
> plot=pc.add_projection( ... )
> pc.set_zlim(a,b) #does work.
> pc.save(filename)
>
> 3.) If you change the colormap *and* zlim, the colorbar won't reflect
> the new colormap (try it with "gray", it's most noticable)  You can
> get around this by doing an extra "save" before set_zlim
>
> 4.)  My general script looks something like this:
>
> pf=lagos.EnzoStaticOutput(path)
> for field in field_list:
>  pc=raven.PlotCollection(pf)
>  plot = pc.add_projection(field,axis,weight)
>  pc.set_cmap('ZebraStripes') #or maybe a more useful cmap
>  pc.save(Filename)
>  pc.set_zlim(0,1)
>  pc.save(Filename)
>
>
>
> On Tue, Sep 15, 2009 at 12:46 PM, Eric Hallman
> <Eric.Hallman at colorado.edu> wrote:
>> Hear hear.  I am working on something right now, which is doing a similar
>> thing.  no matter what I set the limits to, it is giving me only a factor of
>> 10 of the data in the color scale.  My example is very similar, just using
>> set_zlim...
>>
>>
>> On Sep 15, 2009, at 1:34 PM, Fen Zhao wrote:
>>
>> 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)
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>> Dr. Eric J. Hallman
>> NSF Astronomy and Astrophysics Postdoctoral Fellow
>> Center for Astrophysics and Space Astronomy
>> University of Colorado at Boulder
>> hallman (at) casa.colorado.edu
>> office(s): (303) 735-0129 / (303) 492-7484
>> http://solo.colorado.edu/~hallman/
>>
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>



-- 
Samuel W. Skillman
DOE Computational Science Graduate Fellow
Center for Astrophysics and Space Astronomy
University of Colorado at Boulder
samuel.skillman[at]colorado.edu



More information about the yt-users mailing list