[yt-users] Finding the indices of a cell's neighbors
David Collins
dcollins4096 at gmail.com
Fri Jul 26 10:00:21 PDT 2013
Hi, Morgan--
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.
def _XAverageDensity(field,data):
#this is to make sure your output is the right shape
new_field = na.zeros(data['Density'].shape)
#watch these indices, I just made this up on the spot
new_field[1:,:,:] = 0.5*(data['Density'][:-1,:,:] +
data['Density'][1:,:,:])
return new_field
add_field('XAverageDensity', function = _XAverageDensity,
validators=[ValidateSpatial(1,['Density'])])
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.
d.
On Fri, Jul 26, 2013 at 7:39 AM, Morgan Presley <mpresley at princeton.edu>wrote:
> Hello all,
>
> 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?
>
> Thanks for any help!
> Morgan
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
--
-- Sent from a computer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20130726/67ec8808/attachment.html>
More information about the yt-users
mailing list