[Scipy-svn] r5435 - in trunk/scipy/stsci: . image image/lib image/tests

scipy-svn@scip... scipy-svn@scip...
Sun Jan 11 21:36:48 CST 2009


Author: chanley
Date: 2009-01-11 21:36:28 -0600 (Sun, 11 Jan 2009)
New Revision: 5435

Added:
   trunk/scipy/stsci/image/tests/
   trunk/scipy/stsci/image/tests/test_average.py
   trunk/scipy/stsci/image/tests/test_median.py
   trunk/scipy/stsci/image/tests/test_minimum.py
   trunk/scipy/stsci/image/tests/test_threshold.py
Modified:
   trunk/scipy/stsci/__init__.py
   trunk/scipy/stsci/image/lib/__init__.py
   trunk/scipy/stsci/image/setup.py
Log:
Adding nose tests for stsci.stsci.image module

Modified: trunk/scipy/stsci/__init__.py
===================================================================
--- trunk/scipy/stsci/__init__.py	2009-01-11 17:57:52 UTC (rev 5434)
+++ trunk/scipy/stsci/__init__.py	2009-01-12 03:36:28 UTC (rev 5435)
@@ -4,5 +4,4 @@
 __all__ = ['convolve','image']
 
 from numpy.testing import Tester
-test = Tester().test
-
+test = Tester().test
\ No newline at end of file

Modified: trunk/scipy/stsci/image/lib/__init__.py
===================================================================
--- trunk/scipy/stsci/image/lib/__init__.py	2009-01-11 17:57:52 UTC (rev 5434)
+++ trunk/scipy/stsci/image/lib/__init__.py	2009-01-12 03:36:28 UTC (rev 5435)
@@ -3,27 +3,8 @@
 from combine import *
 
 __version__ = '2.0'
-if sys.version_info < (2,4):
-    def test():
-        import doctest, _image, combine
 
-        t = doctest.Tester(globs = globals())
+def test(level=1, verbosity=1):
+    from numpy.testing import Tester
+    return Tester().test(level,verbosity)
 
-        t.rundict(_image.__dict__, "_image")
-        t.rundict(combine.__dict__, "combine")
-
-        return t.summarize()
-
-else:
-    def test():
-        import doctest, _image, combine
-
-        finder=doctest.DocTestFinder()
-        tests=finder.find(_image)
-        tests.extend(finder.find(combine))
-
-        runner=doctest.DocTestRunner(verbose=False)
-
-        for test in tests:
-            runner.run(test)
-        return runner.summarize()

Modified: trunk/scipy/stsci/image/setup.py
===================================================================
--- trunk/scipy/stsci/image/setup.py	2009-01-11 17:57:52 UTC (rev 5434)
+++ trunk/scipy/stsci/image/setup.py	2009-01-12 03:36:28 UTC (rev 5435)
@@ -9,6 +9,7 @@
                          sources=["src/_combinemodule.c"],
                          define_macros = [('NUMPY', '1')],
                          include_dirs = [numpy.get_numarray_include()])
+    config.add_data_dir('tests')
     return config
 
 if __name__ == "__main__":

Added: trunk/scipy/stsci/image/tests/test_average.py
===================================================================
--- trunk/scipy/stsci/image/tests/test_average.py	2009-01-11 17:57:52 UTC (rev 5434)
+++ trunk/scipy/stsci/image/tests/test_average.py	2009-01-12 03:36:28 UTC (rev 5435)
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+import numpy as np
+import nose
+from scipy.stsci.image import *
+from numpy.testing import *
+
+def test_average1():
+    """
+    average() nominally computes the average pixel value for a stack of
+    identically shaped images.
+
+    arrays     specifies a sequence of inputs arrays, which are nominally a
+               stack of identically shaped images.
+
+    output     may be used to specify the output array.  If none is specified,
+               either arrays[0] is copied or a new array of type 'outtype'
+               is created.
+
+    outtype    specifies the type of the output array when no 'output' is
+               specified.
+
+    nlow       specifies the number of pixels to be excluded from average
+               on the low end of the pixel stack.
+
+    nhigh      specifies the number of pixels to be excluded from average
+               on the high end of the pixel stack.
+
+    badmasks   specifies boolean arrays corresponding to 'arrays', where true
+               indicates that a particular pixel is not to be included in the
+               average calculation.
+    """
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = average(arrays)
+    test = np.array([[ 0,  7],
+           [15, 22]])
+    assert_equal(result,test)
+    
+def test_average2():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = average(arrays, nhigh=1)
+    test = np.array([[ 0,  4],
+           [ 9, 14]])
+    assert_equal(result,test)
+
+def test_average3():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = average(arrays, nlow=1)
+    test = np.array([[ 0,  9],
+           [18, 28]])
+    assert_equal(result,test)
+
+def test_average4():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = average(arrays, outtype=np.float32)
+    test = np.array([[  0. ,   7.5],
+           [ 15. ,  22.5]], dtype=np.float32)
+    assert_equal(result,test)
+
+def test_average5():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    bm = np.zeros((4,2,2), dtype=np.bool8)
+    bm[2,...] = 1
+    result = average(arrays, badmasks=bm)
+    test = np.array([[ 0,  9],
+           [18, 28]])
+    assert_equal(result,test)
+
+def test_average6():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = average(arrays, badmasks=threshhold(arrays, high=25))
+    test = np.array([[ 0,  7],
+           [ 9, 14]])
+    assert_equal(result,test)
+
+if __name__ == "__main__":
+    run_module_suite()

Added: trunk/scipy/stsci/image/tests/test_median.py
===================================================================
--- trunk/scipy/stsci/image/tests/test_median.py	2009-01-11 17:57:52 UTC (rev 5434)
+++ trunk/scipy/stsci/image/tests/test_median.py	2009-01-12 03:36:28 UTC (rev 5435)
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+import numpy as np
+import nose
+from scipy.stsci.image import *
+from numpy.testing import *
+
+def test_median1():
+    """
+    median() nominally computes the median pixels for a stack of
+    identically shaped images.
+
+    arrays     specifies a sequence of inputs arrays, which are nominally a
+               stack of identically shaped images.
+
+    output     may be used to specify the output array.  If none is specified,
+               either arrays[0] is copied or a new array of type 'outtype'
+               is created.
+
+    outtype    specifies the type of the output array when no 'output' is
+               specified.
+
+    nlow       specifies the number of pixels to be excluded from median
+               on the low end of the pixel stack.
+
+    nhigh      specifies the number of pixels to be excluded from median
+               on the high end of the pixel stack.
+
+    badmasks   specifies boolean arrays corresponding to 'arrays', where true
+               indicates that a particular pixel is not to be included in the
+               median calculation.
+    """    
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = median(arrays)
+    test = np.array([[ 0,  6],
+           [12, 18]])
+    assert_equal(result,test)
+
+def test_median2():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = median(arrays, nhigh=1)
+    test = np.array([[ 0,  4],
+           [ 8, 12]])
+    assert_equal(result,test)
+
+def test_median3():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = median(arrays, nlow=1)
+    test = np.array([[ 0,  8],
+           [16, 24]])
+    assert_equal(result,test)
+
+def test_median4():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = median(arrays, outtype=np.float32)
+    test = np.array([[  0.,   6.],
+           [ 12.,  18.]], dtype=np.float32)
+    assert_equal(result,test)
+    
+def test_median5():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    bm = np.zeros((4,2,2), dtype=np.bool8)
+    bm[2,...] = 1
+    result = median(arrays, badmasks=bm)
+    test = np.array([[ 0,  8],
+           [16, 24]])
+    assert_equal(result,test)
+    
+def test_median6():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = median(arrays, badmasks=threshhold(arrays, high=25))
+    test = np.array([[ 0,  6],
+           [ 8, 12]])
+    assert_equal(result,test)
+           
+if __name__ == "__main__":
+    run_module_suite()

Added: trunk/scipy/stsci/image/tests/test_minimum.py
===================================================================
--- trunk/scipy/stsci/image/tests/test_minimum.py	2009-01-11 17:57:52 UTC (rev 5434)
+++ trunk/scipy/stsci/image/tests/test_minimum.py	2009-01-12 03:36:28 UTC (rev 5435)
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+import numpy as np
+import nose
+from scipy.stsci.image import *
+from numpy.testing import *
+
+def test_minimum1():
+    """
+    minimum() nominally computes the minimum pixel value for a stack of
+    identically shaped images.
+
+    arrays     specifies a sequence of inputs arrays, which are nominally a
+               stack of identically shaped images.
+
+    output     may be used to specify the output array.  If none is specified,
+               either arrays[0] is copied or a new array of type 'outtype'
+               is created.
+
+    outtype    specifies the type of the output array when no 'output' is
+               specified.
+
+    nlow       specifies the number of pixels to be excluded from minimum
+               on the low end of the pixel stack.
+
+    nhigh      specifies the number of pixels to be excluded from minimum
+               on the high end of the pixel stack.
+
+    badmasks   specifies boolean arrays corresponding to 'arrays', where true
+               indicates that a particular pixel is not to be included in the
+               minimum calculation.
+    """
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = minimum(arrays)
+    test = np.array([[0, 2],
+           [4, 6]])
+    assert_equal(result,test)
+ 
+def test_minimum2():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = minimum(arrays, nhigh=1)
+    test = np.array([[0, 2],
+           [4, 6]])
+    assert_equal(result,test)
+    
+def test_minimum3():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = minimum(arrays, nlow=1)
+    test = np.array([[ 0,  4],
+           [ 8, 12]])
+    assert_equal(result,test)
+    
+def test_minimum4():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = minimum(arrays, outtype=np.float32)
+    test = np.array([[ 0.,  2.],
+           [ 4.,  6.]], dtype=np.float32)
+    assert_equal(result,test)
+    
+def test_minimum5():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    bm = np.zeros((4,2,2), dtype=np.bool8)
+    bm[2,...] = 1
+    result = minimum(arrays, badmasks=bm)
+    test = np.array([[ 0,  4],
+           [ 8, 12]])
+    assert_equal(result,test)
+
+def test_minimum6():
+    a = np.arange(4)
+    a = a.reshape((2,2))
+    arrays = [a*16, a*4, a*2, a*8]
+    result = minimum(arrays, badmasks=threshhold(arrays, low=10))
+    test = np.array([[ 0, 16],
+           [16, 12]])
+    assert_equal(result,test)
+
+
+if __name__ == "__main__":
+    run_module_suite()

Added: trunk/scipy/stsci/image/tests/test_threshold.py
===================================================================
--- trunk/scipy/stsci/image/tests/test_threshold.py	2009-01-11 17:57:52 UTC (rev 5434)
+++ trunk/scipy/stsci/image/tests/test_threshold.py	2009-01-12 03:36:28 UTC (rev 5435)
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+import numpy as np
+import nose
+from scipy.stsci.image import *
+from numpy.testing import *
+
+def test_threshhold1():
+    """
+    threshhold() computes a boolean array 'outputs' with
+    corresponding elements for each element of arrays.  The
+    boolean value is true where each of the arrays values
+    is < the low or >= the high threshholds.
+    """
+
+    a=np.arange(100)
+    a=a.reshape((10,10))
+    result = (threshhold(a, 1, 50)).astype(np.int8)
+    test = np.array([[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, 0, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=np.int8)
+    assert_equal(result,test)
+
+def test_threshold2():
+    a=np.arange(100)
+    a=a.reshape((10,10))
+    result = (threshhold([ range(10)]*10, 3, 7)).astype(np.int8)
+    test = np.array([[1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
+           [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
+           [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
+           [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
+           [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
+           [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
+           [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
+           [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
+           [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
+           [1, 1, 1, 0, 0, 0, 0, 1, 1, 1]], dtype=np.int8)
+    assert_equal(result,test)
+
+def test_threshold3():
+    a=np.arange(100)
+    a=a.reshape((10,10))
+    result = (threshhold(a, high=50)).astype(np.int8)
+    test = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+           [0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=np.int8)
+    assert_equal(result,test)
+    
+def test_threshold4():
+    a=np.arange(100)
+    a=a.reshape((10,10))
+    result = (threshhold(a, low=50)).astype(np.int8)
+    test = np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+           [1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0],
+           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=np.int8)
+
+if __name__ == "__main__":
+    run_module_suite()



More information about the Scipy-svn mailing list