[yt-svn] commit/yt: 6 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Oct 12 13:01:02 PDT 2012
6 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/1b3aa8af97c7/
changeset: 1b3aa8af97c7
branch: yt
user: MatthewTurk
date: 2012-10-12 01:25:15
summary: Adding tests for the Profiles. I believe this covers averaging, end
collection, non-end collection, and unweighted addition.
affected #: 2 files
diff -r 71fc69a95b0d9b68723ebec67a7e4684f9eab725 -r 1b3aa8af97c7138944e1141c4a23108b2c2d11af yt/data_objects/tests/test_profiles.py
--- /dev/null
+++ b/yt/data_objects/tests/test_profiles.py
@@ -0,0 +1,74 @@
+from yt.testing import *
+from yt.data_objects.profiles import \
+ BinnedProfile1D, BinnedProfile2D, BinnedProfile3D
+
+_fields = ("Density", "Temperature", "Dinosaurs", "Tribbles")
+
+def test_profiles():
+ pf = fake_random_pf(64, nprocs = 8, fields = _fields)
+ nv = pf.domain_dimensions.prod()
+ dd = pf.h.all_data()
+ (rmi, rma), (tmi, tma), (dmi, dma) = dd.quantities["Extrema"](
+ ["Density", "Temperature", "Dinosaurs"])
+ rt, tt, dt = dd.quantities["TotalQuantity"](
+ ["Density", "Temperature", "Dinosaurs"])
+ # First we look at the
+ for nb in [8, 16, 32, 64]:
+ for lr in [True, False]:
+ # We log all the fields or don't log 'em all. No need to do them
+ # individually.
+ for lf in [True, False]:
+ # We have the min and the max, but to avoid cutting them off
+ # since we aren't doing end-collect, we cut a bit off the edges
+ for ec, e1, e2 in [(False, 0.9, 1.1), (True, 1.0, 1.0)]:
+ p1d = BinnedProfile1D(dd,
+ nb, "Density", rmi*e1, rma*e2, lf,
+ lr, end_collect=ec)
+ p1d.add_fields(["Ones", "Temperature"], weight=None)
+ yield assert_equal, p1d["Ones"].sum(), nv
+ yield assert_rel_equal, tt, p1d["Temperature"].sum(), 7
+
+ p2d = BinnedProfile2D(dd,
+ nb, "Density", rmi*e1, rma*e2, lf,
+ nb, "Temperature", tmi*e1, tma*e2, lf,
+ lr, end_collect=ec)
+ p2d.add_fields(["Ones", "Temperature"], weight=None)
+ yield assert_equal, p2d["Ones"].sum(), nv
+ yield assert_rel_equal, tt, p2d["Temperature"].sum(), 7
+
+ p3d = BinnedProfile3D(dd,
+ nb, "Density", rmi*e1, rma*e2, lf,
+ nb, "Temperature", tmi*e1, tma*e2, lf,
+ nb, "Dinosaurs", dmi*e1, dma*e2, lf,
+ lr, end_collect=ec)
+ p3d.add_fields(["Ones", "Temperature"], weight=None)
+ yield assert_equal, p3d["Ones"].sum(), nv
+ yield assert_rel_equal, tt, p3d["Temperature"].sum(), 7
+
+ p1d = BinnedProfile1D(dd, nb, "x", 0.0, 1.0, log_space=False)
+ p1d.add_fields("Ones", weight=None)
+ av = nv / nb
+ yield assert_equal, p1d["Ones"][:-1], np.ones(nb)*av
+ # We re-bin ones with a weight now
+ p1d.add_fields(["Ones"], weight="Temperature")
+ yield assert_equal, p1d["Ones"][:-1], np.ones(nb)
+
+ p2d = BinnedProfile2D(dd, nb, "x", 0.0, 1.0, False,
+ nb, "y", 0.0, 1.0, False)
+ p2d.add_fields("Ones", weight=None)
+ av = nv / nb**2
+ yield assert_equal, p2d["Ones"][:-1,:-1], np.ones((nb, nb))*av
+ # We re-bin ones with a weight now
+ p2d.add_fields(["Ones"], weight="Temperature")
+ yield assert_equal, p2d["Ones"][:-1,:-1], np.ones((nb, nb))
+
+ p3d = BinnedProfile3D(dd, nb, "x", 0.0, 1.0, False,
+ nb, "y", 0.0, 1.0, False,
+ nb, "z", 0.0, 1.0, False)
+ p3d.add_fields("Ones", weight=None)
+ av = nv / nb**3
+ yield assert_equal, p3d["Ones"][:-1,:-1,:-1], np.ones((nb, nb, nb))*av
+ # We re-bin ones with a weight now
+ p3d.add_fields(["Ones"], weight="Temperature")
+ yield assert_equal, p3d["Ones"][:-1,:-1,:-1], np.ones((nb,nb,nb))
+
diff -r 71fc69a95b0d9b68723ebec67a7e4684f9eab725 -r 1b3aa8af97c7138944e1141c4a23108b2c2d11af yt/testing.py
--- a/yt/testing.py
+++ b/yt/testing.py
@@ -24,7 +24,10 @@
import numpy as np
from yt.funcs import *
-from numpy.testing import assert_array_equal
+from numpy.testing import assert_array_equal, assert_equal, assert_almost_equal
+
+def assert_rel_equal(a1, a2, decimels):
+ return assert_almost_equal(a1/a2, 1.0, decimels)
def amrspace(extent, levels=7, cells=8):
"""Creates two numpy arrays representing the left and right bounds of
@@ -127,7 +130,8 @@
return left, right, level
-def fake_random_pf(ndims, peak_value = 1.0, fields = ("Density",), negative = False):
+def fake_random_pf(ndims, peak_value = 1.0, fields = ("Density",),
+ negative = False, nprocs = 1):
from yt.frontends.stream.api import load_uniform_grid
if not iterable(ndims):
ndims = [ndims, ndims, ndims]
@@ -139,5 +143,5 @@
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)
+ ug = load_uniform_grid(data, ndims, 1.0, nprocs = nprocs)
return ug
https://bitbucket.org/yt_analysis/yt/changeset/661eefd928c8/
changeset: 661eefd928c8
branch: yt
user: MatthewTurk
date: 2012-10-12 02:48:48
summary: Adding first set of tests of projections
affected #: 1 file
diff -r 1b3aa8af97c7138944e1141c4a23108b2c2d11af -r 661eefd928c8112d10241a5c6b8b5872ceabf427 yt/data_objects/tests/test_projection.py
--- /dev/null
+++ b/yt/data_objects/tests/test_projection.py
@@ -0,0 +1,28 @@
+from yt.testing import *
+from yt.data_objects.profiles import \
+ BinnedProfile1D, BinnedProfile2D, BinnedProfile3D
+
+def test_projection():
+ for nprocs in [1, 8]:
+ # We want to test both 1 proc and 8 procs, to make sure that
+ # parallelism isn't broken
+ pf = fake_random_pf(64, nprocs = 1)
+ dims = pf.domain_dimensions
+ xn, yn, zn = pf.domain_dimensions
+ xi, yi, zi = pf.domain_left_edge + 1.0/(pf.domain_dimensions * 2)
+ xf, yf, zf = pf.domain_right_edge - 1.0/(pf.domain_dimensions * 2)
+ coords = np.mgrid[xi:xf:xn*1j, yi:yf:yn*1j, zi:zf:zn*1j]
+ uc = [np.unique(c) for c in coords]
+ # Some simple projection tests with single grids
+ for ax in [0, 1, 2]:
+ xax = x_dict[ax]
+ yax = y_dict[ax]
+ for wf in [None, "Density"]:
+ proj = pf.h.proj(ax, "Ones", weight_field = wf)
+ yield assert_equal, proj["Ones"].sum(), proj["Ones"].size
+ yield assert_equal, proj["Ones"].min(), 1.0
+ yield assert_equal, proj["Ones"].max(), 1.0
+ yield assert_equal, np.unique(proj["px"]), uc[xax]
+ yield assert_equal, np.unique(proj["py"]), uc[yax]
+ yield assert_equal, np.unique(proj["pdx"]), 1.0/(dims[xax]*2.0)
+ yield assert_equal, np.unique(proj["pdy"]), 1.0/(dims[yax]*2.0)
https://bitbucket.org/yt_analysis/yt/changeset/7914345a91cc/
changeset: 7914345a91cc
branch: yt
user: MatthewTurk
date: 2012-10-12 03:15:50
summary: Adding a couple more tests for projections to verify Density is correctly
projected.
affected #: 1 file
diff -r 661eefd928c8112d10241a5c6b8b5872ceabf427 -r 7914345a91cc3b87fb8fb2ba60800e7e12510b2d yt/data_objects/tests/test_projection.py
--- a/yt/data_objects/tests/test_projection.py
+++ b/yt/data_objects/tests/test_projection.py
@@ -3,7 +3,7 @@
BinnedProfile1D, BinnedProfile2D, BinnedProfile3D
def test_projection():
- for nprocs in [1, 8]:
+ for nprocs in [8, 1]:
# We want to test both 1 proc and 8 procs, to make sure that
# parallelism isn't broken
pf = fake_random_pf(64, nprocs = 1)
@@ -11,14 +11,16 @@
xn, yn, zn = pf.domain_dimensions
xi, yi, zi = pf.domain_left_edge + 1.0/(pf.domain_dimensions * 2)
xf, yf, zf = pf.domain_right_edge - 1.0/(pf.domain_dimensions * 2)
+ dd = pf.h.all_data()
+ rho_tot = dd.quantities["TotalQuantity"]("Density")[0]
coords = np.mgrid[xi:xf:xn*1j, yi:yf:yn*1j, zi:zf:zn*1j]
uc = [np.unique(c) for c in coords]
# Some simple projection tests with single grids
- for ax in [0, 1, 2]:
+ for ax, an in enumerate("xyz"):
xax = x_dict[ax]
yax = y_dict[ax]
- for wf in [None, "Density"]:
- proj = pf.h.proj(ax, "Ones", weight_field = wf)
+ for wf in ["Density", None]:
+ proj = pf.h.proj(ax, ["Ones", "Density"], weight_field = wf)
yield assert_equal, proj["Ones"].sum(), proj["Ones"].size
yield assert_equal, proj["Ones"].min(), 1.0
yield assert_equal, proj["Ones"].max(), 1.0
@@ -26,3 +28,8 @@
yield assert_equal, np.unique(proj["py"]), uc[yax]
yield assert_equal, np.unique(proj["pdx"]), 1.0/(dims[xax]*2.0)
yield assert_equal, np.unique(proj["pdy"]), 1.0/(dims[yax]*2.0)
+ # wf == None
+ yield assert_equal, wf, None
+ v1 = proj["Density"].sum()
+ v2 = (dd["Density"] * dd["d%s" % an]).sum()
+ yield assert_rel_equal, v1, v2, 10
https://bitbucket.org/yt_analysis/yt/changeset/9eb577243510/
changeset: 9eb577243510
branch: yt
user: MatthewTurk
date: 2012-10-12 04:03:01
summary: Added a __withintesting option to the config to allow suppression of the
progress bars during projections. Then, turn it on inside the setup() function
for projections.
affected #: 3 files
diff -r 7914345a91cc3b87fb8fb2ba60800e7e12510b2d -r 9eb57724351006c3ca5d7af51ee1a0540fd76390 yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -38,6 +38,7 @@
inline = 'False',
numthreads = '-1',
__withinreason = 'False',
+ __withintesting = 'False',
__parallel = 'False',
__global_parallel_rank = '0',
__global_parallel_size = '1',
diff -r 7914345a91cc3b87fb8fb2ba60800e7e12510b2d -r 9eb57724351006c3ca5d7af51ee1a0540fd76390 yt/data_objects/tests/test_projection.py
--- a/yt/data_objects/tests/test_projection.py
+++ b/yt/data_objects/tests/test_projection.py
@@ -2,6 +2,10 @@
from yt.data_objects.profiles import \
BinnedProfile1D, BinnedProfile2D, BinnedProfile3D
+def setup():
+ from yt.config import ytcfg
+ ytcfg["yt","__withintesting"] = "True"
+
def test_projection():
for nprocs in [8, 1]:
# We want to test both 1 proc and 8 procs, to make sure that
diff -r 7914345a91cc3b87fb8fb2ba60800e7e12510b2d -r 9eb57724351006c3ca5d7af51ee1a0540fd76390 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -310,7 +310,8 @@
maxval = max(maxval, 1)
from yt.config import ytcfg
if ytcfg.getboolean("yt", "suppressStreamLogging") or \
- ytcfg.getboolean("yt", "ipython_notebook"):
+ ytcfg.getboolean("yt", "ipython_notebook") or \
+ ytcfg.getboolean("yt", "__withintesting"):
return DummyProgressBar()
elif ytcfg.getboolean("yt", "__withinreason"):
from yt.gui.reason.extdirect_repl import ExtProgressBar
https://bitbucket.org/yt_analysis/yt/changeset/b7aa69d03e99/
changeset: b7aa69d03e99
branch: yt
user: MatthewTurk
date: 2012-10-12 06:03:00
summary: Adding tests for covering_grid and fixing three bugs.
* The _con_args for covering_grid were out of data. This fixes pickling and
__repr__.
* dds couldn't be set correctly for going to a higher level than is present in
the dataset. Now the dds is set via refine_by and the domain dimensions.
* If nprocs > 1 in load_uniform_grid, the grid dimensions would be set to
int64, which would break covering grids.
affected #: 4 files
diff -r 9eb57724351006c3ca5d7af51ee1a0540fd76390 -r b7aa69d03e992658bbb368f75f78b619a95833d5 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -3658,7 +3658,7 @@
class AMRCoveringGridBase(AMR3DData):
_spatial = True
_type_name = "covering_grid"
- _con_args = ('level', 'left_edge', 'right_edge', 'ActiveDimensions')
+ _con_args = ('level', 'left_edge', 'ActiveDimensions')
def __init__(self, level, left_edge, dims, fields = None,
pf = None, num_ghost_zones = 0, use_pbar = True, **kwargs):
"""A 3D region with all data extracted to a single, specified
@@ -3685,8 +3685,9 @@
fields=fields, pf=pf, **kwargs)
self.left_edge = np.array(left_edge)
self.level = level
- self.dds = self.pf.h.select_grids(self.level)[0].dds.copy()
- self.ActiveDimensions = np.array(dims,dtype='int32')
+ rdx = self.pf.domain_dimensions*self.pf.refine_by**level
+ self.dds = self.pf.domain_width/rdx.astype("float64")
+ self.ActiveDimensions = np.array(dims, dtype='int32')
self.right_edge = self.left_edge + self.ActiveDimensions*self.dds
self._num_ghost_zones = num_ghost_zones
self._use_pbar = use_pbar
diff -r 9eb57724351006c3ca5d7af51ee1a0540fd76390 -r b7aa69d03e992658bbb368f75f78b619a95833d5 yt/data_objects/tests/test_covering_grid.py
--- /dev/null
+++ b/yt/data_objects/tests/test_covering_grid.py
@@ -0,0 +1,27 @@
+from yt.testing import *
+from yt.data_objects.profiles import \
+ BinnedProfile1D, BinnedProfile2D, BinnedProfile3D
+
+def setup():
+ from yt.config import ytcfg
+ ytcfg["yt","__withintesting"] = "True"
+
+def test_covering_grid():
+ # We decompose in different ways
+ for level in [0, 1, 2]:
+ for nprocs in [1, 2, 4, 8]:
+ pf = fake_random_pf(16, nprocs = nprocs)
+ dn = pf.refine_by**level
+ cg = pf.h.covering_grid(level, [0.0, 0.0, 0.0],
+ dn * pf.domain_dimensions)
+ yield assert_equal, cg["Ones"].max(), 1.0
+ yield assert_equal, cg["Ones"].min(), 1.0
+ yield assert_equal, cg["CellVolume"].sum(), pf.domain_width.prod()
+ for g in pf.h.grids:
+ di = g.get_global_startindex()
+ dd = g.ActiveDimensions
+ for i in range(dn):
+ f = cg["Density"][dn*di[0]+i:dn*(di[0]+dd[0])+i:dn,
+ dn*di[1]+i:dn*(di[1]+dd[1])+i:dn,
+ dn*di[2]+i:dn*(di[2]+dd[2])+i:dn]
+ yield assert_equal, f, g["Density"]
diff -r 9eb57724351006c3ca5d7af51ee1a0540fd76390 -r b7aa69d03e992658bbb368f75f78b619a95833d5 yt/data_objects/tests/test_projection.py
--- a/yt/data_objects/tests/test_projection.py
+++ b/yt/data_objects/tests/test_projection.py
@@ -10,7 +10,7 @@
for nprocs in [8, 1]:
# We want to test both 1 proc and 8 procs, to make sure that
# parallelism isn't broken
- pf = fake_random_pf(64, nprocs = 1)
+ pf = fake_random_pf(64, nprocs = nprocs)
dims = pf.domain_dimensions
xn, yn, zn = pf.domain_dimensions
xi, yi, zi = pf.domain_left_edge + 1.0/(pf.domain_dimensions * 2)
diff -r 9eb57724351006c3ca5d7af51ee1a0540fd76390 -r b7aa69d03e992658bbb368f75f78b619a95833d5 yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -353,7 +353,8 @@
psize = get_psize(np.array(data[key].shape), nprocs)
grid_left_edges, grid_right_edges, temp[key] = \
decompose_array(data[key], psize, bbox)
- grid_dimensions = np.array([grid.shape for grid in temp[key]])
+ grid_dimensions = np.array([grid.shape for grid in temp[key]],
+ dtype="int32")
for gid in range(nprocs):
new_data[gid] = {}
for key in temp.keys():
@@ -364,7 +365,7 @@
sfh.update({0:data})
grid_left_edges = domain_left_edge
grid_right_edges = domain_right_edge
- grid_dimensions = domain_dimensions.reshape(nprocs,3)
+ grid_dimensions = domain_dimensions.reshape(nprocs,3).astype("int32")
handler = StreamHandler(
grid_left_edges,
https://bitbucket.org/yt_analysis/yt/changeset/b0ad4da28d61/
changeset: b0ad4da28d61
branch: yt
user: MatthewTurk
date: 2012-10-12 21:59:08
summary: Merging
affected #: 2 files
diff -r b7aa69d03e992658bbb368f75f78b619a95833d5 -r b0ad4da28d6177e66558de3a9c3bbe1a3dbcfce2 yt/testing.py
--- a/yt/testing.py
+++ b/yt/testing.py
@@ -24,7 +24,9 @@
import numpy as np
from yt.funcs import *
-from numpy.testing import assert_array_equal, assert_equal, assert_almost_equal
+from numpy.testing import assert_array_equal, assert_almost_equal, \
+ assert_approx_equal, assert_array_almost_equal, assert_equal, \
+ assert_string_equal
def assert_rel_equal(a1, a2, decimels):
return assert_almost_equal(a1/a2, 1.0, decimels)
diff -r b7aa69d03e992658bbb368f75f78b619a95833d5 -r b0ad4da28d6177e66558de3a9c3bbe1a3dbcfce2 yt/utilities/tests/test_kdtrees.py
--- /dev/null
+++ b/yt/utilities/tests/test_kdtrees.py
@@ -0,0 +1,96 @@
+"""
+Unit test the kD trees in yt.
+
+Author: Stephen Skory <s at skory.us>
+Affiliation: U of Colorado
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2008-2011 Stephen Skory. 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/>.
+"""
+
+from yt.testing import *
+
+try:
+ from yt.utilities.kdtree import \
+ chainHOP_tags_dens, \
+ create_tree, fKD, find_nn_nearest_neighbors, \
+ free_tree, find_chunk_nearest_neighbors
+except ImportError:
+ mylog.debug("The Fortran kD-Tree did not import correctly.")
+
+from yt.utilities.spatial import cKDTree
+
+def setup():
+ pass
+
+def test_fortran_tree():
+ r"""This test makes sure that the fortran kdtree is finding the correct
+ nearest neighbors.
+ """
+ # Four points.
+ try:
+ fKD.pos = np.empty((3, 4), dtype='float64', order='F')
+ except NameError:
+ return
+ # Make four points by hand that, in particular, will allow us to test
+ # the periodicity of the kdtree.
+ points = np.array([0.01, 0.5, 0.98, 0.99])
+ fKD.pos[0, :] = points
+ fKD.pos[1, :] = points
+ fKD.pos[2, :] = points
+ fKD.qv = np.empty(3, dtype='float64')
+ fKD.dist = np.empty(4, dtype='float64')
+ fKD.tags = np.empty(4, dtype='int64')
+ fKD.nn = 4
+ fKD.sort = True
+ create_tree(0)
+ # Now we check to make sure that we find the correct nearest neighbors,
+ # which get stored in dist and tags.
+ fKD.qv[:] = 0.999
+ find_nn_nearest_neighbors()
+ # Fix fortran counting.
+ fKD.tags -= 1
+ # Clean up before the tests.
+ free_tree(0)
+ # What the answers should be.
+ dist = np.array([2.43e-04, 3.63e-04, 1.083e-03, 7.47003e-01])
+ tags = np.array([3, 0, 2, 1], dtype='int64')
+ assert_array_almost_equal(fKD.dist, dist)
+ assert_array_equal(fKD.tags, tags)
+
+def test_cython_tree():
+ r"""This test makes sure that the cython kdtree is finding the correct
+ nearest neighbors.
+ """
+ # Four points.
+ pos = np.empty((4, 3), dtype='float64')
+ # Make four points by hand that, in particular, will allow us to test
+ # the periodicity of the kdtree.
+ points = np.array([0.01, 0.5, 0.98, 0.99])
+ pos[:, 0] = points
+ pos[:, 1] = points
+ pos[:, 2] = points
+ kdtree = cKDTree(pos, leafsize = 2)
+ qv = np.array([0.999]*3)
+ res = kdtree.query(qv, 4, period=[1.,1.,1])
+ # What the answers should be.
+ dist = np.array([2.43e-04, 3.63e-04, 1.083e-03, 7.47003e-01])
+ tags = np.array([3, 0, 2, 1], dtype='int64')
+ assert_array_almost_equal(res[0], dist)
+ assert_array_equal(res[1], tags)
+
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