[yt-svn] commit/yt: 4 new changesets
Bitbucket
commits-noreply at bitbucket.org
Wed Sep 26 08:26:43 PDT 2012
4 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/2fcc03b82af1/
changeset: 2fcc03b82af1
branch: yt
user: MatthewTurk
date: 2012-09-26 16:45:02
summary: Porting over the test_interpolators code from 3.0
affected #: 1 file
diff -r dfe2b9787bc7b39b6a82bc904fee5d3967502c37 -r 2fcc03b82af1282e1c410add0059c492d44a7e81 yt/utilities/tests/test_interpolators.py
--- /dev/null
+++ b/yt/utilities/tests/test_interpolators.py
@@ -0,0 +1,13 @@
+import numpy as np
+from numpy.testing import assert_array_equal
+import yt.utilities.linear_interpolators as lin
+
+def setup():
+ pass
+
+
+def test_linear_interpolator():
+ random_data = np.random.random(128)
+ x = {"Random":np.mgrid[0.0:1.0:128j]}
+ ufi = lin.UnilinearFieldInterpolator(random_data, (0.0, 1.0), "Random", True)
+ assert_array_equal(ufi(x), random_data)
https://bitbucket.org/yt_analysis/yt/changeset/d71aa73bd6ac/
changeset: d71aa73bd6ac
branch: yt
user: MatthewTurk
date: 2012-09-26 16:59:53
summary: Adding bi and tri linear interpolator tests.
affected #: 1 file
diff -r 2fcc03b82af1282e1c410add0059c492d44a7e81 -r d71aa73bd6ac48fd11b21aa90656fb7ded769395 yt/utilities/tests/test_interpolators.py
--- a/yt/utilities/tests/test_interpolators.py
+++ b/yt/utilities/tests/test_interpolators.py
@@ -5,9 +5,24 @@
def setup():
pass
+def test_linear_interpolator_1d():
+ random_data = np.random.random(64)
+ fv = {'x': np.mgrid[0.0:1.0:64j]}
+ ufi = lin.UnilinearFieldInterpolator(random_data, (0.0, 1.0), "x", True)
+ assert_array_equal(ufi(fv), random_data)
-def test_linear_interpolator():
- random_data = np.random.random(128)
- x = {"Random":np.mgrid[0.0:1.0:128j]}
- ufi = lin.UnilinearFieldInterpolator(random_data, (0.0, 1.0), "Random", True)
- assert_array_equal(ufi(x), random_data)
+def test_linear_interpolator_2d():
+ random_data = np.random.random((64, 64))
+ fv = dict((ax, v) for ax, v in zip("xyz",
+ np.mgrid[0.0:1.0:64j, 0.0:1.0:64j]))
+ bfi = lin.BilinearFieldInterpolator(random_data,
+ (0.0, 1.0, 0.0, 1.0), "xy", True)
+ assert_array_equal(bfi(fv), random_data)
+
+def test_linear_interpolator_3d():
+ random_data = np.random.random((64, 64, 64))
+ fv = dict((ax, v) for ax, v in zip("xyz",
+ np.mgrid[0.0:1.0:64j, 0.0:1.0:64j, 0.0:1.0:64j]))
+ tfi = lin.TrilinearFieldInterpolator(random_data,
+ (0.0, 1.0, 0.0, 1.0, 0.0, 1.0), "xyz", True)
+ assert_array_equal(tfi(fv), random_data)
https://bitbucket.org/yt_analysis/yt/changeset/182debc46fdb/
changeset: 182debc46fdb
branch: yt
user: MatthewTurk
date: 2012-09-26 17:04:33
summary: Adding in Anthony's testing helper module
affected #: 1 file
diff -r d71aa73bd6ac48fd11b21aa90656fb7ded769395 -r 182debc46fdba2fe1aae830bfa136e7d4f68f27f yt/testing.py
--- /dev/null
+++ b/yt/testing.py
@@ -0,0 +1,127 @@
+"""Provides utility and helper functions for testing in yt.
+
+Author: Anthony Scpatz <scopatz at gmail.com>
+Affiliation: The University of Chicago
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2012 Anthony Scopatz. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+import numpy as np
+
+
+def amrspace(extent, levels=7, cells=8):
+ """Creates two numpy arrays representing the left and right bounds of
+ an AMR grid as well as an array for the AMR level of each cell.
+
+ Parameters
+ ----------
+ extent : array-like
+ This a sequence of length 2*ndims that is the bounds of each dimension.
+ For example, the 2D unit square would be given by [0.0, 1.0, 0.0, 1.0].
+ A 3D cylindrical grid may look like [0.0, 2.0, -1.0, 1.0, 0.0, 2*np.pi].
+ levels : int or sequence of ints, optional
+ This is the number of AMR refinement levels. If given as a sequence (of
+ length ndims), then each dimension will be refined down to this level.
+ All values in this array must be the same or zero. A zero valued dimension
+ indicates that this dim should not be refined. Taking the 3D cylindrical
+ example above if we don't want refine theta but want r and z at 5 we would
+ set levels=(5, 5, 0).
+ cells : int, optional
+ This is the number of cells per refinement level.
+
+ Returns
+ -------
+ left : float ndarray, shape=(npoints, ndims)
+ The left AMR grid points.
+ right : float ndarray, shape=(npoints, ndims)
+ The right AMR grid points.
+ level : int ndarray, shape=(npoints,)
+ The AMR level for each point.
+
+ Examples
+ --------
+ >>> l, r, lvl = amrspace([0.0, 2.0, 1.0, 2.0, 0.0, 3.14], levels=(3,3,0), cells=2)
+ >>> print l
+ [[ 0. 1. 0. ]
+ [ 0.25 1. 0. ]
+ [ 0. 1.125 0. ]
+ [ 0.25 1.125 0. ]
+ [ 0.5 1. 0. ]
+ [ 0. 1.25 0. ]
+ [ 0.5 1.25 0. ]
+ [ 1. 1. 0. ]
+ [ 0. 1.5 0. ]
+ [ 1. 1.5 0. ]]
+
+ """
+ extent = np.asarray(extent, dtype='f8')
+ dextent = extent[1::2] - extent[::2]
+ ndims = len(dextent)
+
+ if isinstance(levels, int):
+ minlvl = maxlvl = levels
+ levels = np.array([levels]*ndims, dtype='int32')
+ else:
+ levels = np.asarray(levels, dtype='int32')
+ minlvl = levels.min()
+ maxlvl = levels.max()
+ if minlvl != maxlvl and (minlvl != 0 or set([minlvl, maxlvl]) != set(levels)):
+ raise ValueError("all levels must have the same value or zero.")
+ dims_zero = (levels == 0)
+ dims_nonzero = ~dims_zero
+ ndims_nonzero = dims_nonzero.sum()
+
+ npoints = (cells**ndims_nonzero - 1)*maxlvl + 1
+ left = np.empty((npoints, ndims), dtype='float64')
+ right = np.empty((npoints, ndims), dtype='float64')
+ level = np.empty(npoints, dtype='int32')
+
+ # fill zero dims
+ left[:,dims_zero] = extent[::2][dims_zero]
+ right[:,dims_zero] = extent[1::2][dims_zero]
+
+ # fill non-zero dims
+ dcell = 1.0 / cells
+ left_slice = tuple([slice(extent[2*n], extent[2*n+1], extent[2*n+1]) if \
+ dims_zero[n] else slice(0.0,1.0,dcell) for n in range(ndims)])
+ right_slice = tuple([slice(extent[2*n+1], extent[2*n], -extent[2*n+1]) if \
+ dims_zero[n] else slice(dcell,1.0+dcell,dcell) for n in range(ndims)])
+ left_norm_grid = np.reshape(np.mgrid[left_slice].T.flat[ndims:], (-1, ndims))
+ lng_zero = left_norm_grid[:,dims_zero]
+ lng_nonzero = left_norm_grid[:,dims_nonzero]
+
+ right_norm_grid = np.reshape(np.mgrid[right_slice].T.flat[ndims:], (-1, ndims))
+ rng_zero = right_norm_grid[:,dims_zero]
+ rng_nonzero = right_norm_grid[:,dims_nonzero]
+
+ level[0] = maxlvl
+ left[0,:] = extent[::2]
+ right[0,dims_zero] = extent[1::2][dims_zero]
+ right[0,dims_nonzero] = (dcell**maxlvl)*dextent[dims_nonzero] + extent[::2][dims_nonzero]
+ for i, lvl in enumerate(range(maxlvl, 0, -1)):
+ start = (cells**ndims_nonzero - 1)*i + 1
+ stop = (cells**ndims_nonzero - 1)*(i+1) + 1
+ dsize = dcell**(lvl-1) * dextent[dims_nonzero]
+ level[start:stop] = lvl
+ left[start:stop,dims_zero] = lng_zero
+ left[start:stop,dims_nonzero] = lng_nonzero*dsize + extent[::2][dims_nonzero]
+ right[start:stop,dims_zero] = rng_zero
+ right[start:stop,dims_nonzero] = rng_nonzero*dsize + extent[::2][dims_nonzero]
+
+ return left, right, level
https://bitbucket.org/yt_analysis/yt/changeset/db90f5fd1742/
changeset: db90f5fd1742
branch: yt
user: MatthewTurk
date: 2012-09-26 17:20:57
summary: Adding a fake_random_pf to yt/testing.py, and starting to add some refinement
criteria.
affected #: 4 files
diff -r 182debc46fdba2fe1aae830bfa136e7d4f68f27f -r db90f5fd17420a0d36e816b82b50695358de52d1 yt/testing.py
--- a/yt/testing.py
+++ b/yt/testing.py
@@ -23,7 +23,8 @@
"""
import numpy as np
-
+from yt.funcs import *
+from numpy.testing import assert_array_equal
def amrspace(extent, levels=7, cells=8):
"""Creates two numpy arrays representing the left and right bounds of
@@ -125,3 +126,18 @@
right[start:stop,dims_nonzero] = rng_nonzero*dsize + extent[::2][dims_nonzero]
return left, right, level
+
+def fake_random_pf(ndims, peak_value = 1.0, fields = ("Density",), negative = False):
+ from yt.frontends.stream.api import load_uniform_grid
+ if not iterable(ndims):
+ ndims = [ndims, ndims, ndims]
+ else:
+ assert(len(ndims) == 3)
+ if negative:
+ offset = 0.5
+ else:
+ offset = 0.0
+ data = dict((field, (np.random.random(ndims) - offset) * peak_value)
+ for field in fields)
+ ug = load_uniform_grid(data, ndims, 1.0)
+ return ug
diff -r 182debc46fdba2fe1aae830bfa136e7d4f68f27f -r db90f5fd17420a0d36e816b82b50695358de52d1 yt/utilities/flagging_methods.py
--- /dev/null
+++ b/yt/utilities/flagging_methods.py
@@ -0,0 +1,51 @@
+"""
+Utilities for flagging zones for refinement in a dataset
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2012 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+import numpy as np # For modern purposes
+
+flagging_method_registry = {}
+
+def flag_cells(grid, methods):
+ flagged = np.zeros(grid.ActiveDimensions, dtype="bool")
+ for method in methods:
+ flagged |= method(grid)
+ return flagged
+
+class FlaggingMethod(object):
+ _skip_add = False
+ class __metaclass__(type):
+ def __init__(cls, name, b, d):
+ type.__init__(cls, name, b, d)
+ if hasattr(cls, "_type_name") and not cls._skip_add:
+ flagging_method_registry[cls._type_name] = cls
+
+class OverDensity(FlaggingMethod):
+ _type_name = "overdensity"
+ def __init__(self, over_density):
+ self.over_density = over_density
+
+ def __call__(self, pf, grid):
+ rho = grid["Density"] / (pf.refine_by**grid.Level)
+ return (rho > self.over_density)
diff -r 182debc46fdba2fe1aae830bfa136e7d4f68f27f -r db90f5fd17420a0d36e816b82b50695358de52d1 yt/utilities/tests/test_flagging_methods.py
--- /dev/null
+++ b/yt/utilities/tests/test_flagging_methods.py
@@ -0,0 +1,12 @@
+from yt.testing import *
+from yt.utilities.flagging_methods import flagging_method_registry
+
+def setup():
+ global pf
+ pf = fake_random_pf(64)
+ pf.h
+
+def test_over_density():
+ od_flag = flagging_method_registry["overdensity"](0.75)
+ criterion = (pf.h.grids[0]["Density"] > 0.75)
+ assert( np.all( od_flag(pf, pf.h.grids[0]) == criterion) )
diff -r 182debc46fdba2fe1aae830bfa136e7d4f68f27f -r db90f5fd17420a0d36e816b82b50695358de52d1 yt/utilities/tests/test_interpolators.py
--- a/yt/utilities/tests/test_interpolators.py
+++ b/yt/utilities/tests/test_interpolators.py
@@ -1,5 +1,4 @@
-import numpy as np
-from numpy.testing import assert_array_equal
+from yt.testing import *
import yt.utilities.linear_interpolators as lin
def setup():
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