Repository navigation
Expand file tree
/
Copy pathtest_msclean.py
More file actions
48 lines (40 loc) · 2.48 KB
/
Copy pathtest_msclean.py
File metadata and controls
48 lines (40 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
""" Unit processing_library for image deconvolution via MSClean
"""
import unittest
import numpy
import logging
from processing_library.arrays.cleaners import create_scalestack, convolve_scalestack, convolve_convolve_scalestack,\
argmax
log = logging.getLogger(__name__)
class TestImageMSClean(unittest.TestCase):
def setUp(self):
self.npixel = 256
self.scales = [0.0, 8.0 / numpy.sqrt(2.0), 8.0]
self.stackshape = [len(self.scales), self.npixel, self.npixel]
self.scalestack = create_scalestack(self.stackshape, self.scales)
def test_convolve(self):
img = numpy.zeros([self.npixel, self.npixel])
img[75, 31] = 1.0
result = convolve_scalestack(self.scalestack, img)
assert argmax(result)[1:] == (75, 31)
numpy.testing.assert_array_almost_equal(result[0, 75, 31],
self.scalestack[0, self.npixel // 2, self.npixel // 2], 7)
numpy.testing.assert_array_almost_equal(result[1, 75, 31],
self.scalestack[1, self.npixel // 2, self.npixel // 2], 7)
numpy.testing.assert_array_almost_equal(result[2, 75, 31],
self.scalestack[2, self.npixel // 2, self.npixel // 2], 7)
def test_convolve_convolve(self):
img = numpy.zeros([self.npixel, self.npixel])
img[75, 31] = 1.0
result = convolve_convolve_scalestack(self.scalestack, img)
assert argmax(result)[2:] == (75, 31)
numpy.testing.assert_array_almost_equal(result[0, 0, 75, 31], self.scalestack[0, self.npixel // 2,
self.npixel // 2], 7)
numpy.testing.assert_array_almost_equal(result[0, 1, 75, 31], self.scalestack[1, self.npixel // 2,
self.npixel // 2], 7)
numpy.testing.assert_array_almost_equal(result[0, 2, 75, 31], self.scalestack[2, self.npixel // 2,
self.npixel // 2], 7)
# This is a coarse test since the scales do not having the property of widths adding incoherently under
# convolution
numpy.testing.assert_array_almost_equal(result[1, 1, 75, 31], self.scalestack[2, self.npixel // 2,
self.npixel // 2], 2)