<div dir="ltr">Hi, Morgan--<br><div><br></div><div>I do this by adding a new field, and getting the new field to work with the grid data.  This works for Enzo, it's probably similar in other codes.  Follow the examples on the website for adding new fields, my example is a little out of date.<br>

</div><div><br>def _XAverageDensity(field,data):<br>  #this is to make sure your output is the right shape<br>  new_field = na.zeros(data['Density'].shape)  <br></div><div>  #watch these indices, I just made this up on the spot<br>

</div><div>  new_field[1:,:,:] =  0.5*(data['Density'][:-1,:,:] + data['Density'][1:,:,:])<br></div><div>  return new_field<br></div><div><br>add_field('XAverageDensity', function = _XAverageDensity, validators=[ValidateSpatial(1,['Density'])])<br>

<br></div><div>The last bit about validators forces this function to work on the 3d data cube that yt gets off disk, rather than the flattened arrays that are better for variable resolution.  The 1 indicates how many extra ghost zones yt gets, and ['Density'] can be a whole list of fields.<br>

<br></div><div>d.<br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 26, 2013 at 7:39 AM, Morgan Presley <span dir="ltr"><<a href="mailto:mpresley@princeton.edu" target="_blank">mpresley@princeton.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span style="font-family:arial,sans-serif;font-size:13.333333969116211px">Hello all,</span></div><span style="font-family:arial,sans-serif;font-size:13.333333969116211px"><div>

<span style="font-family:arial,sans-serif;font-size:13.333333969116211px"><br>
</span></div>I'm trying to access the density for a cell and its six neighbors (in the x,y,z directions), but I can't figure out how I can get the information for the neighboring cells. The problem is that dd[ 'NumberDensity' ] is a one-dimensional array, and I don't know the original 3d shape of the data, so I can't reshape the array into three dimensions. Is there a way to get the indices of a cell's neighbors? </span><div>


<span style="font-family:arial,sans-serif;font-size:13.333333969116211px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13.333333969116211px">Thanks for any help!</span><span class="HOEnZb"><font color="#888888"><br>

<div><span style="font-family:arial,sans-serif;font-size:13.333333969116211px">Morgan</span></div>
</font></span></div></div>
<br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr">-- Sent from a computer.<br></div>
</div>