[Yt-svn] commit/yt: MatthewTurk: Adding a find_values_at_point function. For an example of using this to find

Bitbucket commits-noreply at bitbucket.org
Fri Jul 29 15:32:02 PDT 2011


1 new changeset in yt:

http://bitbucket.org/yt_analysis/yt/changeset/3fd820235b04/
changeset:   3fd820235b04
branch:      yt
user:        MatthewTurk
date:        2011-07-30 00:31:52
summary:     Adding a find_values_at_point function.  For an example of using this to find
all the points on the surface of a sphere, see
http://paste.enzotools.org/show/1733/
affected #:  2 files (2.2 KB)

--- a/yt/data_objects/data_containers.py	Fri Jul 29 15:52:48 2011 -0400
+++ b/yt/data_objects/data_containers.py	Fri Jul 29 18:31:52 2011 -0400
@@ -410,6 +410,23 @@
                              __del_grid_levels)
 
 
+    def __get_grid_dimensions(self):
+        if self.__grid_dimensions == None:
+            self.__grid_dimensions = na.array([g.ActiveDimensions for g in self._grids])
+        return self.__grid_dimensions
+
+    def __del_grid_dimensions(self):
+        del self.__grid_dimensions
+        self.__grid_dimensions = None
+
+    def __set_grid_dimensions(self, val):
+        self.__grid_dimensions = val
+
+    __grid_dimensions = None
+    grid_dimensions = property(__get_grid_dimensions, __set_grid_dimensions,
+                             __del_grid_dimensions)
+
+
 class AMR1DData(AMRData, GridPropertiesMixin):
     _spatial = False
     def __init__(self, pf, fields, **kwargs):


--- a/yt/utilities/_amr_utils/misc_utilities.pyx	Fri Jul 29 15:52:48 2011 -0400
+++ b/yt/utilities/_amr_utils/misc_utilities.pyx	Fri Jul 29 18:31:52 2011 -0400
@@ -73,3 +73,38 @@
                 break
         if inside == 1: mask[i] = 1
         else: mask[i] = 0
+
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
+def find_values_at_point(np.ndarray[np.float64_t, ndim=1] point,
+                         np.ndarray[np.float64_t, ndim=2] left_edges,
+                         np.ndarray[np.float64_t, ndim=2] right_edges,
+                         np.ndarray[np.int32_t, ndim=2] dimensions,
+                         field_names, grid_objects):
+    # This iterates in order, first to last, and then returns with the first
+    # one in which the point is located; this means if you order from highest
+    # level to lowest, you will find the correct grid without consulting child
+    # masking.  Note also that we will do a few relatively slow operations on
+    # strings and whatnot, but they should not be terribly slow.
+    cdef int ind[3], gi, fi
+    cdef int nf = len(field_names)
+    cdef np.float64_t dds
+    cdef np.ndarray[np.float64_t, ndim=3] field
+    cdef np.ndarray[np.float64_t, ndim=1] rv = np.zeros(nf, dtype='float64')
+    for gi in range(left_edges.shape[0]):
+        if not ((left_edges[gi,0] < point[0] < right_edges[gi,0])
+            and (left_edges[gi,1] < point[1] < right_edges[gi,1])
+            and (left_edges[gi,2] < point[2] < right_edges[gi,2])):
+            continue
+        # We found our grid!
+        for fi in range(3):
+            dds = ((right_edges[gi,fi] - left_edges[gi,fi])/
+                   (<np.float64_t> dimensions[gi,fi]))
+            ind[fi] = <int> ((point[fi] - left_edges[gi,fi])/dds)
+        grid = grid_objects[gi]
+        for fi in range(nf):
+            field = grid[field_names[fi]]
+            rv[fi] = field[ind[0], ind[1], ind[2]]
+        return rv
+    raise KeyError

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list