[yt-svn] commit/yt: MatthewTurk: Adding a sample_values_at_positions function. This accepts an array, the
Bitbucket
commits-noreply at bitbucket.org
Thu Feb 9 09:16:25 PST 2012
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/changeset/7e23090f3d87/
changeset: 7e23090f3d87
branch: yt
user: MatthewTurk
date: 2012-02-09 14:24:18
summary: Adding a sample_values_at_positions function. This accepts an array, the
left/right edges of that array, and a set of x,y,z positions. It returns the
values at those positions.
affected #: 1 file
diff -r a87f40c55cfb316027d2e013e66ca21d6d8d384d -r 7e23090f3d87d6b1b18dcf55a344596b75812de8 yt/utilities/_amr_utils/CICDeposit.pyx
--- a/yt/utilities/_amr_utils/CICDeposit.pyx
+++ b/yt/utilities/_amr_utils/CICDeposit.pyx
@@ -78,3 +78,32 @@
field[i1 ,j1-1,k1 ] += mass[n] * dx2 * dy * dz2
field[i1-1,j1 ,k1 ] += mass[n] * dx * dy2 * dz2
field[i1 ,j1 ,k1 ] += mass[n] * dx2 * dy2 * dz2
+
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
+def sample_field_at_positions(np.ndarray[np.float64_t, ndim=3] arr,
+ np.ndarray[np.float64_t, ndim=1] left_edge,
+ np.ndarray[np.float64_t, ndim=1] right_edge,
+ np.ndarray[np.float64_t, ndim=1] pos_x,
+ np.ndarray[np.float64_t, ndim=1] pos_y,
+ np.ndarray[np.float64_t, ndim=1] pos_z):
+ cdef np.float64_t idds[3], pp[3]
+ cdef int dims[3], npart, ind[3]
+ cdef int i, j
+ npart = pos_x.shape[0]
+ cdef np.ndarray[np.float64_t, ndim=1] sample
+ sample = np.zeros(npart, dtype='float64')
+ for i in range(3):
+ dims[i] = arr.shape[i]
+ idds[i] = (<np.float64_t> dims[i]) / (right_edge[i] - left_edge[i])
+ for i in range(npart):
+ if not ((left_edge[0] <= pos_x[i] <= right_edge[0]) and
+ (left_edge[1] <= pos_y[i] <= right_edge[1]) and
+ (left_edge[2] <= pos_z[i] <= right_edge[2])):
+ continue
+ ind[0] = <int> ((pos_x[i] - left_edge[0]) * idds[0])
+ ind[1] = <int> ((pos_y[i] - left_edge[1]) * idds[1])
+ ind[2] = <int> ((pos_z[i] - left_edge[2]) * idds[2])
+ sample[i] = arr[ind[0], ind[1], ind[2]]
+ return sample
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