コード例 #1
0
ファイル: test_noise.py プロジェクト: JIANSHULI/hera_sim
 def test_resample_Tsky(self):
     fqs = np.linspace(0.1, 0.2, 100)
     lsts = np.linspace(0, 2 * np.pi, 200)
     tsky = noise.resample_Tsky(fqs, lsts)
     self.assertEqual(tsky.shape, (200, 100))
     self.assertTrue(np.all(tsky[0] == tsky[1]))
     self.assertFalse(np.all(tsky[:, 0] == tsky[:, 1]))
     # import uvtools, pylab as plt
     # uvtools.plot.waterfall(tsky); plt.show()
     tsky = noise.resample_Tsky(fqs, lsts, Tsky_mdl=noise.HERA_Tsky_mdl["xx"])
     self.assertEqual(tsky.shape, (200, 100))
     self.assertFalse(np.all(tsky[0] == tsky[1]))
     self.assertFalse(np.all(tsky[:, 0] == tsky[:, 1]))
コード例 #2
0
    def test_resample_Tsky(self):
        fqs = np.linspace(0.1, 0.2, 100)
        lsts = np.linspace(0, 2 * np.pi, 200)
        tsky = noise.resample_Tsky(fqs, lsts)
        self.assertEqual(tsky.shape, (200, 100))
        self.assertTrue(np.all(tsky[0] == tsky[1]))
        self.assertFalse(np.all(tsky[:, 0] == tsky[:, 1]))

        tsky = noise.resample_Tsky(fqs,
                                   lsts,
                                   Tsky_mdl=noise.HERA_Tsky_mdl["xx"])
        self.assertEqual(tsky.shape, (200, 100))
        self.assertFalse(np.all(tsky[0] == tsky[1]))
        self.assertFalse(np.all(tsky[:, 0] == tsky[:, 1]))
コード例 #3
0
 def test_sky_noise_jy(self):
     fqs = np.linspace(0.1, 0.2, 100)
     lsts = np.linspace(0, 2 * np.pi, 500)
     omp = noise.bm_poly_to_omega_p(fqs)
     tsky = noise.resample_Tsky(fqs, lsts)
     jy2T = noise.jy2T(fqs, omega_p=omp) / 1e3
     jy2T.shape = (1, -1)
     nos_jy = noise.sky_noise_jy(tsky, fqs, lsts, inttime=10.7, omega_p=omp)
     self.assertEqual(nos_jy.shape, (500, 100))
     np.testing.assert_allclose(np.average(nos_jy, axis=0), 0, atol=0.7)
     scaling = np.average(tsky, axis=0) / jy2T
     np.testing.assert_allclose(np.std(nos_jy, axis=0) / scaling *
                                np.sqrt(1e6 * 10.7),
                                1.0,
                                atol=0.1)
     np.random.seed(0)
     nos_jy = noise.sky_noise_jy(tsky, fqs, lsts, inttime=None, omega_p=omp)
     np.testing.assert_allclose(
         np.std(nos_jy, axis=0) / scaling *
         np.sqrt(1e6 * aipy.const.sidereal_day / 500),
         1.0,
         atol=0.1)
     np.random.seed(0)
     nos_jy = noise.sky_noise_jy(tsky,
                                 fqs,
                                 lsts,
                                 B=.1,
                                 inttime=10.7,
                                 omega_p=omp)
     np.testing.assert_allclose(np.std(nos_jy, axis=0) / scaling *
                                np.sqrt(1e8 * 10.7),
                                1.0,
                                atol=0.1)
コード例 #4
0
 def generate_noise(self):
     omega_p = noise.bm_poly_to_omega_p(self.fqs)
     tsky = noise.resample_Tsky(self.fqs,
                                self.lsts,
                                Tsky_mdl=noise.HERA_Tsky_mdl['xx'])
     t_rx = 150.
     return noise.sky_noise_jy(tsky + t_rx, self.fqs, self.lsts, omega_p)
コード例 #5
0
ファイル: SimEnviron.py プロジェクト: jkerrigan/hera_sim
    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
コード例 #6
0
for k, v in zip(idxs, ants):
    antpos[k] = v

reds = redcal.get_pos_reds(antpos)

# Extract all ants
ants = list(set([ant for bls in reds for bl in bls for ant in bl]))

# Generate gains
gains = sigchain.gen_gains(fqs, ants, dly_rng=(-1, 1))
true_vis, data = {}, {}

# Generate sky model--common for all ants
Tsky_mdl = noise.HERA_Tsky_mdl['xx']
tsky = noise.resample_Tsky(fqs, lsts, Tsky_mdl=noise.HERA_Tsky_mdl['xx'])

fp = h5py.File('fake_vis.hdf5', 'a')

fp.attrs.create('Nants', 37)
fp.create_dataset('fqs', data=fqs)
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,