From e780bd7a5ac7b958994963cd396f69e0dc322e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20B=C3=B8=20Fl=C3=B8ystad?= Date: Sat, 6 Jul 2013 23:32:02 +0200 Subject: [PATCH] unwrap: refactor tests. Update imports to skimage Use simple test functions, do not wrap in a class Whitespace fixes --- skimage/exposure/tests/test_unwrap.py | 85 +++++++++++++-------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/skimage/exposure/tests/test_unwrap.py b/skimage/exposure/tests/test_unwrap.py index f371494f..5627bd79 100644 --- a/skimage/exposure/tests/test_unwrap.py +++ b/skimage/exposure/tests/test_unwrap.py @@ -1,64 +1,63 @@ -from numpy.testing import run_module_suite, TestCase, assert_array_almost_equal -from unwrap import unwrap import numpy as np +from numpy.testing import run_module_suite, TestCase, assert_array_almost_equal -class test_unwrap(TestCase): +from skimage.exposure import unwrap - def test_unwrap2D(self): - x, y = np.ogrid[:8, :16] - phi = 2*np.pi*(x*0.2 + y*0.1) - phi_wrapped = np.angle(np.exp(1j*phi)) - phi_unwrapped = unwrap(phi_wrapped) +def test_unwrap2D(): + x, y = np.ogrid[:8, :16] + phi = 2*np.pi*(x*0.2 + y*0.1) + phi_wrapped = np.angle(np.exp(1j*phi)) + phi_unwrapped = unwrap(phi_wrapped) - s = np.round(phi_unwrapped[0,0]/(2*np.pi)) - assert_array_almost_equal(phi, phi_unwrapped - s*2*np.pi) + s = np.round(phi_unwrapped[0,0]/(2*np.pi)) + assert_array_almost_equal(phi, phi_unwrapped - s*2*np.pi) - def test_unwrap2D_masked(self): - x, y = np.ogrid[:8, :16] - phi = 2*np.pi*(x*0.2 + y*0.1) +def test_unwrap2D_masked(): + x, y = np.ogrid[:8, :16] + phi = 2*np.pi*(x*0.2 + y*0.1) - mask = np.zeros_like(phi, dtype = np.uint8) - mask[4:6, 4:8] = 1 + mask = np.zeros_like(phi, dtype = np.uint8) + mask[4:6, 4:8] = 1 - phi_wrapped = np.angle(np.exp(1j*phi)) - phi_wrapped_masked = np.ma.array(phi_wrapped, dtype = np.float32, mask = mask) - phi_unwrapped_masked = unwrap(phi_wrapped_masked) + phi_wrapped = np.angle(np.exp(1j*phi)) + phi_wrapped_masked = np.ma.array(phi_wrapped, dtype = np.float32, mask = mask) + phi_unwrapped_masked = unwrap(phi_wrapped_masked) - s = np.round(phi_unwrapped_masked[0,0]/(2*np.pi)) - assert_array_almost_equal(phi + 2*np.pi*s, phi_unwrapped_masked) + s = np.round(phi_unwrapped_masked[0,0]/(2*np.pi)) + assert_array_almost_equal(phi + 2*np.pi*s, phi_unwrapped_masked) - def test_unwrap3D(self): - x, y, z = np.ogrid[:8, :12, :4] - phi = 2*np.pi*(x*0.2 + y*0.1 + z*0.05) - phi_wrapped = np.angle(np.exp(1j*phi)) - phi_unwrapped = unwrap(phi_wrapped) +def test_unwrap3D(): + x, y, z = np.ogrid[:8, :12, :4] + phi = 2*np.pi*(x*0.2 + y*0.1 + z*0.05) + phi_wrapped = np.angle(np.exp(1j*phi)) + phi_unwrapped = unwrap(phi_wrapped) - s = np.round(phi_unwrapped[0,0]/(2*np.pi)) - assert_array_almost_equal(phi, phi_unwrapped - s*2*np.pi) + s = np.round(phi_unwrapped[0,0]/(2*np.pi)) + assert_array_almost_equal(phi, phi_unwrapped - s*2*np.pi) - def test_unwrap3D_masked(self): - x, y, z = np.ogrid[:8, :12, :4] - phi = 2*np.pi*(x*0.2 + y*0.1 + z*0.05) - phi_wrapped = np.angle(np.exp(1j*phi)) - mask = np.zeros_like(phi, dtype = np.uint8) - mask[4:6, 4:6, 1:3] = 1 - phi_wrapped_masked = np.ma.array(phi_wrapped, dtype = np.float32, mask = mask) - phi_unwrapped_masked = unwrap(phi_wrapped_masked) +def test_unwrap3D_masked(): + x, y, z = np.ogrid[:8, :12, :4] + phi = 2*np.pi*(x*0.2 + y*0.1 + z*0.05) + phi_wrapped = np.angle(np.exp(1j*phi)) + mask = np.zeros_like(phi, dtype = np.uint8) + mask[4:6, 4:6, 1:3] = 1 + phi_wrapped_masked = np.ma.array(phi_wrapped, dtype = np.float32, mask = mask) + phi_unwrapped_masked = unwrap(phi_wrapped_masked) - s = np.round(phi_unwrapped_masked[0,0,0]/(2*np.pi)) - assert_array_almost_equal(phi + 2*np.pi*s, phi_unwrapped_masked) + s = np.round(phi_unwrapped_masked[0,0,0]/(2*np.pi)) + assert_array_almost_equal(phi + 2*np.pi*s, phi_unwrapped_masked) def unwrap_plots(): - + x, y = np.ogrid[:32, :32] phi = 2*np.pi*(x*0.2 + y*0.1) #phi = 1*np.arctan2(x-14.3, y-6.3) - 2*np.arctan2(x-18.3, y-22.1) phi[8,8] = np.NaN - + phi_wrapped = np.angle(np.exp(1j*phi)) - phi_unwrapped = unwrap(phi_wrapped, + phi_unwrapped = unwrap(phi_wrapped, #wrap_around_axis_0 = True, #wrap_around_axis_1 = True, ) @@ -67,7 +66,7 @@ def unwrap_plots(): #mask[10:22, 4:10] = 1 phi_wrapped_masked = np.ma.array(phi_wrapped, dtype = np.float32, mask = mask) phi_unwrapped_masked = unwrap(phi_wrapped_masked) - + import matplotlib.pyplot as plt plt.figure(1) plt.clf() @@ -83,12 +82,12 @@ def unwrap_plots(): plt.draw() plt.show() - + if __name__=="__main__": run_module_suite() unwrap_plots() - + # p0,p1,p2,p3,p4 = test_unwrap2D() # plt.figure(1) # plt.clf()