Ejemplo n.º 1
0
    def test_gains(self):
        A0 = deconv.clean(img0, ker, stop_if_div=False, tol=0.1, gain=0.01)[0]
        A1 = deconv.clean(img1, ker, stop_if_div=False, tol=1e-6,
                          gain=0.001)[0]
        A2 = deconv.clean(img2, ker, stop_if_div=False, tol=1e-9, gain=0.3)[0]
        A3 = deconv.clean(img3,
                          ker128,
                          stop_if_div=False,
                          tol=1e-6,
                          gain=0.001)[0]

        B0 = clean(img0, ker, stop_if_div=False, tol=0.1, gain=0.01)[0]
        B1 = clean(img1, ker, stop_if_div=False, tol=1e-6, gain=0.001)[0]
        B2 = clean([img2] * 3, [ker] * 3,
                   stop_if_div=False,
                   tol=1e-9,
                   gain=0.3)[0][1]
        B3 = clean(img3, ker128, stop_if_div=False, tol=1e-6, gain=0.001)[0]

        for i in xrange(1024):
            self.assertEqual(A0[i], B0[i])

        for i in xrange(1024):
            self.assertEqual(A1[i], B1[i])

        for i in xrange(1024):
            self.assertEqual(A2[i], B2[i])

        for i in xrange(1024):
            self.assertEqual(A3[i], B3[i])
Ejemplo n.º 2
0
    def test_areas(self):
        A0 = deconv.clean(img0, ker, stop_if_div=False, tol=0, area=area0)[0]
        A1 = deconv.clean(img1, ker, stop_if_div=False, tol=0, area=area1)[0]
        A2 = deconv.clean(img2, ker, stop_if_div=False, tol=0, area=area1)[0]
        A3 = deconv.clean(img3, ker128, stop_if_div=False, tol=0,
                          area=area1)[0]

        B0 = clean(img0, ker, stop_if_div=False, tol=0, area=area0)[0]
        B1 = clean(img1, ker, stop_if_div=False, tol=0, area=area1)[0]
        B2 = clean([img2] * 3, [ker] * 3, stop_if_div=False, tol=0,
                   area=area1)[0][1]
        B3 = clean([img3] * 3, [ker128] * 3,
                   stop_if_div=False,
                   tol=0,
                   area=area1)[0][1]
        for i in xrange(1024):
            self.assertEqual(A0[i], B0[i])

        for i in xrange(1024):
            self.assertEqual(A1[i], B1[i])

        for i in xrange(1024):
            self.assertEqual(A2[i], B2[i])

        for i in xrange(1024):
            self.assertEqual(A3[i], B3[i])
Ejemplo n.º 3
0
 def test_ZeroGain(self):
     dim = 128
     res = np.ones(dim)
     ker = np.ones(dim)
     mdl = np.ones(dim)
     area = np.ones(dim)
     self.assertEqual(1,
                      clean(res, ker, mdl, area, 0, 100, 1, 0, 1024)[0][0])
     self.assertEqual(1,
                      clean(res, ker, mdl, area, 0, 100, 1, 0, 1024)[0][-1])
Ejemplo n.º 4
0
    def test_mdls(self):
        A0 = deconv.clean(img0,
                          ker,
                          np.array(area0, dtype=np.complex64),
                          stop_if_div=False,
                          tol=0.1,
                          verbose=False)[0]
        A1 = deconv.clean(img1,
                          ker,
                          stop_if_div=False,
                          tol=1e-6,
                          mdl=np.array(area1, dtype=np.complex64),
                          verbose=False)[0]
        A2 = deconv.clean(img2,
                          ker,
                          stop_if_div=False,
                          tol=1e-9,
                          mdl=np.array(area2, dtype=np.complex64),
                          verbose=False)[0]
        A3 = deconv.clean(img3,
                          ker128,
                          stop_if_div=False,
                          tol=1e-6,
                          mdl=np.array(area1, dtype=np.complex128))[0]

        B0 = clean(img0,
                   ker,
                   stop_if_div=False,
                   tol=0.1,
                   mdl=np.array(area0, dtype=np.complex64))[0]
        B1 = clean(img1,
                   ker,
                   stop_if_div=False,
                   tol=1e-6,
                   mdl=np.array(area1, dtype=np.complex64))[0]
        B2 = clean([img2] * 3, [ker] * 3,
                   stop_if_div=False,
                   tol=1e-9,
                   mdl=[np.array(area2, dtype=np.complex64)] * 3)[0][1]
        B3 = clean(img3,
                   ker128,
                   stop_if_div=False,
                   tol=1e-6,
                   mdl=np.array(area1, dtype=np.complex128))[0]
        for i in xrange(1024):
            self.assertEqual(A0[i], B0[i])

        for i in xrange(1024):
            self.assertEqual(A1[i], B1[i])

        for i in xrange(1024):
            self.assertEqual(A2[i], B2[i])

        for i in xrange(1024):
            self.assertEqual(A3[i], B3[i])
Ejemplo n.º 5
0
    def test_tolerances(self):
        A0 = deconv.clean(img0, ker, stop_if_div=False, tol=0.01)[0]
        A1 = deconv.clean(img1, ker, stop_if_div=False, tol=1e-6)[0]
        A2 = deconv.clean(img2, ker, stop_if_div=False, tol=1e-9)[0]

        B0 = clean(img0, ker, stop_if_div=False, tol=0.01)[0]
        B1 = clean(img1, ker, stop_if_div=False, tol=1e-6)[0]
        B2 = clean([img2] * 3, [ker] * 3, stop_if_div=False, tol=1e-9)[0][1]
        for i in xrange(1024):
            self.assertEqual(A0[i], B0[i])

        for i in xrange(1024):
            self.assertEqual(A1[i], B1[i])

        for i in xrange(1024):
            self.assertEqual(A2[i], B2[i])
Ejemplo n.º 6
0
    def test_EZ(self):
        img = np.array([0, 0, 0, 4, 6, 4, 0, 0, -2, -3, -2, 0], dtype=np.float)
        ker = np.array([3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], dtype=np.float)

        # print deconv.clean(img, ker)
        # print clean(img, ker)
        self.assertAlmostEqual(0, clean(img, ker)[0])
Ejemplo n.º 7
0
    def test_RandomInput(self):
        dim = 25
        img = np.array(np.random.rand(dim), dtype=np.float32)
        ker = np.array(np.random.rand(dim), dtype=np.float32)

        A = deconv.clean(img, ker)[0]
        B = clean(img, ker)[0]

        for i in xrange(dim):
            self.assertEqual(A[i], B[i])
Ejemplo n.º 8
0
    def test_Default(self):
        img = np.array([0, 0, 0, 4, 6, 4, 0, 0, -2, -3, -2, 0],
                       dtype=np.float32)
        ker = np.array([3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], dtype=np.float32)

        #print deconv.clean(img, ker, verbose=True)[0]
        #print clean(img, ker)[0]

        for i in xrange(12):
            self.assertEqual(
                deconv.clean(img, ker)[0][i],
                clean(img, ker)[0][i])
Ejemplo n.º 9
0
    def test_mdls(self):
        A0 = deconv.clean(img0,
                          ker,
                          stop_if_div=False,
                          tol=0.1,
                          mdl=np.array(area0, dtype=np.float32),
                          verbose=False)[0]
        A1 = deconv.clean(img1,
                          ker,
                          stop_if_div=False,
                          tol=1e-6,
                          mdl=np.array(area1, dtype=np.float32),
                          verbose=False)[0]
        A2 = deconv.clean(img2,
                          ker,
                          stop_if_div=False,
                          tol=1e-9,
                          mdl=np.array(area2, dtype=np.float32),
                          verbose=False)[0]

        B0 = clean(img0, ker, stop_if_div=False, tol=0.1, mdl=area0)[0]
        B1 = clean(img1,
                   ker,
                   stop_if_div=False,
                   tol=1e-6,
                   mdl=np.array(area1, dtype=np.float32))[0]
        B2 = clean([img2] * 3, [ker] * 3,
                   stop_if_div=False,
                   tol=1e-9,
                   mdl=[np.array(area2, dtype=np.float32)] * 3)[0][1]
        for i in xrange(1024):
            self.assertEqual(A0[i], B0[i])

        for i in xrange(1024):
            self.assertEqual(A1[i], B1[i])

        for i in xrange(1024):
            self.assertEqual(A2[i], B2[i])
Ejemplo n.º 10
0
    def test_spike(self):
        ker = np.zeros(1024, dtype=np.float32)
        ker[0] = 1
        img = ker.copy()
        A, info = deconv.clean(img,
                               ker,
                               stop_if_div=True,
                               tol=0,
                               maxiter=int(1e4))

        B = clean(img, ker, stop_if_div=True, tol=0, maxiter=int(1e4))[0]

        for i in xrange(1024):
            self.assertEqual(A[i], B[i])
Ejemplo n.º 11
0
    def test_many(self):
        A0 = deconv.clean(img0, ker0, stop_if_div=False, tol=0)[0]
        A1 = deconv.clean(img1, ker1, stop_if_div=False, tol=0)[0]
        A2 = deconv.clean(img2, ker0, stop_if_div=False, tol=0)[0]
        A3 = deconv.clean(img3, ker1, stop_if_div=False, tol=0)[0]
        A4 = deconv.clean(img4, ker0, stop_if_div=False, tol=0)[0]
        A5 = deconv.clean(img5, ker1, stop_if_div=False, tol=0)[0]
        A6 = deconv.clean(img6, ker0, stop_if_div=False, tol=0)[0]
        A7 = deconv.clean(img7, ker1, stop_if_div=False, tol=0)[0]
        A8 = deconv.clean(img8, ker0, stop_if_div=False, tol=0)[0]

        B = clean(imgs, kers, stop_if_div=False, tol=0)[0]

        for i in xrange(1024):
            self.assertAlmostEqual(A5[i], B[5][i])
Ejemplo n.º 12
0
    def test_foregrounds(self):

        fqs = np.linspace(.1, .2, 1024, endpoint=False)
        lsts = np.linspace(0, 2 * np.pi, 10000, endpoint=False)
        bl_len_ns = 30.
        vis_fg_pntsrc = foregrounds.pntsrc_foreground(lsts,
                                                      fqs,
                                                      bl_len_ns,
                                                      nsrcs=200)
        img0 = np.array(vis_fg_pntsrc[100], dtype=np.float32)
        img1 = np.array(vis_fg_pntsrc[500], dtype=np.float32)
        img2 = np.array(vis_fg_pntsrc[700], dtype=np.float32)
        ker = np.ones(1024)

        A = set()
        while len(A) < 160:
            A.add(random.randint(0, 1024))
        for i in xrange(len(ker)):
            if i in A:
                ker[i] = 0

        ker = np.array(np.fft.fft(ker), dtype=np.float32)

        A0, info = deconv.clean(img0,
                                ker,
                                stop_if_div=True,
                                tol=0,
                                verbose=True)
        # A1 = deconv.clean(img1, ker, stop_if_div=True, tol=0)[0]
        # A2 = deconv.clean(img2, ker, stop_if_div=True, tol=0)[0]

        B0 = clean(img0, ker, stop_if_div=True, tol=0)[0]
        # B1 = clean(img1, ker, stop_if_div=True, tol=0)[0]
        # B2 = clean([img2]*3, [ker]*3, stop_if_div=False, tol=0)[0][1]

        for i in xrange(1024):
            self.assertEqual(A0[i], B0[i])
Ejemplo n.º 13
0
print s.time_till(e) / 1000, "s"

# s = cuda.Event()
# e = cuda.Event()
# s.record()
# deconv.clean(img2, ker, stop_if_div=False, tol=0, maxiter=100000)
# e.record()
# e.synchronize()
# print s.time_till(e), "ms"

print "MY CLEAN"

s = cuda.Event()
e = cuda.Event()
s.record()
clean([img1] * numImgs, [ker] * numImgs, stop_if_div=False, tol=0)
e.record()
e.synchronize()
print s.time_till(e) / 1000, "s"

s = cuda.Event()
e = cuda.Event()
s.record()
clean([img2] * numImgs, [ker] * numImgs, stop_if_div=False, tol=0)
e.record()
e.synchronize()
print s.time_till(e) / 1000, "s"

# ---REAL---
# 10 images