[yt-svn] commit/yt: 4 new changesets

Bitbucket commits-noreply at bitbucket.org
Tue Nov 27 02:40:21 PST 2012


4 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/d85812546e5d/
changeset:   d85812546e5d
branch:      yt
user:        jzuhone
date:        2012-11-24 05:28:14
summary:     1) Adding CICSample_3, which performs the reverse operation of CICDeposit_3. 1st-order interpolation of values on the grid to particle positions. Also added a test which interpolates the grid coordinates to the particle positions. Since the coordinates vary linearly, the interpolation and the actual value of the particle coordinate should be identical in this case.

2) Added a couple new fluid operators for the beta model and the NFW model, common fitting functions for galaxy cluster gas profiles and dark matter halo profiles.
affected #:  3 files

diff -r 1ea61855c847d65670ceb8354c2803d891ecf400 -r d85812546e5d1e208dc72745f61ad78323d4ff63 yt/utilities/initial_conditions.py
--- a/yt/utilities/initial_conditions.py
+++ b/yt/utilities/initial_conditions.py
@@ -67,6 +67,47 @@
             val = ((r[ind] - cr2) / (r2 - cr2))**0.5 * (outer_val - inner_val)
             grid[field][ind] = val + inner_val
 
+class BetaModelSphere(FluidOperator):
+    def __init__(self, beta, core_radius, radius, center, fields):
+        self.radius = radius
+        self.center = center
+        self.fields = fields
+        self.core_radius = core_radius
+        self.beta = beta
+        
+    def __call__(self, grid, sub_select = None):
+        r = np.zeros(grid.ActiveDimensions, dtype="float64")
+        r2 = self.radius**2
+        cr2 = self.core_radius**2
+        for i, ax in enumerate("xyz"):
+            np.add(r, (grid[ax] - self.center[i])**2.0, r)            
+        ind = (r <= r2)
+        if sub_select is not None:
+            ind &= sub_select            
+        for field, core_val in self.fields.iteritems() :
+            val = core_val*(1.+r[ind]/cr2)**(-1.5*self.beta)
+            grid[field][ind] = val
+
+class NFWModelSphere(FluidOperator):
+    def __init__(self, scale_radius, radius, center, fields):
+        self.radius = radius
+        self.center = center
+        self.fields = fields
+        self.scale_radius = scale_radius
+        
+    def __call__(self, grid, sub_select = None):
+        r = np.zeros(grid.ActiveDimensions, dtype="float64")
+        for i, ax in enumerate("xyz"):
+            np.add(r, (grid[ax] - self.center[i])**2.0, r)
+        np.sqrt(r,r)
+        ind = (r <= self.radius)
+        r /= self.scale_radius
+        if sub_select is not None:
+            ind &= sub_select
+        for field, scale_val in self.fields.iteritems() :
+            val = scale_val/(r[ind]*(1.+r[ind])**2)
+            grid[field][ind] = val
+            
 class RandomFluctuation(FluidOperator):
     def __init__(self, fields):
         self.fields = fields


diff -r 1ea61855c847d65670ceb8354c2803d891ecf400 -r d85812546e5d1e208dc72745f61ad78323d4ff63 yt/utilities/lib/CICDeposit.pyx
--- a/yt/utilities/lib/CICDeposit.pyx
+++ b/yt/utilities/lib/CICDeposit.pyx
@@ -117,6 +117,63 @@
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
+def CICSample_3(np.ndarray[np.float64_t, ndim=1] posx,
+                np.ndarray[np.float64_t, ndim=1] posy,
+                np.ndarray[np.float64_t, ndim=1] posz,
+                np.ndarray[np.float64_t, ndim=1] sample,
+                np.int64_t npositions,
+                np.ndarray[np.float64_t, ndim=3] field,
+                np.ndarray[np.float64_t, ndim=1] leftEdge,
+                np.ndarray[np.int32_t, ndim=1] gridDimension,
+                np.float64_t cellSize):
+    
+    cdef int i1, j1, k1, n
+    cdef double xpos, ypos, zpos
+    cdef double fact, edge0, edge1, edge2
+    cdef double le0, le1, le2
+    cdef float dx, dy, dz, dx2, dy2, dz2
+    
+    edge0 = (<float> gridDimension[0]) - 0.5001
+    edge1 = (<float> gridDimension[1]) - 0.5001
+    edge2 = (<float> gridDimension[2]) - 0.5001
+    fact = 1.0 / cellSize
+    
+    le0 = leftEdge[0] 
+    le1 = leftEdge[1] 
+    le2 = leftEdge[2] 
+                                                    
+    for n in range(npositions):
+        
+        # Compute the position of the central cell
+        xpos = fmin(fmax((posx[n] - le0)*fact, 0.5001), edge0)
+        ypos = fmin(fmax((posy[n] - le1)*fact, 0.5001), edge1)
+        zpos = fmin(fmax((posz[n] - le2)*fact, 0.5001), edge2)
+        
+        i1  = <int> (xpos + 0.5)
+        j1  = <int> (ypos + 0.5)
+        k1  = <int> (zpos + 0.5)
+        
+        # Compute the weights
+        dx = (<float> i1) + 0.5 - xpos
+        dy = (<float> j1) + 0.5 - ypos
+        dz = (<float> k1) + 0.5 - zpos
+        dx2 =  1.0 - dx
+        dy2 =  1.0 - dy
+        dz2 =  1.0 - dz
+
+        # Interpolate from field onto the particle
+        sample[n] = (field[i1-1,j1-1,k1-1] * dx  * dy  * dz +
+                     field[i1  ,j1-1,k1-1] * dx2 * dy  * dz +
+                     field[i1-1,j1  ,k1-1] * dx  * dy2 * dz +
+                     field[i1  ,j1  ,k1-1] * dx2 * dy2 * dz +
+                     field[i1-1,j1-1,k1  ] * dx  * dy  * dz2 +
+                     field[i1  ,j1-1,k1  ] * dx2 * dy  * dz2 +
+                     field[i1-1,j1  ,k1  ] * dx  * dy2 * dz2 +
+                     field[i1  ,j1  ,k1  ] * dx2 * dy2 * dz2)
+                                                                                                                        
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
 def assign_particles_to_cells(np.ndarray[np.int32_t, ndim=1] levels, #for cells
                               np.ndarray[np.float32_t, ndim=2] left_edges, #many cells
                               np.ndarray[np.float32_t, ndim=2] right_edges,


diff -r 1ea61855c847d65670ceb8354c2803d891ecf400 -r d85812546e5d1e208dc72745f61ad78323d4ff63 yt/utilities/lib/tests/test_sample.py
--- /dev/null
+++ b/yt/utilities/lib/tests/test_sample.py
@@ -0,0 +1,42 @@
+import numpy as np
+
+from yt.testing import *
+from yt.utilities.lib import CICSample_3
+
+def setup():
+    pass
+
+def test_sample() :
+
+    grid = {}
+
+    dims = np.array([64,64,64], dtype='int32')
+    
+    inds = np.indices(dims)
+    grid["x"] = inds[0] + 0.5
+    grid["y"] = inds[1] + 0.5
+    grid["z"] = inds[2] + 0.5
+
+    num_particles = np.int64(1000)
+    
+    xp = np.random.uniform(low=1.0, high=63.0, size=num_particles)
+    yp = np.random.uniform(low=1.0, high=63.0, size=num_particles)
+    zp = np.random.uniform(low=1.0, high=63.0, size=num_particles)
+
+    xfield = np.zeros((num_particles))
+    yfield = np.zeros((num_particles))
+    zfield = np.zeros((num_particles))
+
+    dx = 1.
+    le = np.zeros((3))
+    
+    CICSample_3(xp,yp,zp,xfield,num_particles,grid["x"],
+                le,dims,dx)
+    CICSample_3(xp,yp,zp,yfield,num_particles,grid["y"],
+                le,dims,dx)
+    CICSample_3(xp,yp,zp,zfield,num_particles,grid["z"],
+                le,dims,dx)
+
+    assert_allclose(xp,xfield)
+    assert_allclose(yp,yfield)
+    assert_allclose(zp,zfield)



https://bitbucket.org/yt_analysis/yt/changeset/c1d3b872cec6/
changeset:   c1d3b872cec6
branch:      yt
user:        jzuhone
date:        2012-11-26 23:56:23
summary:     Getting types consistent with each other and using fclip
affected #:  1 file

diff -r d85812546e5d1e208dc72745f61ad78323d4ff63 -r c1d3b872cec6e7673aed0f699576a9522d028add yt/utilities/lib/CICDeposit.pyx
--- a/yt/utilities/lib/CICDeposit.pyx
+++ b/yt/utilities/lib/CICDeposit.pyx
@@ -128,14 +128,14 @@
                 np.float64_t cellSize):
     
     cdef int i1, j1, k1, n
-    cdef double xpos, ypos, zpos
-    cdef double fact, edge0, edge1, edge2
-    cdef double le0, le1, le2
-    cdef float dx, dy, dz, dx2, dy2, dz2
+    cdef np.float64_t xpos, ypos, zpos
+    cdef np.float64_t fact, edge0, edge1, edge2
+    cdef np.float64_t le0, le1, le2
+    cdef np.float64_t dx, dy, dz, dx2, dy2, dz2
     
-    edge0 = (<float> gridDimension[0]) - 0.5001
-    edge1 = (<float> gridDimension[1]) - 0.5001
-    edge2 = (<float> gridDimension[2]) - 0.5001
+    edge0 = (<np.float64_t> gridDimension[0]) - 0.5001
+    edge1 = (<np.float64_t> gridDimension[1]) - 0.5001
+    edge2 = (<np.float64_t> gridDimension[2]) - 0.5001
     fact = 1.0 / cellSize
     
     le0 = leftEdge[0] 
@@ -145,10 +145,10 @@
     for n in range(npositions):
         
         # Compute the position of the central cell
-        xpos = fmin(fmax((posx[n] - le0)*fact, 0.5001), edge0)
-        ypos = fmin(fmax((posy[n] - le1)*fact, 0.5001), edge1)
-        zpos = fmin(fmax((posz[n] - le2)*fact, 0.5001), edge2)
-        
+	xpos = fclip((posx[n] - le0)*fact, 0.5001, edge0)
+	ypos = fclip((posy[n] - le1)*fact, 0.5001, edge1)
+	zpos = fclip((posz[n] - le2)*fact, 0.5001, edge2)
+
         i1  = <int> (xpos + 0.5)
         j1  = <int> (ypos + 0.5)
         k1  = <int> (zpos + 0.5)



https://bitbucket.org/yt_analysis/yt/changeset/523b01bbce78/
changeset:   523b01bbce78
branch:      yt
user:        jzuhone
date:        2012-11-27 00:01:53
summary:     Fixing tabs
affected #:  1 file

diff -r c1d3b872cec6e7673aed0f699576a9522d028add -r 523b01bbce78c6c93538339fb901ad245dc60295 yt/utilities/lib/CICDeposit.pyx
--- a/yt/utilities/lib/CICDeposit.pyx
+++ b/yt/utilities/lib/CICDeposit.pyx
@@ -143,11 +143,11 @@
     le2 = leftEdge[2] 
                                                     
     for n in range(npositions):
-        
+
         # Compute the position of the central cell
-	xpos = fclip((posx[n] - le0)*fact, 0.5001, edge0)
-	ypos = fclip((posy[n] - le1)*fact, 0.5001, edge1)
-	zpos = fclip((posz[n] - le2)*fact, 0.5001, edge2)
+        xpos = fclip((posx[n] - le0)*fact, 0.5001, edge0)
+        ypos = fclip((posy[n] - le1)*fact, 0.5001, edge1)
+        zpos = fclip((posz[n] - le2)*fact, 0.5001, edge2)
 
         i1  = <int> (xpos + 0.5)
         j1  = <int> (ypos + 0.5)



https://bitbucket.org/yt_analysis/yt/changeset/4a6750aa4709/
changeset:   4a6750aa4709
branch:      yt
user:        MatthewTurk
date:        2012-11-27 11:40:19
summary:     Merged in jzuhone/yt (pull request #347)
affected #:  3 files

diff -r bd0ac35d628e271f53e041fa253d79af12b3ae0e -r 4a6750aa470968444770411d1dce3b1d10b77a16 yt/utilities/initial_conditions.py
--- a/yt/utilities/initial_conditions.py
+++ b/yt/utilities/initial_conditions.py
@@ -67,6 +67,47 @@
             val = ((r[ind] - cr2) / (r2 - cr2))**0.5 * (outer_val - inner_val)
             grid[field][ind] = val + inner_val
 
+class BetaModelSphere(FluidOperator):
+    def __init__(self, beta, core_radius, radius, center, fields):
+        self.radius = radius
+        self.center = center
+        self.fields = fields
+        self.core_radius = core_radius
+        self.beta = beta
+        
+    def __call__(self, grid, sub_select = None):
+        r = np.zeros(grid.ActiveDimensions, dtype="float64")
+        r2 = self.radius**2
+        cr2 = self.core_radius**2
+        for i, ax in enumerate("xyz"):
+            np.add(r, (grid[ax] - self.center[i])**2.0, r)            
+        ind = (r <= r2)
+        if sub_select is not None:
+            ind &= sub_select            
+        for field, core_val in self.fields.iteritems() :
+            val = core_val*(1.+r[ind]/cr2)**(-1.5*self.beta)
+            grid[field][ind] = val
+
+class NFWModelSphere(FluidOperator):
+    def __init__(self, scale_radius, radius, center, fields):
+        self.radius = radius
+        self.center = center
+        self.fields = fields
+        self.scale_radius = scale_radius
+        
+    def __call__(self, grid, sub_select = None):
+        r = np.zeros(grid.ActiveDimensions, dtype="float64")
+        for i, ax in enumerate("xyz"):
+            np.add(r, (grid[ax] - self.center[i])**2.0, r)
+        np.sqrt(r,r)
+        ind = (r <= self.radius)
+        r /= self.scale_radius
+        if sub_select is not None:
+            ind &= sub_select
+        for field, scale_val in self.fields.iteritems() :
+            val = scale_val/(r[ind]*(1.+r[ind])**2)
+            grid[field][ind] = val
+            
 class RandomFluctuation(FluidOperator):
     def __init__(self, fields):
         self.fields = fields


diff -r bd0ac35d628e271f53e041fa253d79af12b3ae0e -r 4a6750aa470968444770411d1dce3b1d10b77a16 yt/utilities/lib/CICDeposit.pyx
--- a/yt/utilities/lib/CICDeposit.pyx
+++ b/yt/utilities/lib/CICDeposit.pyx
@@ -117,6 +117,63 @@
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
+def CICSample_3(np.ndarray[np.float64_t, ndim=1] posx,
+                np.ndarray[np.float64_t, ndim=1] posy,
+                np.ndarray[np.float64_t, ndim=1] posz,
+                np.ndarray[np.float64_t, ndim=1] sample,
+                np.int64_t npositions,
+                np.ndarray[np.float64_t, ndim=3] field,
+                np.ndarray[np.float64_t, ndim=1] leftEdge,
+                np.ndarray[np.int32_t, ndim=1] gridDimension,
+                np.float64_t cellSize):
+    
+    cdef int i1, j1, k1, n
+    cdef np.float64_t xpos, ypos, zpos
+    cdef np.float64_t fact, edge0, edge1, edge2
+    cdef np.float64_t le0, le1, le2
+    cdef np.float64_t dx, dy, dz, dx2, dy2, dz2
+    
+    edge0 = (<np.float64_t> gridDimension[0]) - 0.5001
+    edge1 = (<np.float64_t> gridDimension[1]) - 0.5001
+    edge2 = (<np.float64_t> gridDimension[2]) - 0.5001
+    fact = 1.0 / cellSize
+    
+    le0 = leftEdge[0] 
+    le1 = leftEdge[1] 
+    le2 = leftEdge[2] 
+                                                    
+    for n in range(npositions):
+
+        # Compute the position of the central cell
+        xpos = fclip((posx[n] - le0)*fact, 0.5001, edge0)
+        ypos = fclip((posy[n] - le1)*fact, 0.5001, edge1)
+        zpos = fclip((posz[n] - le2)*fact, 0.5001, edge2)
+
+        i1  = <int> (xpos + 0.5)
+        j1  = <int> (ypos + 0.5)
+        k1  = <int> (zpos + 0.5)
+        
+        # Compute the weights
+        dx = (<float> i1) + 0.5 - xpos
+        dy = (<float> j1) + 0.5 - ypos
+        dz = (<float> k1) + 0.5 - zpos
+        dx2 =  1.0 - dx
+        dy2 =  1.0 - dy
+        dz2 =  1.0 - dz
+
+        # Interpolate from field onto the particle
+        sample[n] = (field[i1-1,j1-1,k1-1] * dx  * dy  * dz +
+                     field[i1  ,j1-1,k1-1] * dx2 * dy  * dz +
+                     field[i1-1,j1  ,k1-1] * dx  * dy2 * dz +
+                     field[i1  ,j1  ,k1-1] * dx2 * dy2 * dz +
+                     field[i1-1,j1-1,k1  ] * dx  * dy  * dz2 +
+                     field[i1  ,j1-1,k1  ] * dx2 * dy  * dz2 +
+                     field[i1-1,j1  ,k1  ] * dx  * dy2 * dz2 +
+                     field[i1  ,j1  ,k1  ] * dx2 * dy2 * dz2)
+                                                                                                                        
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
 def assign_particles_to_cells(np.ndarray[np.int32_t, ndim=1] levels, #for cells
                               np.ndarray[np.float32_t, ndim=2] left_edges, #many cells
                               np.ndarray[np.float32_t, ndim=2] right_edges,


diff -r bd0ac35d628e271f53e041fa253d79af12b3ae0e -r 4a6750aa470968444770411d1dce3b1d10b77a16 yt/utilities/lib/tests/test_sample.py
--- /dev/null
+++ b/yt/utilities/lib/tests/test_sample.py
@@ -0,0 +1,42 @@
+import numpy as np
+
+from yt.testing import *
+from yt.utilities.lib import CICSample_3
+
+def setup():
+    pass
+
+def test_sample() :
+
+    grid = {}
+
+    dims = np.array([64,64,64], dtype='int32')
+    
+    inds = np.indices(dims)
+    grid["x"] = inds[0] + 0.5
+    grid["y"] = inds[1] + 0.5
+    grid["z"] = inds[2] + 0.5
+
+    num_particles = np.int64(1000)
+    
+    xp = np.random.uniform(low=1.0, high=63.0, size=num_particles)
+    yp = np.random.uniform(low=1.0, high=63.0, size=num_particles)
+    zp = np.random.uniform(low=1.0, high=63.0, size=num_particles)
+
+    xfield = np.zeros((num_particles))
+    yfield = np.zeros((num_particles))
+    zfield = np.zeros((num_particles))
+
+    dx = 1.
+    le = np.zeros((3))
+    
+    CICSample_3(xp,yp,zp,xfield,num_particles,grid["x"],
+                le,dims,dx)
+    CICSample_3(xp,yp,zp,yfield,num_particles,grid["y"],
+                le,dims,dx)
+    CICSample_3(xp,yp,zp,zfield,num_particles,grid["z"],
+                le,dims,dx)
+
+    assert_allclose(xp,xfield)
+    assert_allclose(yp,yfield)
+    assert_allclose(zp,zfield)

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