Ejemplo n.º 1
0
 def test_gen_gains(self):
     fqs = np.linspace(0.12, 0.18, 1024, endpoint=False)
     g = sigchain.gen_gains(fqs, [1, 2], gain_spread=0, dly_rng=(10, 20))
     np.testing.assert_allclose(np.abs(g[1]), np.abs(g[2]), 1e-5)
     for i in g:
         p = np.polyfit(fqs, np.unwrap(np.angle(g[i])), deg=1)
         self.assertAlmostEqual(p[-1] % (2 * np.pi), 0.0, -2)
         self.assertLessEqual(p[0], 20 * 2 * np.pi)
         self.assertGreaterEqual(p[0], 10 * 2 * np.pi)
Ejemplo n.º 2
0
    def __init__(self):
        self.fqs = np.linspace(.1, .2, 64, endpoint=False)
        self.lsts = np.linspace(0, 2 * np.pi, 256, endpoint=False)
        self.times = self.lsts / (2 * np.pi) * aipy.const.sidereal_day
        self.bl_len_ns_list = [5, 10, 20, 100, 500]
        self.n_sources_list = [1, 10, 50, 200, 1000]

        self.MX, self.DRNG = 2.5, 3
        self.Tsky_mdl = noise.HERA_Tsky_mdl['xx']
        self.g = sigchain.gen_gains(self.fqs, [100, 2, 3])

        r = np.random.randint(0, 5)
        self.bl_len_ns = self.bl_len_ns_list[r]
        #self.bl_len_ns = self.bl_len_ns_list[3]
        #self.n_sources = self.n_sources_list[np.random.randint(0,5)]
        self.n_sources = self.n_sources_list[3]
Ejemplo 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)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
## Generate visibilities for all redundant baselines in array.
ants = np.loadtxt('antenna_positions_37.dat')
idxs = np.arange(37)
antpos = {}

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])
import datetime
import random
import pickle
from tqdm import tqdm
import pandas as pd
from preprocessor import preprocessor

fqs = np.linspace(.1, .2, 64, endpoint=False)
lsts = np.linspace(0, 2 * np.pi, 256, endpoint=False)
times = lsts / (2 * np.pi) * aipy.const.sidereal_day
bl_len_ns_list = [
    1, 2, 5, 10, 20, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000
]
MX, DRNG = 2.5, 3
Tsky_mdl = noise.HERA_Tsky_mdl['xx']
g = sigchain.gen_gains(fqs, [1, 2, 3])


class HERA_generator():
    def __init__(self):
        self.bl_len_ns = bl_len_ns_list[random.randint(0,
                                                       len(bl_len_ns_list) -
                                                       1)]
        self.nsrcs = random.randint(1, 1001)

    def generate_diffuse_foreground(self):
        return foregrounds.diffuse_foreground(
            lsts, fqs, self.bl_len_ns, Tsky_mdl=Tsky_mdl) / 40

    def generate_point_source(self):
        return foregrounds.pntsrc_foreground(lsts,