[yt-svn] commit/yt: 4 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sun May 4 07:56:19 PDT 2014
4 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/6a37666d6322/
Changeset: 6a37666d6322
Branch: yt-3.0
User: xarthisius
Date: 2014-05-04 11:48:40
Summary: Remove temporary files in test_cutting_plane
Affected #: 1 file
diff -r 148e82200398be3eaec221d639b0e7d7ed6cb6e2 -r 6a37666d6322f22c8381527c658c7a6d55e9ffc1 yt/data_objects/tests/test_cutting_plane.py
--- a/yt/data_objects/tests/test_cutting_plane.py
+++ b/yt/data_objects/tests/test_cutting_plane.py
@@ -1,11 +1,13 @@
-from yt.testing import *
+from yt.testing import assert_equal, fake_random_pf
from yt.units.unit_object import Unit
import os
import tempfile
+
def setup():
from yt.config import ytcfg
- ytcfg["yt","__withintesting"] = "True"
+ ytcfg["yt", "__withintesting"] = "True"
+
def teardown_func(fns):
for fn in fns:
@@ -14,15 +16,15 @@
except OSError:
pass
+
def test_cutting_plane():
+ fns = []
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 = nprocs)
- dims = pf.domain_dimensions
- center = [0.5,0.5,0.5]
- normal = [1,1,1]
- fns = []
+ pf = fake_random_pf(64, nprocs=nprocs)
+ center = [0.5, 0.5, 0.5]
+ normal = [1, 1, 1]
cut = pf.cutting(normal, center)
yield assert_equal, cut["ones"].sum(), cut["ones"].size
yield assert_equal, cut["ones"].min(), 1.0
@@ -30,8 +32,9 @@
pw = cut.to_pw()
tmpfd, tmpname = tempfile.mkstemp(suffix='.png')
os.close(tmpfd)
- fns += pw.save(name=tmpname)
- frb = cut.to_frb((1.0,'unitary'), 64)
+ pw.save(name=tmpname)
+ fns.append(tmpname)
+ frb = cut.to_frb((1.0, 'unitary'), 64)
for cut_field in ['ones', 'density']:
fi = pf._get_field_info("unknown", cut_field)
yield assert_equal, frb[cut_field].info['data_source'], \
@@ -50,4 +53,4 @@
pf.length_unit.in_cgs()
yield assert_equal, frb[cut_field].info['center'], \
cut.center
- teardown_func(fns)
+ teardown_func(fns)
https://bitbucket.org/yt_analysis/yt/commits/3c49a831117f/
Changeset: 3c49a831117f
Branch: yt-3.0
User: xarthisius
Date: 2014-05-04 11:54:27
Summary: Remove temporary files in test_projection
Affected #: 1 file
diff -r 6a37666d6322f22c8381527c658c7a6d55e9ffc1 -r 3c49a831117f6b869f56a5463f6a1657346d48f5 yt/data_objects/tests/test_projection.py
--- a/yt/data_objects/tests/test_projection.py
+++ b/yt/data_objects/tests/test_projection.py
@@ -1,11 +1,15 @@
-from yt.testing import *
+import numpy as np
+from yt.testing import \
+ fake_random_pf, assert_equal, assert_rel_equal
from yt.units.unit_object import Unit
import os
import tempfile
+
def setup():
from yt.config import ytcfg
- ytcfg["yt","__withintesting"] = "True"
+ ytcfg["yt", "__withintesting"] = "True"
+
def teardown_func(fns):
for fn in fns:
@@ -14,15 +18,19 @@
except OSError:
pass
+
def test_projection():
+ fns = []
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 = nprocs)
+ pf = fake_random_pf(64, nprocs=nprocs)
dims = pf.domain_dimensions
xn, yn, zn = pf.domain_dimensions
- xi, yi, zi = pf.domain_left_edge.to_ndarray() + 1.0/(pf.domain_dimensions * 2)
- xf, yf, zf = pf.domain_right_edge.to_ndarray() - 1.0/(pf.domain_dimensions * 2)
+ xi, yi, zi = pf.domain_left_edge.to_ndarray() + \
+ 1.0 / (pf.domain_dimensions * 2)
+ xf, yf, zf = pf.domain_right_edge.to_ndarray() - \
+ 1.0 / (pf.domain_dimensions * 2)
dd = pf.h.all_data()
rho_tot = dd.quantities["TotalQuantity"]("density")
coords = np.mgrid[xi:xf:xn*1j, yi:yf:yn*1j, zi:zf:zn*1j]
@@ -32,8 +40,7 @@
xax = pf.coordinates.x_axis[ax]
yax = pf.coordinates.y_axis[ax]
for wf in ["density", None]:
- fns = []
- proj = pf.proj(["ones", "density"], ax, weight_field = wf)
+ proj = pf.proj(["ones", "density"], ax, 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
@@ -44,16 +51,17 @@
pw = proj.to_pw()
tmpfd, tmpname = tempfile.mkstemp(suffix='.png')
os.close(tmpfd)
- fns += pw.save(name=tmpname)
- frb = proj.to_frb((1.0,'unitary'), 64)
+ pw.save(name=tmpname)
+ fns.append(tmpname)
+ frb = proj.to_frb((1.0, 'unitary'), 64)
for proj_field in ['ones', 'density']:
fi = pf._get_field_info(proj_field)
yield assert_equal, frb[proj_field].info['data_source'], \
- proj.__str__()
+ proj.__str__()
yield assert_equal, frb[proj_field].info['axis'], \
- ax
+ ax
yield assert_equal, frb[proj_field].info['field'], \
- proj_field
+ proj_field
field_unit = Unit(fi.units)
if wf is not None:
yield assert_equal, frb[proj_field].units, \
@@ -64,22 +72,21 @@
else:
proj_unit = "cm"
if field_unit != '' and field_unit != Unit():
- proj_unit = "({0}) * {1}".format(field_unit, proj_unit)
+ proj_unit = \
+ "({0}) * {1}".format(field_unit, proj_unit)
yield assert_equal, frb[proj_field].units, \
Unit(proj_unit, registry=pf.unit_registry)
yield assert_equal, frb[proj_field].info['xlim'], \
- frb.bounds[:2]
+ frb.bounds[:2]
yield assert_equal, frb[proj_field].info['ylim'], \
- frb.bounds[2:]
+ frb.bounds[2:]
yield assert_equal, frb[proj_field].info['center'], \
- proj.center
+ proj.center
yield assert_equal, frb[proj_field].info['weight_field'], \
- wf
- teardown_func(fns)
+ wf
# 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
-
-
+ teardown_func(fns)
https://bitbucket.org/yt_analysis/yt/commits/501abca1722f/
Changeset: 501abca1722f
Branch: yt-3.0
User: xarthisius
Date: 2014-05-04 11:56:38
Summary: Remove temporary files in test_slice
Affected #: 1 file
diff -r 3c49a831117f6b869f56a5463f6a1657346d48f5 -r 501abca1722f1335fac07e19d280885725c10b76 yt/data_objects/tests/test_slice.py
--- a/yt/data_objects/tests/test_slice.py
+++ b/yt/data_objects/tests/test_slice.py
@@ -4,23 +4,21 @@
"""
-#-----------------------------------------------------------------------------
+# ----------------------------------------------------------------------------
# Copyright (c) 2013, yt Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
-#-----------------------------------------------------------------------------
+# ----------------------------------------------------------------------------
import os
import numpy as np
import tempfile
-from nose.tools import raises
from yt.testing import \
- fake_random_pf, assert_equal, assert_array_equal, YTArray
-from yt.utilities.exceptions import \
- YTNoDataInObjectError
+ fake_random_pf, assert_equal
from yt.units.unit_object import Unit
+
def setup():
from yt.config import ytcfg
ytcfg["yt", "__withintesting"] = "True"
@@ -33,7 +31,9 @@
except OSError:
pass
+
def test_slice():
+ fns = []
for nprocs in [8, 1]:
# We want to test both 1 proc and 8 procs, to make sure that
# parallelism isn't broken
@@ -51,7 +51,6 @@
xax = pf.coordinates.x_axis[ax]
yax = pf.coordinates.y_axis[ax]
for wf in ["density", None]:
- fns = []
slc = pf.slice(ax, slc_pos)
yield assert_equal, slc["ones"].sum(), slc["ones"].size
yield assert_equal, slc["ones"].min(), 1.0
@@ -63,7 +62,8 @@
pw = slc.to_pw()
tmpfd, tmpname = tempfile.mkstemp(suffix='.png')
os.close(tmpfd)
- fns += pw.save(name=tmpname)
+ pw.save(name=tmpname)
+ fns.append(tmpname)
frb = slc.to_frb((1.0, 'unitary'), 64)
for slc_field in ['ones', 'density']:
fi = pf._get_field_info(slc_field)
@@ -83,9 +83,9 @@
slc.center
yield assert_equal, frb[slc_field].info['coord'], \
slc_pos
- teardown_func(fns)
# wf == None
yield assert_equal, wf, None
+ teardown_func(fns)
def test_slice_over_edges():
https://bitbucket.org/yt_analysis/yt/commits/43b6fc9b1094/
Changeset: 43b6fc9b1094
Branch: yt-3.0
User: xarthisius
Date: 2014-05-04 12:10:51
Summary: Ensure that file descriptor is closed and temporary files are removed in test_ytarray
Affected #: 1 file
diff -r 501abca1722f1335fac07e19d280885725c10b76 -r 43b6fc9b1094fa717396ea93c51fc9d9764044b9 yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -6,24 +6,24 @@
"""
-#-----------------------------------------------------------------------------
+# ----------------------------------------------------------------------------
# Copyright (c) 2013, yt Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
-#-----------------------------------------------------------------------------
+# ----------------------------------------------------------------------------
+import os
from nose.tools import assert_true
from numpy.testing import \
- assert_approx_equal, assert_array_equal, \
+ assert_array_equal, \
assert_equal, assert_raises, \
assert_array_almost_equal_nulp
from numpy import array
from yt.units.yt_array import \
YTArray, YTQuantity, \
unary_operators, binary_operators
-from yt.units.unit_object import Unit
from yt.utilities.exceptions import \
YTUnitOperationError, YTUfuncUnitError
from yt.testing import fake_random_pf
@@ -35,13 +35,16 @@
import tempfile
import itertools
+
def operate_and_compare(a, b, op, answer):
# Test generator for YTArrays tests
assert_array_equal(op(a, b), answer)
+
def assert_isinstance(a, type):
assert isinstance(a, type)
+
def test_addition():
"""
Test addition of two YTArrays
@@ -69,8 +72,8 @@
yield assert_raises, YTUfuncUnitError, np.add, a1, a2
# Test dimensionless quantities
- a1 = YTArray([1,2,3])
- a2 = array([4,5,6])
+ a1 = YTArray([1, 2, 3])
+ a2 = array([4, 5, 6])
answer = YTArray([5, 7, 9])
yield operate_and_compare, a1, a2, operator.add, answer
@@ -85,6 +88,7 @@
yield assert_raises, YTUnitOperationError, operator.add, a1, a2
yield assert_raises, YTUnitOperationError, operator.iadd, a1, a2
+
def test_subtraction():
"""
Test subtraction of two YTArrays
@@ -113,8 +117,8 @@
yield assert_raises, YTUfuncUnitError, np.subtract, a1, a2
# Test dimensionless quantities
- a1 = YTArray([1,2,3])
- a2 = array([4,5,6])
+ a1 = YTArray([1, 2, 3])
+ a2 = array([4, 5, 6])
answer1 = YTArray([-3, -3, -3])
answer2 = YTArray([3, 3, 3])
@@ -130,6 +134,7 @@
yield assert_raises, YTUnitOperationError, operator.sub, a1, a2
yield assert_raises, YTUnitOperationError, operator.isub, a1, a2
+
def test_multiplication():
"""
Test multiplication of two YTArrays
@@ -169,8 +174,8 @@
yield operate_and_compare, a2, a1, np.multiply, answer
# One dimensionless, one unitful
- a1 = YTArray([1,2,3], 'cm')
- a2 = array([4,5,6])
+ a1 = YTArray([1, 2, 3], 'cm')
+ a2 = array([4, 5, 6])
answer = YTArray([4, 10, 18], 'cm')
yield operate_and_compare, a1, a2, operator.mul, answer
@@ -179,8 +184,8 @@
yield operate_and_compare, a2, a1, np.multiply, answer
# Both dimensionless quantities
- a1 = YTArray([1,2,3])
- a2 = array([4,5,6])
+ a1 = YTArray([1, 2, 3])
+ a2 = array([4, 5, 6])
answer = YTArray([4, 10, 18])
yield operate_and_compare, a1, a2, operator.mul, answer
@@ -188,6 +193,7 @@
yield operate_and_compare, a1, a2, np.multiply, answer
yield operate_and_compare, a2, a1, np.multiply, answer
+
def test_division():
"""
Test multiplication of two YTArrays
@@ -251,6 +257,7 @@
yield operate_and_compare, a1, a2, np.divide, answer1
yield operate_and_compare, a2, a1, np.divide, answer2
+
def test_power():
"""
Test power operator ensure units are correct.
@@ -266,20 +273,21 @@
assert_equal, cm**YTQuantity(3), YTQuantity(1, 'cm**3')
assert_raises, YTUnitOperationError, np.power, cm, YTQuantity(3, 'g')
- assert_equal, cm_arr**3, YTArray([1,1], 'cm**3')
- assert_equal, np.power(cm_arr, 3), YTArray([1,1], 'cm**3')
- assert_equal, cm_arr**YTQuantity(3), YTArray([1,1], 'cm**3')
+ assert_equal, cm_arr**3, YTArray([1, 1], 'cm**3')
+ assert_equal, np.power(cm_arr, 3), YTArray([1, 1], 'cm**3')
+ assert_equal, cm_arr**YTQuantity(3), YTArray([1, 1], 'cm**3')
assert_raises, YTUnitOperationError, np.power, cm_arr, YTQuantity(3, 'g')
+
def test_comparisons():
"""
Test numpy ufunc comparison operators for unit consistency.
"""
- from yt.units.yt_array import YTArray, YTQuantity
+ from yt.units.yt_array import YTArray
- a1 = YTArray([1,2,3], 'cm')
- a2 = YTArray([2,1,3], 'cm')
+ a1 = YTArray([1, 2, 3], 'cm')
+ a2 = YTArray([2, 1, 3], 'cm')
a3 = YTArray([.02, .01, .03], 'm')
ops = (
@@ -309,6 +317,7 @@
for op, answer in zip(ops, answers):
yield operate_and_compare, a1, a3.in_units('cm'), op, answer
+
def test_unit_conversions():
"""
Test operations that convert to different units or cast to ndarray
@@ -319,7 +328,6 @@
km = YTQuantity(1, 'km')
km_in_cm = km.in_units('cm')
- km_unit = Unit('km')
cm_unit = Unit('cm')
kpc_unit = Unit('kpc')
@@ -383,6 +391,7 @@
yield assert_isinstance, b*b, YTQuantity
yield assert_isinstance, b/b, YTQuantity
+
def test_selecting():
"""
Test slicing of two YTArrays
@@ -390,15 +399,16 @@
"""
a = YTArray(range(10), 'cm')
a_slice = a[:3]
- a_fancy_index = a[[1,1,3,5]]
- a_array_fancy_index = a[array([[1,1], [3,5]])]
+ a_fancy_index = a[[1, 1, 3, 5]]
+ a_array_fancy_index = a[array([[1, 1], [3, 5]])]
a_boolean_index = a[a > 5]
a_selection = a[0]
yield assert_array_equal, a_slice, YTArray([0, 1, 2], 'cm')
- yield assert_array_equal, a_fancy_index, YTArray([1,1,3,5], 'cm')
- yield assert_array_equal, a_array_fancy_index, YTArray([[1, 1,], [3,5]], 'cm')
- yield assert_array_equal, a_boolean_index, YTArray([6,7,8,9], 'cm')
+ yield assert_array_equal, a_fancy_index, YTArray([1, 1, 3, 5], 'cm')
+ yield assert_array_equal, a_array_fancy_index, \
+ YTArray([[1, 1, ], [3, 5]], 'cm')
+ yield assert_array_equal, a_boolean_index, YTArray([6, 7, 8, 9], 'cm')
yield assert_isinstance, a_selection, YTQuantity
# .base points to the original array for a numpy view. If it is not a
@@ -408,34 +418,42 @@
yield assert_true, a_array_fancy_index.base is None
yield assert_true, a_boolean_index.base is None
+
def test_fix_length():
"""
Test fixing the length of an array. Used in spheres and other data objects
"""
pf = fake_random_pf(64, nprocs=1, length_unit=10)
- length = pf.quan(1.0,'code_length')
+ length = pf.quan(1.0, 'code_length')
new_length = fix_length(length, pf=pf)
yield assert_equal, YTQuantity(10, 'cm'), new_length
+
def test_ytarray_pickle():
pf = fake_random_pf(64, nprocs=1)
- test_data = [pf.quan(12.0, 'code_length'), pf.arr([1,2,3], 'code_length')]
+ test_data = [pf.quan(12.0, 'code_length'),
+ pf.arr([1, 2, 3], 'code_length')]
for data in test_data:
tempf = tempfile.NamedTemporaryFile(delete=False)
pickle.dump(data, tempf)
tempf.close()
- loaded_data = pickle.load(open(tempf.name, "rb"))
+ with open(tempf.name, "rb") as fname:
+ loaded_data = pickle.load(fname)
+ os.unlink(tempf.name)
yield assert_array_equal, data, loaded_data
yield assert_equal, data.units, loaded_data.units
- yield assert_array_equal, array(data.in_cgs()), array(loaded_data.in_cgs())
- yield assert_equal, float(data.units.cgs_value), float(loaded_data.units.cgs_value)
+ yield assert_array_equal, array(data.in_cgs()), \
+ array(loaded_data.in_cgs())
+ yield assert_equal, float(data.units.cgs_value), \
+ float(loaded_data.units.cgs_value)
+
def test_copy():
quan = YTQuantity(1, 'g')
- arr = YTArray([1,2,3], 'cm')
+ arr = YTArray([1, 2, 3], 'cm')
yield assert_equal, copy.copy(quan), quan
yield assert_array_equal, copy.copy(arr), arr
@@ -449,6 +467,7 @@
yield assert_equal, np.copy(quan), quan
yield assert_array_equal, np.copy(arr), arr
+
def unary_ufunc_comparison(ufunc, a):
out = a.copy()
a_array = a.to_ndarray()
@@ -517,13 +536,14 @@
# There shouldn't be any untested ufuncs.
assert_true(False)
+
def binary_ufunc_comparison(ufunc, a, b):
out = a.copy()
- if ufunc in (np.add, np.subtract, np.remainder, np.fmod, np.mod, np.arctan2,
- np.hypot, np.greater, np.greater_equal, np.less, np.less_equal,
- np.equal, np.not_equal, np.logical_and, np.logical_or,
- np.logical_xor, np.maximum, np.minimum, np.fmax, np.fmin,
- np.nextafter):
+ if ufunc in (np.add, np.subtract, np.remainder, np.fmod, np.mod,
+ np.arctan2, np.hypot, np.greater, np.greater_equal, np.less,
+ np.less_equal, np.equal, np.not_equal, np.logical_and,
+ np.logical_or, np.logical_xor, np.maximum, np.minimum,
+ np.fmax, np.fmin, np.nextafter):
if a.units != b.units and a.units.dimensions == b.units.dimensions:
assert_raises(YTUfuncUnitError, ufunc, a, b)
return
@@ -540,10 +560,12 @@
elif ufunc in (np.greater, np.greater_equal, np.less, np.less_equal,
np.not_equal, np.equal, np.logical_and, np.logical_or,
np.logical_xor):
- assert_true(not isinstance(ret, YTArray) and isinstance(ret, np.ndarray))
+ assert_true(not isinstance(ret, YTArray) and
+ isinstance(ret, np.ndarray))
assert_array_equal(ret, out)
assert_array_equal(ret, ufunc(np.array(a), np.array(b)))
+
def test_ufuncs():
for ufunc in unary_operators:
yield unary_ufunc_comparison, ufunc, YTArray([.3, .4, .5], 'cm')
@@ -568,9 +590,10 @@
d = YTArray([.1, .2, .3], 'g')
e = YTArray([.1, .2, .3], 'erg/m**3')
- for pair in itertools.product([a,b,c,d,e], repeat=2):
+ for pair in itertools.product([a, b, c, d, e], repeat=2):
yield binary_ufunc_comparison, ufunc, pair[0], pair[1]
+
def test_convenience():
arr = YTArray([1, 2, 3], 'cm')
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