TEST: Add test suite for draw3d (ellipsoid/ellipsoid_stats)

This commit is contained in:
Josh Warner (Mac)
2013-09-01 21:31:53 -05:00
parent c678fa55f4
commit 50d73fdd62
2 changed files with 106 additions and 2 deletions
+2 -2
View File
@@ -83,9 +83,9 @@ def ellipsoid_stats(a, b, c, sampling=(1., 1., 1.)):
Returns
-------
vol : float
Analytically calculated volume of ellipsoid.
Calculated volume of ellipsoid.
surf : float
Analytically calculated surface area of ellipsoid.
Calculated surface area of ellipsoid.
"""
if (a <= 0) or (b <= 0) or (c <= 0):
+104
View File
@@ -0,0 +1,104 @@
from numpy.testing import assert_array_equal
import numpy as np
from skimage.draw import ellipsoid, ellipsoid_stats
def test_ellipsoid_bool():
test = ellipsoid(2, 2, 2)[1:-1, 1:-1, 1:-1]
test_anisotropic = ellipsoid(2, 2, 4, sampling=(1., 1., 2.))
test_anisotropic = test_anisotropic[1:-1, 1:-1, 1:-1]
expected = np.r_[[[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
[1, 1, 1, 1, 1],
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]]]]
assert_array_equal(test, expected.astype(bool))
assert_array_equal(test_anisotropic, expected.astype(bool))
def test_ellipsoid_levelset():
test = ellipsoid(2, 2, 2, levelset=True)[1:-1, 1:-1, 1:-1]
test_anisotropic = ellipsoid(2, 2, 4, sampling=(1., 1., 2.),
levelset=True)
test_anisotropic = test_anisotropic[1:-1, 1:-1, 1:-1]
expected = np.r_[[[[ 2. , 1.25, 1. , 1.25, 2. ],
[ 1.25, 0.5 , 0.25, 0.5 , 1.25],
[ 1. , 0.25, 0. , 0.25, 1. ],
[ 1.25, 0.5 , 0.25, 0.5 , 1.25],
[ 2. , 1.25, 1. , 1.25, 2. ]],
[[ 1.25, 0.5 , 0.25, 0.5 , 1.25],
[ 0.5 , -0.25, -0.5 , -0.25, 0.5 ],
[ 0.25, -0.5 , -0.75, -0.5 , 0.25],
[ 0.5 , -0.25, -0.5 , -0.25, 0.5 ],
[ 1.25, 0.5 , 0.25, 0.5 , 1.25]],
[[ 1. , 0.25, 0. , 0.25, 1. ],
[ 0.25, -0.5 , -0.75, -0.5 , 0.25],
[ 0. , -0.75, -1. , -0.75, 0. ],
[ 0.25, -0.5 , -0.75, -0.5 , 0.25],
[ 1. , 0.25, 0. , 0.25, 1. ]],
[[ 1.25, 0.5 , 0.25, 0.5 , 1.25],
[ 0.5 , -0.25, -0.5 , -0.25, 0.5 ],
[ 0.25, -0.5 , -0.75, -0.5 , 0.25],
[ 0.5 , -0.25, -0.5 , -0.25, 0.5 ],
[ 1.25, 0.5 , 0.25, 0.5 , 1.25]],
[[ 2. , 1.25, 1. , 1.25, 2. ],
[ 1.25, 0.5 , 0.25, 0.5 , 1.25],
[ 1. , 0.25, 0. , 0.25, 1. ],
[ 1.25, 0.5 , 0.25, 0.5 , 1.25],
[ 2. , 1.25, 1. , 1.25, 2. ]]]]
assert_array_equal(test, expected.astype(bool))
assert_array_equal(test_anisotropic, expected.astype(bool))
def test_ellipsoid_stats():
# Test comparison values generated by Wolfram Alpha
vol, surf = ellipsoid_stats(6, 10, 16)
assert(round(1280 * np.pi, 4) == round(vol, 4))
assert(1383.28 == round(surf, 2))
# Test when a <= b <= c does not hold
vol, surf = ellipsoid_stats(16, 6, 10)
assert(round(1280 * np.pi, 4) == round(vol, 4))
assert(1383.28 == round(surf, 2))
# Larger test to ensure reliability over broad range
vol, surf = ellipsoid_stats(17, 27, 169)
assert(round(103428 * np.pi, 4) == round(vol, 4))
assert(37426.3 == round(surf, 1))
if __name__ == "__main__":
np.testing.run_module_suite()