Exemplo n.º 1
0
    def test_small(self):

        NANT = 16
        antpos = np.array(rand(NANT, 3), dtype=np.float32)
        eq2tops = np.array(rand(NTIMES, 3, 3), dtype=np.float32)
        crd_eq = np.array(rand(3, NPIX), dtype=np.float32)
        I_sky = np.array(rand(NPIX), dtype=np.float32)
        bm_cube = np.array(rand(NANT, BM_PIX, BM_PIX), dtype=np.float32)
        freq = np.array(rand(1), dtype=np.float32)[0]

        t = time.time()
        v_gpu = vis.vis_gpu(antpos,
                            freq,
                            eq2tops,
                            crd_eq,
                            I_sky,
                            bm_cube,
                            precision=2)
        print("SMALL GPU TIME (FLOAT):", time.time() - t, "s")

        t = time.time()
        v_cpu = vis_cpu(antpos,
                        freq,
                        eq2tops,
                        crd_eq,
                        I_sky,
                        bm_cube,
                        real_dtype=np.float64,
                        complex_dtype=np.complex128)
        print("SMALL CPU TIME (FLOAT):", time.time() - t, "s")
        print("MAX REL DIFFERENCE", max_rel_diff(v_gpu, v_cpu))

        antpos = np.array(rand(NANT, 3), dtype=np.float64)
        eq2tops = np.array(rand(NTIMES, 3, 3), dtype=np.float64)
        crd_eq = np.array(rand(3, NPIX), dtype=np.float64)
        I_sky = np.array(rand(NPIX), dtype=np.float64)
        bm_cube = np.array(rand(NANT, BM_PIX, BM_PIX), dtype=np.float64)
        freq = np.array(rand(1), dtype=np.float64)[0]

        t = time.time()
        v_gpu = vis.vis_gpu(antpos,
                            freq,
                            eq2tops,
                            crd_eq,
                            I_sky,
                            bm_cube,
                            precision=2)
        print("SMALL GPU TIME (DOUBLE):", time.time() - t, "s")

        t = time.time()
        v_cpu = vis_cpu(antpos,
                        freq,
                        eq2tops,
                        crd_eq,
                        I_sky,
                        bm_cube,
                        real_dtype=np.float64,
                        complex_dtype=np.complex128)
        print("SMALL CPU TIME (DOUBLE):", time.time() - t, "s")
        print("MAX REL DIFFERENCE", max_rel_diff(v_gpu, v_cpu))
Exemplo n.º 2
0
    def test_hera_350(self):
        NANT = 350

        NPIX = int(3.14159 * 10**5)

        antpos = np.array(rand(NANT, 3), dtype=np.float32)
        eq2tops = np.array(rand(NTIMES, 3, 3), dtype=np.float32)
        crd_eq = np.array(rand(3, NPIX), dtype=np.float32)
        I_sky = np.array(rand(NPIX), dtype=np.float32)
        bm_cube = np.array(rand(NANT, BM_PIX, BM_PIX), dtype=np.float32)
        freq = np.array(rand(1), dtype=np.float32)[0]

        t = time.time()
        v_gpu = vis.vis_gpu(antpos, freq, eq2tops, crd_eq, I_sky, bm_cube)
        print("350 ANTS, PI*10^5 PIX GPU TIME (FLOAT):", time.time() - t, "s")

        t = time.time()
        v_cpu = vis_cpu(antpos, freq, eq2tops, crd_eq, I_sky, bm_cube)
        print("350 ANTS, PI*10^5 PIX CPU TIME (FLOAT):", time.time() - t, "s")
        print("MAX REL DIFFERENCE", max_rel_diff(v_gpu, v_cpu))

        antpos = np.array(rand(NANT, 3), dtype=np.float64)
        eq2tops = np.array(rand(NTIMES, 3, 3), dtype=np.float64)
        crd_eq = np.array(rand(3, NPIX), dtype=np.float64)
        I_sky = np.array(rand(NPIX), dtype=np.float64)
        bm_cube = np.array(rand(NANT, BM_PIX, BM_PIX), dtype=np.float64)
        freq = np.array(rand(1), dtype=np.float64)[0]

        t = time.time()
        v_gpu = vis.vis_gpu(antpos,
                            freq,
                            eq2tops,
                            crd_eq,
                            I_sky,
                            bm_cube,
                            precision=2)
        print("350 ANTS, PI*10^5 PIX GPU TIME (DOUBLE):", time.time() - t, "s")

        t = time.time()
        v_cpu = vis_cpu(antpos,
                        freq,
                        eq2tops,
                        crd_eq,
                        I_sky,
                        bm_cube,
                        real_dtype=np.float64,
                        complex_dtype=np.complex128)
        print("350 ANTS, PI*10^5 CPU TIME (DOUBLE):", time.time() - t, "s")
        print("MAX REL DIFFERENCE", max_rel_diff(v_gpu, v_cpu))
Exemplo n.º 3
0
 def test_compare_phase(self):
     for i in range(NTIMES):
         antpos = np.array(rand(NANT, 3), dtype=np.float32)
         eq2tops = np.array(rand(NTIMES, 3, 3), dtype=np.float32)
         crd_eq = np.array(rand(3, NPIX), dtype=np.float32)
         I_sky = np.array(rand(NPIX), dtype=np.float32)
         bm_cube = np.array(rand(NANT, BM_PIX, BM_PIX), dtype=np.float32)
         freq = float(rand(1)[0])
         for precision in (1, 2):
             v = vis_gpu(antpos,
                         freq,
                         eq2tops,
                         crd_eq,
                         I_sky,
                         bm_cube,
                         precision=precision)
             v_CPU = vis_cpu(antpos,
                             freq,
                             eq2tops,
                             crd_eq,
                             I_sky,
                             bm_cube,
                             precision=precision)
             phase_diff = np.abs(np.angle(v) - np.angle(v_CPU))
             if precision == 2:
                 self.assertLess(np.median(phase_diff), 1e-4)
             else:
                 self.assertLess(np.median(phase_diff), 1e-2)
Exemplo n.º 4
0
 def test_dtypes(self):
     antpos = np.zeros((NANT, 3))
     eq2tops = np.zeros((NTIMES, 3, 3))
     crd_eq = np.zeros((3, NPIX))
     I_sky = np.zeros(NPIX)
     bm_cube = np.zeros((NANT, BM_PIX, BM_PIX))
     for precision, cdtype in zip((1, 2), (np.complex64, np.complex128)):
         v = vis_gpu(antpos,
                     0.15,
                     eq2tops,
                     crd_eq,
                     I_sky,
                     bm_cube,
                     precision=precision)
         self.assertEqual(v.dtype, cdtype)
Exemplo n.º 5
0
 def test_shapes(self):
     antpos = np.zeros((NANT, 3))
     eq2tops = np.zeros((NTIMES, 3, 3))
     crd_eq = np.zeros((3, NPIX))
     I_sky = np.zeros(NPIX)
     bm_cube = np.zeros((NANT, BM_PIX, BM_PIX))
     v = vis_gpu(antpos, 0.15, eq2tops, crd_eq, I_sky, bm_cube)
     self.assertEqual(v.shape, (NTIMES, NANT, NANT))
     self.assertRaises(AssertionError, vis_gpu, antpos.T, 0.15, eq2tops,
                       crd_eq, I_sky, bm_cube)
     self.assertRaises(AssertionError, vis_gpu, antpos, 0.15, eq2tops.T,
                       crd_eq, I_sky, bm_cube)
     self.assertRaises(AssertionError, vis_gpu, antpos, 0.15, eq2tops,
                       crd_eq.T, I_sky, bm_cube)
     self.assertRaises(AssertionError, vis_gpu, antpos, 0.15, eq2tops,
                       crd_eq, I_sky, bm_cube.T)
Exemplo n.º 6
0
    def test_values(self):
        antpos = np.ones((NANT, 3))
        eq2tops = np.array([np.identity(3)] * NTIMES)
        crd_eq = np.zeros((3, NPIX))
        crd_eq[2] = 1
        I_sky = np.ones(NPIX)
        bm_cube = np.ones((NANT, BM_PIX, BM_PIX))
        for precision in (1, 2):
            # Make sure that a zero in sky or beam gives zero output
            v = vis_gpu(antpos,
                        1.0,
                        eq2tops,
                        crd_eq,
                        I_sky * 0,
                        bm_cube,
                        precision=precision)
            np.testing.assert_equal(v, 0)
            v = vis_gpu(antpos,
                        1.0,
                        eq2tops,
                        crd_eq,
                        I_sky,
                        bm_cube * 0,
                        precision=precision)
            np.testing.assert_equal(v, 0)
            # For co-located ants & sources on sky, answer should be sum of pixels
            v = vis_gpu(antpos,
                        1.0,
                        eq2tops,
                        crd_eq,
                        I_sky,
                        bm_cube,
                        precision=precision)
            np.testing.assert_almost_equal(v, NPIX, 22)

        # For co-located ants & two sources separated on sky, answer should still be sum
        crd_eq = np.zeros((3, 2))
        crd_eq[2, 0] = 1
        crd_eq[1, 1] = np.sqrt(0.5)
        crd_eq[2, 1] = np.sqrt(0.5)
        I_sky = np.ones(2)
        for precision in (1, 2):
            v = vis_gpu(antpos,
                        1.0,
                        eq2tops,
                        crd_eq,
                        I_sky,
                        bm_cube,
                        precision=precision)
            np.testing.assert_almost_equal(v, 2, 2)
        # For ant[0] at (0,0,1), ant[1] at (1,1,1), src[0] at (0,0,1) and src[1] at (0,.707,.707)
        antpos[0, 0] = 0
        antpos[0, 1] = 0
        for precision in (1, 2):
            v_CPU = vis_cpu(antpos,
                            1.0,
                            eq2tops,
                            crd_eq,
                            I_sky,
                            bm_cube,
                            precision=precision)
            v = vis_gpu(antpos,
                        1.0,
                        eq2tops,
                        crd_eq,
                        I_sky,
                        bm_cube,
                        precision=precision)
            if precision == 1:
                np.testing.assert_almost_equal(v, v_CPU, 5)
            else:
                np.testing.assert_almost_equal(v, v_CPU, 15)