From abc7a16a8099ce0110b02b2dd934ef4873048943 Mon Sep 17 00:00:00 2001 From: "Josh Warner (Mac)" Date: Mon, 2 Sep 2013 15:31:51 -0500 Subject: [PATCH] STYLE: Use `np.array` instead of `np.r_` and import Poly3DCollection --- doc/examples/plot_marching_cubes.py | 6 +- skimage/draw/tests/test_draw3d.py | 106 ++++++++++++++-------------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/doc/examples/plot_marching_cubes.py b/doc/examples/plot_marching_cubes.py index 0b321bfb..a57a40a2 100644 --- a/doc/examples/plot_marching_cubes.py +++ b/doc/examples/plot_marching_cubes.py @@ -23,7 +23,7 @@ voxel spacing is not equal for every spatial dimension, through use of the import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D -import mpl_toolkits.mplot3d as a3 +from mpl_toolkits.mplot3d.art3d import Poly3DCollection from skimage import measure from skimage.draw import ellipsoid @@ -41,8 +41,8 @@ verts, faces = measure.marching_cubes(ellip_double, 0) fig = plt.figure(figsize=(10, 12)) ax = fig.add_subplot(111, projection='3d') -# Fancy indexing: `verts[faces]` to generate a Poly3DCollection -mesh = a3.art3d.Poly3DCollection(verts[faces]) +# Fancy indexing: `verts[faces]` to generate a collection of triangles +mesh = Poly3DCollection(verts[faces]) ax.add_collection3d(mesh) ax.set_xlabel("x-axis: a = 6 per ellipsoid") diff --git a/skimage/draw/tests/test_draw3d.py b/skimage/draw/tests/test_draw3d.py index 14bf140f..59a7f6b3 100644 --- a/skimage/draw/tests/test_draw3d.py +++ b/skimage/draw/tests/test_draw3d.py @@ -1,5 +1,5 @@ -from numpy.testing import assert_array_equal import numpy as np +from numpy.testing import assert_array_equal, assert_allclose from skimage.draw import ellipsoid, ellipsoid_stats @@ -9,35 +9,35 @@ def test_ellipsoid_bool(): 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]], + expected = np.array([[[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, 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, 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, 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]]]] + [[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)) @@ -49,38 +49,38 @@ def test_ellipsoid_levelset(): 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. ]], + expected = np.array([[[ 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.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. , 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]], + [[ 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. ]]]] + [[ 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) - assert_array_equal(test_anisotropic, expected) + assert_allclose(test, expected) + assert_allclose(test_anisotropic, expected) def test_ellipsoid_stats():