[Yt-svn] commit/yt: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Wed Apr 13 13:23:48 PDT 2011


2 new changesets in yt:

http://bitbucket.org/yt_analysis/yt/changeset/b5abc4b5d65c/
changeset:   r4122:b5abc4b5d65c
branch:      yt
user:        sskory
date:        2011-04-13 22:02:25
summary:     Adding a hierarchy method to quickly and easily get a field value at
a given coordinate.
affected #:  1 file (1.4 KB)

--- a/yt/data_objects/object_finding_mixin.py	Wed Apr 13 15:42:28 2011 -0400
+++ b/yt/data_objects/object_finding_mixin.py	Wed Apr 13 14:02:25 2011 -0600
@@ -107,6 +107,44 @@
         ind = na.where(mask == 1)
         return self.grids[ind], ind
 
+    def find_field_value_at_point(self, fields, coord):
+        r"""Find the value of fields at a point.
+        
+        Returns the values [field1, field2,...] of the fields at the given
+        (x,y,z) point. Returns a list of field values in the same order
+        as the input *fields*.
+        
+        Parameters
+        ---------
+        fields : string or list of strings
+            The field(s) that will be returned.
+        
+        coord : list or array of floats
+            The location for which field values will be returned.
+        
+        Examples
+        --------
+        >>> pf.h.find_field_value_at_point(['Density', 'Temperature'],
+            [0.4, 0.3, 0.8])
+        [2.1489e-24, 1.23843e4]
+        """
+        # Get the most-refined grid at this coordinate.
+        this = self.find_point(coord)[0][-1]
+        cellwidth = (this.RightEdge - this.LeftEdge) / this.ActiveDimensions
+        mark = 0
+        last = 1
+        # Find the index for the cell containing this point.
+        for dim in xrange(len(coord)).__reversed__():
+            temp = (coord[dim] - this.LeftEdge[dim]) / cellwidth[dim]
+            mark += int(temp) * last
+            last *= this.ActiveDimensions[dim]
+        out = []
+        fields = na.atleast_1d(fields)
+        # Pull out the values and add it to the out list.
+        for field in fields:
+            out.append(this[field].flatten()[mark])
+        return out
+
     def find_slice_grids(self, coord, axis):
         """
         Returns the (objects, indices) of grids that a slice intersects along


http://bitbucket.org/yt_analysis/yt/changeset/62f61aca4a45/
changeset:   r4123:62f61aca4a45
branch:      yt
user:        sskory
date:        2011-04-13 22:22:21
summary:     Fixing up find_field_value_at_point.
affected #:  1 file (73 bytes)

--- a/yt/data_objects/object_finding_mixin.py	Wed Apr 13 14:02:25 2011 -0600
+++ b/yt/data_objects/object_finding_mixin.py	Wed Apr 13 14:22:21 2011 -0600
@@ -131,18 +131,15 @@
         # Get the most-refined grid at this coordinate.
         this = self.find_point(coord)[0][-1]
         cellwidth = (this.RightEdge - this.LeftEdge) / this.ActiveDimensions
-        mark = 0
-        last = 1
+        mark = na.zeros(3).astype('int')
         # Find the index for the cell containing this point.
-        for dim in xrange(len(coord)).__reversed__():
-            temp = (coord[dim] - this.LeftEdge[dim]) / cellwidth[dim]
-            mark += int(temp) * last
-            last *= this.ActiveDimensions[dim]
+        for dim in xrange(len(coord)):
+            mark[dim] = int((coord[dim] - this.LeftEdge[dim]) / cellwidth[dim])
         out = []
-        fields = na.atleast_1d(fields)
+        fields = ensure_list(fields)
         # Pull out the values and add it to the out list.
         for field in fields:
-            out.append(this[field].flatten()[mark])
+            out.append(this[field][mark[0], mark[1], mark[2]])
         return out
 
     def find_slice_grids(self, coord, axis):

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