Esempio n. 1
0
    def test_reflection_gains(self):
        # introduce a cable reflection into the autocorrelation
        gains = sigchain.gen_reflection_gains(self.freqs, [0], amp=[1e-1], dly=[300], phs=[1])
        outvis = sigchain.apply_gains(self.vis, gains, [0, 0])
        ovfft = np.fft.fft(
            outvis * windows.blackmanharris(len(self.freqs))[None, :], axis=1
        )

        # assert reflection is at +300 ns and check its amplitude
        select = self.dlys > 200
        nt.assert_almost_equal(
            self.dlys[select][np.argmax(np.mean(np.abs(ovfft), axis=0)[select])], 300
        )
        select = np.argmin(np.abs(self.dlys - 300))
        m = np.mean(np.abs(ovfft), axis=0)
        nt.assert_true(np.isclose(m[select] / m[0], 1e-1, atol=1e-2))

        # assert also reflection at -300 ns
        select = self.dlys < -200
        nt.assert_almost_equal(
            self.dlys[select][np.argmax(np.mean(np.abs(ovfft), axis=0)[select])], -300
        )
        select = np.argmin(np.abs(self.dlys - -300))
        m = np.mean(np.abs(ovfft), axis=0)
        nt.assert_true(np.isclose(m[select] / m[0], 1e-1, atol=1e-2))
Esempio n. 2
0
    def test_reflection_gains(self):
        # introduce a cable reflection into the autocorrelation
        gains = sigchain.gen_reflection_gains(self.freqs, [0],
                                              amp=[1e-1],
                                              dly=[300],
                                              phs=[1])
        outvis = sigchain.apply_gains(self.vis, gains, [0, 0])
        ovfft = np.fft.fft(outvis *
                           windows.blackmanharris(len(self.freqs))[None, :],
                           axis=1)

        # assert reflection is at +300 ns and check its amplitude
        select = self.dlys > 200
        nt.assert_almost_equal(
            self.dlys[select][np.argmax(
                np.mean(np.abs(ovfft), axis=0)[select])], 300)
        select = np.argmin(np.abs(self.dlys - 300))
        m = np.mean(np.abs(ovfft), axis=0)
        nt.assert_true(np.isclose(m[select] / m[0], 1e-1, atol=1e-2))

        # assert also reflection at -300 ns
        select = self.dlys < -200
        nt.assert_almost_equal(
            self.dlys[select][np.argmax(
                np.mean(np.abs(ovfft), axis=0)[select])], -300)
        select = np.argmin(np.abs(self.dlys - -300))
        m = np.mean(np.abs(ovfft), axis=0)
        nt.assert_true(np.isclose(m[select] / m[0], 1e-1, atol=1e-2))

        # test reshaping into Ntimes
        amp = np.linspace(1e-2, 1e-3, 3)
        gains = sigchain.gen_reflection_gains(self.freqs, [0],
                                              amp=[amp],
                                              dly=[300],
                                              phs=[1])
        nt.assert_equal(gains[0].shape, (3, 100))

        # test frequency evolution with one time
        amp = np.linspace(1e-2, 1e-3, 100).reshape(1, -1)
        gains = sigchain.gen_reflection_gains(self.freqs, [0],
                                              amp=[amp],
                                              dly=[300],
                                              phs=[1])
        nt.assert_equal(gains[0].shape, (1, 100))
        # now test with multiple times
        amp = np.repeat(np.linspace(1e-2, 1e-3, 100).reshape(1, -1),
                        10,
                        axis=0)
        gains = sigchain.gen_reflection_gains(self.freqs, [0],
                                              amp=[amp],
                                              dly=[300],
                                              phs=[1])
        nt.assert_equal(gains[0].shape, (10, 100))

        # exception
        amp = np.linspace(1e-2, 1e-3, 2).reshape(1, -1)
        nt.assert_raises(AssertionError,
                         sigchain.gen_reflection_gains,
                         self.freqs, [0],
                         amp=[amp],
                         dly=[300],
                         phs=[1])
Esempio n. 3
0
 def test_apply_gains(self):
     fqs = np.linspace(0.12, 0.18, 1024, endpoint=False)
     vis = np.ones((100, fqs.size), dtype=np.complex)
     g = sigchain.gen_gains(fqs, [1, 2], gain_spread=0, dly_rng=(10, 10))
     gvis = sigchain.apply_gains(vis, g, (1, 2))
     np.testing.assert_allclose(np.angle(gvis), 0, 1e-5)
Esempio n. 4
0
 def generate_gains(self, vis):
     return sigchain.apply_gains(vis, self.g, (1, 2))
Esempio n. 5
0
    def gen_HERA_vis(self,
                     tsamples,
                     fsamples,
                     bl_len_ns=400.,
                     add_rfi=False,
                     inject_frb=False):
        #### Convert time samples to appropriate LST hours where 60 time samples = 10 min
        #### !!!! LST is in rads not hrs
        sph = 60. / .1667
        lst_add = tsamples / sph
        fqs = np.linspace(.1, .2, fsamples, endpoint=False)
        lsts = np.linspace(np.pi / 2., np.pi / 2. + lst_add, tsamples)
        times = lsts / (2. * np.pi) * a.const.sidereal_day

        #### FOREGROUNDS ####
        # Diffuse
        Tsky_mdl = noise.HERA_Tsky_mdl['xx']
        vis_fg_diffuse = foregrounds.diffuse_foreground(
            Tsky_mdl, lsts, fqs, bl_len_ns)
        # Point Sources
        vis_fg_pntsrc = foregrounds.pntsrc_foreground(lsts,
                                                      fqs,
                                                      bl_len_ns,
                                                      nsrcs=1000)
        # FRBs
        vis_fg_frb = np.asarray(gen_simulated_frb(NFREQ=1024,
                                                  NTIME=61,
                                                  width=1.,
                                                  sim=True,
                                                  delta_t=10.,
                                                  freq=(200, 100),
                                                  FREQ_REF=150.,
                                                  fluence=(60., 600.),
                                                  scintillate=True,
                                                  dm=(300., 1800.))[0].T,
                                dtype=np.complex128)
        vis_fg_frb *= np.exp(
            1j * (lsts[30] + .1 * np.pi * np.random.randn(61, 1024)))
        # Combined
        if inject_frb:
            vis_fg = vis_fg_diffuse + vis_fg_pntsrc + vis_fg_frb
        else:
            vis_fg = vis_fg_diffuse + vis_fg_pntsrc
        #### Noise ####
        tsky = noise.resample_Tsky(fqs,
                                   lsts,
                                   Tsky_mdl=noise.HERA_Tsky_mdl['xx'])
        t_rx = 150.
        nos_jy = noise.sky_noise_jy(tsky + t_rx, fqs, lsts)
        # Add Noise
        vis_fg_nos = vis_fg + nos_jy

        #### RFI ####
        if add_rfi:
            g = sigchain.gen_gains(fqs, [1, 2, 3])
            with open(add_rfi, 'r') as infile:
                RFIdict = yaml.load(infile)
            rfi = RFI_Sim(RFIdict)
            rfi.applyRFI()
            self.rfi_true = rfi.getFlags()
            vis_fg_nos_rfi = np.copy(vis_fg_nos) + rfi.getRFI()
            vis_total_rfi = sigchain.apply_gains(vis_fg_nos_rfi, g, (1, 2))
            # add cross-talk
            xtalk = sigchain.gen_xtalk(np.linspace(.1, .2, 1024),
                                       amplitude=.001)
            vis_total_rfi = sigchain.apply_xtalk(vis_total_rfi, xtalk)
            self.data_rfi = vis_total_rfi
        else:
            g = sigchain.gen_gains(fqs, [1, 2, 3])
            vis_total_norfi = sigchain.apply_gains(vis_fg_nos, g, (1, 2))
            self.data = vis_total_norfi
fp.create_dataset('lsts', data=lsts)

for a in ants:
    fp.create_dataset('g%d' % a, data=gains[a])

for bls in reds:
    for (i, j) in bls:
        data[(i, j)] = fp.create_dataset('%d-%d' % (i, j),
                                         (len(lsts), len(fqs)),
                                         chunks=True,
                                         dtype='complex64')

for bls in reds:
    bl_len = get_distance(bls[0], antpos)
    bl_len_ns = bl_len / aipy.const.c * 1e11
    vis_fg_pntsrc = foregrounds.pntsrc_foreground(lsts,
                                                  fqs,
                                                  bl_len_ns,
                                                  nsrcs=200)
    vis_fg_diffuse = foregrounds.diffuse_foreground(Tsky_mdl, lsts, fqs,
                                                    bl_len_ns)
    true_vis[bls[0]] = vis_fg_pntsrc + vis_fg_diffuse

    for (i, j) in bls:
        print(i, j)
        nos_jy = noise.sky_noise_jy(tsky + 150., fqs, lsts)
        vis_tot = nos_jy + true_vis[bls[0]]
        data[(i, j)][:, :] = sigchain.apply_gains(vis_tot, gains, (i, j))

fp.close()
 def generate_gains(self, vis):
     gainscale = np.average([np.median(np.abs(g[i])) for i in g])
     MXG = MX + np.log10(gainscale)
     return sigchain.apply_gains(vis, g, (1, 2))