def RMclean1(fq, spec, gain=0.1, tol=1e-3, stop_if_div=False, maxiter=10000, verbose=True, pos_def=False, window='hamming'): RMs, W = RMTmat(fq, window) rm_spec = RMT(spec, W) ker_spec = RMT(np.ones_like(spec), W) mod, info = deconv.clean(rm_spec, ker_spec, gain=gain, maxiter=maxiter, tol=tol, stop_if_div=stop_if_div, verbose=verbose) W = iRMTmat(fq, window) mod_spec = iRMT(mod, W) res_spec = iRMT(info['res'], W) return mod_spec, res_spec
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])
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])
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])
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] 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] 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])
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])
def test_stop_if_div(self): A0 = deconv.clean(img0, ker, stop_if_div=True, tol=0.1)[0] A1 = deconv.clean(img1, ker, stop_if_div=True, tol=1e-6)[0] A2 = deconv.clean(img2, ker, stop_if_div=True, tol=1e-9)[0] A3 = deconv.clean(img3, ker128, stop_if_div=True, tol=1e-6)[0] B0 = clean(img0, ker, stop_if_div=True, tol=0.1)[0] B1 = clean(img1, ker, stop_if_div=True, tol=1e-6)[0] B2 = clean([img2] * 3, [ker] * 3, stop_if_div=True, tol=1e-9)[0][1] B3 = clean(img3, ker128, stop_if_div=True, tol=1e-6)[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])
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])
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])
ker = np.fft.fft(ker) ker = np.array(ker, dtype=data_type) numImgs = 10 # numImgs = 4096 print numImgs, data_type, "Images" print "AIPY CLEAN" s = cuda.Event() e = cuda.Event() s.record() for i in xrange(numImgs): deconv.clean(img1, ker, 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() deconv.clean(img2, ker, 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()