Package image :: Package test :: Module test_average
[hide private]
[frames] | no frames]

Source Code for Module image.test.test_average

 1  #!/usr/bin/env python 
 2  import numpy as np 
 3  import nose 
 4  from nose.tools import * 
 5  from image import combine 
 6   
7 -def test_average1():
8 """ 9 average() nominally computes the average pixel value for a stack of 10 identically shaped images. 11 12 arrays specifies a sequence of inputs arrays, which are nominally a 13 stack of identically shaped images. 14 15 output may be used to specify the output array. If none is specified, 16 either arrays[0] is copied or a new array of type 'outtype' 17 is created. 18 19 outtype specifies the type of the output array when no 'output' is 20 specified. 21 22 nlow specifies the number of pixels to be excluded from average 23 on the low end of the pixel stack. 24 25 nhigh specifies the number of pixels to be excluded from average 26 on the high end of the pixel stack. 27 28 badmasks specifies boolean arrays corresponding to 'arrays', where true 29 indicates that a particular pixel is not to be included in the 30 average calculation. 31 """ 32 a = np.arange(4) 33 a = a.reshape((2,2)) 34 arrays = [a*16, a*4, a*2, a*8] 35 result = combine.average(arrays) 36 test = np.array([[ 0, 7], 37 [15, 22]]) 38 assert_equal(result.all(),test.all())
39
40 -def test_average2():
41 a = np.arange(4) 42 a = a.reshape((2,2)) 43 arrays = [a*16, a*4, a*2, a*8] 44 result = combine.average(arrays, nhigh=1) 45 test = np.array([[ 0, 4], 46 [ 9, 14]]) 47 assert_equal(result.all(),test.all())
48
49 -def test_average3():
50 a = np.arange(4) 51 a = a.reshape((2,2)) 52 arrays = [a*16, a*4, a*2, a*8] 53 result = combine.average(arrays, nlow=1) 54 test = np.array([[ 0, 9], 55 [18, 28]]) 56 assert_equal(result.all(),test.all())
57
58 -def test_average4():
59 a = np.arange(4) 60 a = a.reshape((2,2)) 61 arrays = [a*16, a*4, a*2, a*8] 62 result = combine.average(arrays, outtype=np.float32) 63 test = np.array([[ 0. , 7.5], 64 [ 15. , 22.5]], dtype=np.float32) 65 assert_equal(result.all(),test.all())
66
67 -def test_average5():
68 a = np.arange(4) 69 a = a.reshape((2,2)) 70 arrays = [a*16, a*4, a*2, a*8] 71 bm = np.zeros((4,2,2), dtype=np.bool8) 72 bm[2,...] = 1 73 result = combine.average(arrays, badmasks=bm) 74 test = np.array([[ 0, 9], 75 [18, 28]]) 76 assert_equal(result.all(),test.all())
77
78 -def test_average6():
79 a = np.arange(4) 80 a = a.reshape((2,2)) 81 arrays = [a*16, a*4, a*2, a*8] 82 result = combine.average(arrays, badmasks=combine.threshhold(arrays, high=25)) 83 test = np.array([[ 0, 7], 84 [ 9, 14]]) 85 assert_equal(result.all(),test.all())
86