<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi Junhwan</div><div><br></div><div>In fact, in general you'll get back a 1D array. These are the collapsed values for the data in a single grid (i.e. flattened from 3D to 1D).</div><div><br></div><div>Since your field does not explicitly depend on the 3D nature of the grid, this is an easy fix:</div><div><br></div><div>def _DensityCeiling(field, data):</div><div><div bgcolor="#FFFFFF" text="#000000"><font face="Monotype.com"> Ceiling = 1e-22</font></div><div bgcolor="#FFFFFF" text="#000000"><font face="Monotype.com"> wh = np.where(data["Density"] < Ceiling)<br> DensityCeiling = data["Density"]<br></font></div><div bgcolor="#FFFFFF" text="#000000"> DensityCeiling[wh] = Ceiling</div><div bgcolor="#FFFFFF" text="#000000"><font face="Monotype.com"> return DensityCeiling</font></div></div><div><br></div><div>Here np is how I've imported numpy locally. There may be an even cleverer way of doing the array manipulation that someone else on the list may know of off-hand.</div><div><br></div><div>Cheers,</div><div><br></div><div>Nathan</div><br><div><div>On Oct 4, 2012, at 2:00 PM, Jun-Hwan Choi wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<div bgcolor="#FFFFFF" text="#000000">
<font face="Monotype.com">Hi yt-users,<br>
<br>
I try to make a density projection of my simulation.<br>
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.<br>
And, I made a following script:<br>
############################################<br>
from yt.mods import *<br>
import matplotlib.pylab as pylab<br>
<br>
def _DensityCeiling(field, data):<br>
Ceiling = 1e-22<br>
nx, ny, nz = data["Density"].shape<br>
DensityCeiling = na.zeros(data["Density"].shape,
dtype='float64')<br>
DensityCeiling = data["Density"]<br>
for ix, in range(0,nx):<br>
for iy, in range(0,ny):<br>
for iz, in range(0,nz):<br>
if(data["DensityCeiling"][ix,iy,iz] >
Ceiling):<br>
DensityCeiling[ix,iy,iz] = Ceiling<br>
return DensityCeiling<br>
add_field("DensityCeiling", function=_DensityCeiling,
units=r"\rm{g}/\rm{cm^3}")<br>
<br>
<br>
# load up a dataset<br>
pf = load("DD0000/DD0000")<br>
all_center = [0.5, 0.5, 0.5]<br>
<br>
pc = PlotCollection(pf,center=all_center)<br>
pc.add_slice("DensityCeiling", 0)<br>
pc.add_slice("DensityCeiling", 2)<br>
pc.add_projection("DensityCeiling", 0)<br>
pc.add_projection("DensityCeiling", 2)<br>
<br>
pc.set_width(6, 'kpc')<br>
pc.save("cen_t%04.1f_L6K" % pf.current_time)<br>
pc.set_width(1, 'kpc')<br>
pc.save("cen_t%04.1f_L1K" % pf.current_time)<br>
#######################################################<br>
<br>
And then, I got a following error.<br>
File "DenViz.py", line 6, in _DensityCeiling<br>
nx, ny, nz = data["Density"].shape<br>
ValueError: need more than 1 value to unpack<br>
<br>
It turns out that the data</font><font face="Monotype.com">["Density"]
is not always 3d array but sometimes become 1d array.<br>
Is there any way to fix the derived field to avoid this problem?<br>
<br>
Thank you in advance,<br>
Junhwan<br>
</font><font face="Monotype.com"><br>
<br>
</font>
<pre class="moz-signature" cols="72">--
--------------------------------------------------------------
Jun-Hwan Choi, Ph.D.
Department of Physics and Astronomy, University of Kentucky
Tel: (859) 897-6737 Fax: (859) 323-2846
Email: <a class="moz-txt-link-abbreviated" href="mailto:jhchoi@pa.uky.edu">jhchoi@pa.uky.edu</a> URL: <a class="moz-txt-link-freetext" href="http://www.pa.uky.edu/~jhchoi">http://www.pa.uky.edu/~jhchoi</a>
--------------------------------------------------------------
</pre>
</div>
_______________________________________________<br>yt-users mailing list<br><a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org<br></blockquote></div><br></body></html>