Hi Elizabeth,<div><br></div><div>Since conferences are good times for very short projects, I've written up a go at the nearest neighbors.  See the commit message for a bit more info.  </div><div><br></div><div><a href="https://bitbucket.org/yt_analysis/yt/changeset/dfb88152f5e0">https://bitbucket.org/yt_analysis/yt/changeset/dfb88152f5e0</a></div>

<div><br></div><div>There are two functions.  One that takes a position and will return the neighbor cells around that position.  The other takes the grid object and cell indices and does the same thing.</div><div><br></div>

<div>They are </div><div>AMRKDTree.get_nearest_neighbors_from_position</div><div>and</div><div><div>AMRKDTree.get_nearest_neighbors</div><div><br></div><div>Check out the pastebin for an example:</div><div><a href="http://paste.yt-project.org/show/1803/">http://paste.yt-project.org/show/1803/</a></div>

<div><br></div><div>Let me know if it works/if it is insanely slow/how it could be improved!</div><div><br></div><div>Best,</div><div>Sam</div><br><div class="gmail_quote">On Tue, Sep 13, 2011 at 5:35 PM, Elizabeth Tasker <span dir="ltr"><<a href="mailto:taskere@mcmaster.ca">taskere@mcmaster.ca</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi Matt,<br>
<br>
I actually use that to get my initial sweep of objects and it works great. This next step through it more complex than just a contour, since it's not obvious what my boundary line will be: it depends on the environment of each object which gives saddle points in the potential field. (This is why this program is taking me a while. *One day* it will be complete and work and I will win at life. Yes.)<br>


<br>
I'm good with covering grids, honest. I was just seeing if I could be smarter easily.<br><font color="#888888">
<br>
Elizabeth</font><div><div></div><div class="h5"><br>
<br>
<br>
<br>
Matthew Turk wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Elizabeth,<br>
<br>
We have an "extract_connected_sets" routine that may work for what you<br>
are doing.  This is what the clump finder is built on.  You can supply<br>
it a threshold, and it will conduct FOF on the cells, returning<br>
objects (and boundary values) that satisfy it.  Unfortunately, right<br>
now it only works with threshholding in one dimension.  So, what you<br>
can do is define a field that returns 1/0 for whether it should be<br>
included, and then perform the contouring with extract_connected_sets<br>
on your initial data object.<br>
<br>
-Matt<br>
<br>
On Tue, Sep 13, 2011 at 5:22 PM, Elizabeth Tasker <<a href="mailto:taskere@mcmaster.ca" target="_blank">taskere@mcmaster.ca</a>> wrote:<br>
  <br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Matt and Sam,<br>
<br>
I just want to do a friends-of-friends scheme where I add cells to an<br>
ordered list if their properties (density, Potential field etc) satisfy my<br>
criteria.<br>
<br>
Unfortunately, that does mean that I might walk completely off one grid,<br>
ghost zones and all, and onto another one, so I think what Matt suggests<br>
below only buys me a few extra steps.<br>
<br>
Sam, your routine probably was what I was thinking of, but my question<br>
wasn't supposed to cause extra work! It was more a "does this exist and<br>
everyone is using it apart from me?" query. I'll keep with extracted grids<br>
and then if I run into issues or this later morphs into a useful analysis<br>
routine that people want to use or parallelise, perhaps we'll revisit the<br>
question of using trees.<br>
<br>
Thanks again,<br>
<br>
Elizabeth<br>
<br>
Matthew Turk wrote:<br>
    <br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Elizabeth,<br>
<br>
If you request ghost zones you can do this.  In particular, requested<br>
unsmoothed ghost zones will ensure no interpolation occurs.  You can<br>
do this either by yourself, grid by grid with<br>
grid_obj.retrieve_ghost_zones(<u></u>...) or you can use ValidateSpatial in a<br>
field definition.<br>
<br>
It might help if you shared what kind of operation you want to do once<br>
you have the 26.  If you have the index of a cell, you can just<br>
access:<br>
<br>
grid[field][index_i+1, index_j+1, index_k+1]<br>
<br>
and do the +/- and 0/1 modifications.<br>
<br>
-Matt<br>
<br>
On Tue, Sep 13, 2011 at 5:04 PM, Elizabeth Tasker <<a href="mailto:taskere@mcmaster.ca" target="_blank">taskere@mcmaster.ca</a>><br>
wrote:<br>
<br>
      <br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Stephen,<br>
<br>
Honestly, I was just hoping there was some magically pre-programmed way<br>
to<br>
grab the 26 most refined neighbours of a cell, regardless of which grid<br>
they<br>
were on or level that happened to be. Mapping to an extracted region is<br>
no<br>
hassle, I was just checking there wasn't a smart, quick way of doing this<br>
already.<br>
<br>
Thanks for the info!<br>
<br>
Elizabeth<br>
<br>
<br>
<br>
Stephen Skory wrote:<br>
<br>
        <br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Elizabeth,<br>
<br>
<br>
<br>
          <br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
So ... how hard are we talking? :)<br>
<br>
<br>
            <br>
</blockquote>
The thing is, in all honesty the kdtree we're using in yt (in<br>
parallelHF and in a few other places) is not very convenient. It's<br>
written in fortran, so the array orderings are backwards from the rest<br>
of python (which is C based). It's also confusing to use, it has a<br>
weird wrapper to access the functions that isn't very easy to<br>
understand. The only reason we're using it is in my tests I found this<br>
kdtree implementation to be significantly faster than the alternatives<br>
out there.<br>
<br>
Perhaps if I knew a bit more about what you wanted to do I could help<br>
you come up with a solution that avoids the kdtree. Are you interested<br>
in only the nearest 6 touching cells to a cell? Or do you want to look<br>
at the edges and the corners? Farther out? Do you care about<br>
periodicity? You mentioned looking at grids of coarser resolution, do<br>
you still think you'd like to have neighbor cells returned from a<br>
lower resolution grid?<br>
<br>
<br>
<br>
          <br>
</blockquote>
______________________________<u></u>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">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/<u></u>listinfo.cgi/yt-users-<u></u>spacepope.org</a><br>
<br>
<br>
        <br>
</blockquote>
______________________________<u></u>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">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/<u></u>listinfo.cgi/yt-users-<u></u>spacepope.org</a><br>
<br>
      <br>
</blockquote>
______________________________<u></u>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">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/<u></u>listinfo.cgi/yt-users-<u></u>spacepope.org</a><br>
<br>
    <br>
</blockquote>
______________________________<u></u>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">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/<u></u>listinfo.cgi/yt-users-<u></u>spacepope.org</a><br>
  <br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">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/<u></u>listinfo.cgi/yt-users-<u></u>spacepope.org</a><br>
</div></div></blockquote></div><br></div>