[yt-users] Error in visualization with new derived field
Jun-Hwan Choi
choi.junhwan at gmail.com
Thu Oct 4 14:00:37 PDT 2012
Hi yt-users,
I try to make a density projection of my simulation.
I would like to make a small modification that if the cell density
higher than a given density ceiling the density value becomes the
density ceiling.
And, I made a following script:
############################################
from yt.mods import *
import matplotlib.pylab as pylab
def _DensityCeiling(field, data):
Ceiling = 1e-22
nx, ny, nz = data["Density"].shape
DensityCeiling = na.zeros(data["Density"].shape, dtype='float64')
DensityCeiling = data["Density"]
for ix, in range(0,nx):
for iy, in range(0,ny):
for iz, in range(0,nz):
if(data["DensityCeiling"][ix,iy,iz] > Ceiling):
DensityCeiling[ix,iy,iz] = Ceiling
return DensityCeiling
add_field("DensityCeiling", function=_DensityCeiling,
units=r"\rm{g}/\rm{cm^3}")
# load up a dataset
pf = load("DD0000/DD0000")
all_center = [0.5, 0.5, 0.5]
pc = PlotCollection(pf,center=all_center)
pc.add_slice("DensityCeiling", 0)
pc.add_slice("DensityCeiling", 2)
pc.add_projection("DensityCeiling", 0)
pc.add_projection("DensityCeiling", 2)
pc.set_width(6, 'kpc')
pc.save("cen_t%04.1f_L6K" % pf.current_time)
pc.set_width(1, 'kpc')
pc.save("cen_t%04.1f_L1K" % pf.current_time)
#######################################################
And then, I got a following error.
File "DenViz.py", line 6, in _DensityCeiling
nx, ny, nz = data["Density"].shape
ValueError: need more than 1 value to unpack
It turns out that the data["Density"] is not always 3d array but
sometimes become 1d array.
Is there any way to fix the derived field to avoid this problem?
Thank you in advance,
Junhwan
--
--------------------------------------------------------------
Jun-Hwan Choi, Ph.D.
Department of Physics and Astronomy, University of Kentucky
Tel: (859) 897-6737 Fax: (859) 323-2846
Email: jhchoi at pa.uky.edu URL: http://www.pa.uky.edu/~jhchoi
--------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20121004/6448bb4c/attachment.htm>
More information about the yt-users
mailing list