Ejemplo n.º 1
0
def gen_eor_mdl(ks,
                Pk,
                shape,
                fq_axis=1,
                fq0=.1,
                fq1=.2,
                bm_eff=HERA_BM_EFF_150,
                bm_nos=HERA_BM_NOS_150,
                kpr=.06):
    fqs = np.linspace(fq0, fq1, shape[fq_axis])  # GHz
    B = fq1 - fq0  # GHz
    z = capo.pspec.f2z(np.average(fqs))
    scalar = capo.pspec.X2Y(z) * bm_eff * B
    mdl = scipy.interpolate.interp1d(ks, Pk, bounds_error=False, fill_value=0)
    etas = np.fft.fftfreq(fqs.size, fqs[1] - fqs[0])
    kpls = etas * capo.pspec.dk_deta(z)
    ks = np.sqrt(kpls**2 + kpr**2)
    Pk = mdl(ks)
    dspec_amp = np.sqrt(Pk / scalar)
    sh = [1] * len(shape)
    sh[fq_axis] = -1
    dspec_amp.shape = sh
    jy2mK_HERA = jy2T(fqs, bm=bm_nos)
    jy2mK_HERA.shape = sh
    vis = oqe.noise(shape).astype(np.complex128) * dspec_amp
    vis_mK = np.fft.fft(vis, axis=fq_axis)
    vis_Jy = vis_mK / jy2mK_HERA
    return vis_Jy
Ejemplo n.º 2
0
 def test_q_eor_nocov(self):
     k1, k2 = ('a', (0, 1), 'I'), ('b', (0, 1), 'I')
     ds = oqe.DataSet({k1: self.eor, k2: self.eor})
     q = ds.q_hat(k1, k2, use_cov=False)
     self.assertTrue(np.all(q > 0))
     self.assertAlmostEqual(np.average(q).real, q.shape[0], 0)
     n1, n2 = oqe.noise(self.eor.shape), oqe.noise(self.eor.shape)
     ds = oqe.DataSet({k1: self.eor + n1, k2: self.eor + n2})
     qn = ds.q_hat(k1, k2, use_cov=False)
     self.assertFalse(np.all(qn > 0))
     self.assertAlmostEqual(np.average(qn).real, qn.shape[0], 0)
     self.assertAlmostEqual(np.average(qn).real, np.average(q).real, 0)
     ds = oqe.DataSet({k1: n1, k2: n2})
     qn = ds.q_hat(k1, k2, use_cov=False)
     self.assertFalse(np.all(qn > 0))
     self.assertAlmostEqual(np.average(qn).real, 0, 0)
Ejemplo n.º 3
0
 def test_q_eor_nocov(self):
     k1,k2 = ('a',(0,1),'I'), ('b',(0,1),'I')
     ds = oqe.DataSet({k1:self.eor, k2:self.eor})
     q = ds.q_hat(k1,k2,use_cov=False)
     self.assertTrue(np.all(q > 0))
     self.assertAlmostEqual(np.average(q).real, q.shape[0], 0)
     n1,n2 = oqe.noise(self.eor.shape), oqe.noise(self.eor.shape)
     ds = oqe.DataSet({k1:self.eor+n1, k2:self.eor+n2})
     qn = ds.q_hat(k1,k2,use_cov=False)
     self.assertFalse(np.all(qn > 0))
     self.assertAlmostEqual(np.average(qn).real, qn.shape[0], 0)
     self.assertAlmostEqual(np.average(qn).real, np.average(q).real, 0)
     ds = oqe.DataSet({k1:n1, k2:n2})
     qn = ds.q_hat(k1,k2,use_cov=False)
     self.assertFalse(np.all(qn > 0))
     self.assertAlmostEqual(np.average(qn).real, 0, 0)
Ejemplo n.º 4
0
 def setUpClass(self):
     NFREQ = 32
     NSAMP = 1024
     fq = np.exp(1j*np.linspace(0,2*np.pi,NFREQ)); fq.shape = (1,-1)
     ts = np.exp(1j*np.linspace(0,2*np.pi,NSAMP+1)[:-1]); ts.shape = (-1,1)
     self.sky = fq * ts
     self.eor = oqe.noise(size=(NSAMP,NFREQ))
     sets = ['even','odd']
     bls = [(0,1),(1,2),(2,3),(3,4),(4,5)]
     pols = 'I'
     self.data = {}
     for s in sets:
         self.data[s] = {}
         for bl in bls:
             self.data[s][bl] = {}
             for pol in pols:
                 self.data[s][bl][pol] = self.sky + self.eor + oqe.noise((NSAMP,NFREQ))
Ejemplo n.º 5
0
def frf(shape,loc=0,scale=1): #FRF NOISE
    shape = shape[1]*2,shape[0] #(2*times,freqs)
    dij = oqe.noise(size=shape)
    wij = n.ones(shape,dtype=bool) #XXX flags are all true (times,freqs)
    #dij and wij are (times,freqs)
    _d,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir)
    _d = n.transpose(_d)
    _d = _d[:,shape[0]/4:shape[0]/2+shape[0]/4]
    return _d
Ejemplo n.º 6
0
def frf(shape,loc=0,scale=1): #FRF NOISE
    shape = shape[1]*2,shape[0] #(2*times,freqs)
    dij = oqe.noise(size=shape)
    wij = n.ones(shape,dtype=bool) #XXX flags are all true (times,freqs)
    #dij and wij are (times,freqs)
    _d,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir)
    _d = n.transpose(_d)
    _d = _d[:,shape[0]/4:shape[0]/2+shape[0]/4]
    return _d
Ejemplo n.º 7
0
 def setUpClass(self):
     NFREQ = 32
     NSAMP = 1024
     fq = np.exp(1j * np.linspace(0, 2 * np.pi, NFREQ))
     fq.shape = (1, -1)
     ts = np.exp(1j * np.linspace(0, 2 * np.pi, NSAMP + 1)[:-1])
     ts.shape = (-1, 1)
     self.sky = fq * ts
     self.eor = oqe.noise(size=(NSAMP, NFREQ))
     sets = ['even', 'odd']
     bls = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5)]
     pols = 'I'
     self.data = {}
     for s in sets:
         self.data[s] = {}
         for bl in bls:
             self.data[s][bl] = {}
             for pol in pols:
                 self.data[s][bl][pol] = self.sky + self.eor + oqe.noise(
                     (NSAMP, NFREQ))
Ejemplo n.º 8
0
def frf(shape,loc=0,scale=1):
    shape = shape[1]*2,shape[0] #(2*times,freqs)
    dij = noise(shape,loc=loc,scale=scale)
    dij = oqe.noise(shape)
    #bins = fringe.gen_frbins(inttime)
    #frp, bins = fringe.aa_to_fr_profile(aa, ij, len(afreqs)/2, bins=bins)
    #timebins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[len(afreqs)/2])
    #_,blconj,_ = zsa.grid2ij(aa.ant_layout)
    #if blconj[a.miriad.ij2bl(ij[0],ij[1])]: fir = {(ij[0],ij[1],POL):n.conj(firs)}
    #else: fir = {(ij[0],ij[1],POL):firs}
    wij = n.ones(shape,dtype=bool) #XXX flags are all true (times,freqs)
    #dij and wij are (times,freqs)
    _d,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir)
    _d = n.transpose(_d)
    _d = _d[:,shape[0]/4:shape[0]/2+shape[0]/4]
    return _d
Ejemplo n.º 9
0
def frf(shape,loc=0,scale=1):
    shape = shape[1]*2,shape[0] #(2*times,freqs)
    dij = noise(shape,loc=loc,scale=scale)
    dij = oqe.noise(shape)
    #bins = fringe.gen_frbins(inttime)
    #frp, bins = fringe.aa_to_fr_profile(aa, ij, len(afreqs)/2, bins=bins)
    #timebins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[len(afreqs)/2])
    #_,blconj,_ = zsa.grid2ij(aa.ant_layout)
    #if blconj[a.miriad.ij2bl(ij[0],ij[1])]: fir = {(ij[0],ij[1],POL):n.conj(firs)}
    #else: fir = {(ij[0],ij[1],POL):firs}
    wij = n.ones(shape,dtype=bool) #XXX flags are all true (times,freqs)
    #dij and wij are (times,freqs)
    _d,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir)
    _d = n.transpose(_d)
    _d = _d[:,shape[0]/4:shape[0]/2+shape[0]/4]
    return _d
Ejemplo n.º 10
0
def gen_eor_mdl(ks, Pk, shape, fq_axis=1, fq0=.1, fq1=.2, bm_eff=HERA_BM_EFF_150, bm_nos=HERA_BM_NOS_150, kpr=.06):
    fqs = np.linspace(fq0,fq1,shape[fq_axis]) # GHz
    B = fq1 - fq0 # GHz
    z = capo.pspec.f2z(np.average(fqs))
    scalar = capo.pspec.X2Y(z) * bm_eff * B
    mdl = scipy.interpolate.interp1d(ks, Pk, bounds_error=False, fill_value=0)
    etas = np.fft.fftfreq(fqs.size, fqs[1]-fqs[0])
    kpls = etas * capo.pspec.dk_deta(z)
    ks = np.sqrt(kpls**2 + kpr**2)
    Pk = mdl(ks)
    dspec_amp = np.sqrt(Pk / scalar)
    sh = [1] * len(shape); sh[fq_axis] = -1
    dspec_amp.shape = sh
    jy2mK_HERA = jy2T(fqs, bm=bm_nos); jy2mK_HERA.shape = sh
    vis = oqe.noise(shape).astype(np.complex128) * dspec_amp
    vis_mK = np.fft.fft(vis, axis=fq_axis)
    vis_Jy = vis_mK / jy2mK_HERA
    return vis_Jy
Ejemplo n.º 11
0
#! /usr/bin/env python
import numpy as np, pylab as plt
import capo, aipy
import capo.oqe as oqe
import sys

CH0,NCHAN = 30, 61
NSAMP = 120

for i in xrange(10):
    e = oqe.noise(size=(NCHAN,NSAMP))
    v = oqe.noise(size=(NCHAN,NSAMP))
    r = e + v
    
    k = ('even',(0,1),'I')
    k1 = ('e',(0,1),'I')
    k2 = ('v',(0,1),'I')
    ds = oqe.DataSet(dsets={k:r.T[:-20]})
    print i, np.linalg.cond(ds.C(k))
    iC_r = ds.iC(k)
    ds.set_data({k:e.T}); q_e = ds.q_hat(k,k)
    ds.set_data({k:v.T}); q_v = ds.q_hat(k,k)
    ds.set_data({k:r.T}); q_r = ds.q_hat(k,k)
    F = ds.get_F(k,k)
    ds.set_data({k1:e.T, k2:v.T})
    ds.set_iC({k1:iC_r, k2:iC_r})
    q_ev = ds.q_hat(k1,k2)
    (M,W) = ds.get_MW(F)
    p_e = ds.p_hat(M,q_e)
    p_v = ds.p_hat(M,q_v)
    p_r = ds.p_hat(M,q_r)
Ejemplo n.º 12
0
    n.savez(outpath, kpl=kpl, scalar=scalar, times=n.array(lsts),
        pk_vs_t=pC, err_vs_t=1./cnt, temp_noise_var=var, nocov_vs_t=pI,
        afreqs=afreqs,chans=chans,cmd=' '.join(sys.argv))

    #XXX Overwriting to new variables
    pCv = pC.copy()
    pIv = pI
    
    ### Loop to calculate pC of (data/noise+eor) and pI of eor ###
    print '   Getting pCr and pIe'

    if INJECT_SIG > 0.: #Create a fake EoR signal to inject
        print '     INJECTING SIMULATED SIGNAL'
        eor = (frf((len(chans),timelen),loc=0,scale=1) * INJECT_SIG).T #create FRF-ered noise
        if opts.nofrf:
            eor = (oqe.noise((len(chans),timelen))*INJECT_SIG).T #not FRF-ed
        data_dict_2 = {}
        data_dict_eor = {}
        for key in data_dict:
            data_dict_2[key] = data_dict[key].copy() + eor.copy() #add injected signal to data
            data_dict_eor[key] = eor.copy()

    #Set data
    ds2 = oqe.DataSet() #data + eor
    ds2.set_data(dsets=data_dict_2,conj=conj_dict,wgts=flg_dict)
    dse = oqe.DataSet() #just eor   
    dse.set_data(dsets=data_dict_eor,conj=conj_dict,wgts=flg_dict)
   
    #Change C if wanted
    if opts.changeC:
        if opts.otherbls != None:
Ejemplo n.º 13
0
#! /usr/bin/env python
import numpy as np, pylab as plt
import capo, aipy
import capo.oqe as oqe
import sys

CH0, NCHAN = 30, 61
NSAMP = 120

for i in xrange(10):
    e = oqe.noise(size=(NCHAN, NSAMP))
    v = oqe.noise(size=(NCHAN, NSAMP))
    r = e + v

    k = ('even', (0, 1), 'I')
    k1 = ('e', (0, 1), 'I')
    k2 = ('v', (0, 1), 'I')
    ds = oqe.DataSet(dsets={k: r.T[:-20]})
    print i, np.linalg.cond(ds.C(k))
    iC_r = ds.iC(k)
    ds.set_data({k: e.T})
    q_e = ds.q_hat(k, k)
    ds.set_data({k: v.T})
    q_v = ds.q_hat(k, k)
    ds.set_data({k: r.T})
    q_r = ds.q_hat(k, k)
    F = ds.get_F(k, k)
    ds.set_data({k1: e.T, k2: v.T})
    ds.set_iC({k1: iC_r, k2: iC_r})
    q_ev = ds.q_hat(k1, k2)
    (M, W) = ds.get_MW(F)
Ejemplo n.º 14
0
            ij[0], ij[1]
    )]:  #makes sure FRP will be the same whether bl is a conjugated one or not
        if ij[0] < ij[1]:
            temp = (ij[1], ij[0])
            ij = temp
    timelen = data_dict[keys[0]].shape[0]
    bins = fringe.gen_frbins(inttime)
    frp, bins = fringe.aa_to_fr_profile(aa, ij, len(afreqs) / 2, bins=bins)
    timebins, firs = fringe.frp_to_firs(frp,
                                        bins,
                                        aa.get_freqs(),
                                        fq0=aa.get_freqs()[len(afreqs) / 2])
    fir = {(ij[0], ij[1], POL): firs}
    if opts.same and opts.frf:
        NOISE = frf((len(chans), timelen))  #same noise on all bls
    if opts.same and opts.frf == None: NOISE = oqe.noise((len(chans), timelen))
    for key in data_dict:
        if opts.same: thing = NOISE.T
        if opts.diff and opts.frf: thing = frf((len(chans), timelen)).T
        if opts.diff and opts.frf == None:
            thing = oqe.noise((len(chans), timelen)).T
        if blconj[a.miriad.ij2bl(key[1][0], key[1][1])]:
            data_dict[key] = n.conj(thing)
        else:
            data_dict[key] = thing
        flg_dict[key] = n.ones_like(data_dict[key])

#Set data
ds.set_data(dsets=data_dict, conj=conj_dict, wgts=flg_dict)

#Get some statistics
Ejemplo n.º 15
0
frp, bins = fringe.aa_to_fr_profile(aa, ij, len(afreqs) / 2, bins=bins)
timebins, firs = fringe.frp_to_firs(frp,
                                    bins,
                                    aa.get_freqs(),
                                    fq0=aa.get_freqs()[len(afreqs) / 2])
fir = {(ij[0], ij[1], POL): firs}

#If data is replaced by noise
if opts.noise_only:
    if opts.same == None and opts.diff == None:
        print 'Need to specify if noise is the same on all baselines (--same) or different (--diff)'
        sys.exit()
    if opts.same and opts.frf:
        NOISE = frf((len(chans), timelen))  #same noise on all bls
    if opts.same and opts.frf == None:
        NOISE = oqe.noise(size=(len(chans), timelen))
    for key in data_dict:
        if opts.same: thing = NOISE.T
        if opts.diff and opts.frf: thing = frf((len(chans), timelen)).T
        if opts.diff and opts.frf == None:
            thing = oqe.noise(size=(len(chans), timelen)).T
        if blconj[a.miriad.ij2bl(key[1][0], key[1][1])]:
            data_dict[key] = n.conj(thing)
        else:
            data_dict[key] = thing
        flg_dict[key] = n.ones_like(data_dict[key])

#Set data
ds.set_data(dsets=data_dict, conj=conj_dict, wgts=flg_dict)

#Get some statistics
Ejemplo n.º 16
0
    #bp = mk_dly_profile([0,-10],[-1.,-.1]))
    fg = 0
    for cnt in xrange(NFG):
        fg_ch = 1e3 * (fqs / .150)**np.random.uniform(-2, 0)
        fg_ch.shape = (-1, 1)
        bm = mk_dly_profile(
            [np.random.uniform(-10, 0),
             np.random.uniform(-40, 0)],
            [np.random.uniform(-1, -2),
             np.random.uniform(-.1, -.2)])
        bm.shape = (-1, 1)
        fg_t = np.sin((cnt + 1) * ts)
        fg_t.shape = (1, -1)
        fg += bm * fg_ch * fg_t
    eor = .01 * oqe.noise(size=(NCHAN, NSAMP))

#f = 0.3 # inject less eor so pspec goes below the eor signal used for computing ratios
f = 1  # inject less eor so pspec goes below the eor signal used for computing ratios
dat = {}
for k in fg:
    dat[k] = (fg[k] + f * eor[k])
NSAMP = fg[k].shape[0]
dat_cut = {}
for k in dat:
    dat_cut[k] = np.concatenate([dat[k][:54], dat[k][65:]], axis=0)
ds = oqe.DataSet(dsets=dat)
#ds = oqe.DataSet(dsets=dat_cut)

prf_c_final = {.1: 100, .15: 100, .2: 100}
prf_w_final = {.1: 100, .15: 100, .2: 100}
Ejemplo n.º 17
0
    if blconj[aipy.miriad.ij2bl(ij[0], ij[1])]:
        fir = {(ij[0], ij[1], POL): np.conj(firs)}  #conjugate fir if needed
    else:
        fir = {(ij[0], ij[1], POL): firs}

qs_e, qs_v, qs_r, qs_ev = [], [], [], []
ps_e, ps_v, ps_r, ps_ev = [], [], [], []
c_nums = []
for sc in v_scale:
    tmp_qs_e, tmp_qs_v, tmp_qs_r, tmp_qs_ev = [], [], [], []
    tmp_ps_e, tmp_ps_v, tmp_ps_r, tmp_ps_ev = [], [], [], []
    tmp_c = []
    for i in xrange(NRUN):

        v = oqe.noise(size=(NCHAN, NSAMP * NTIMES)) * sc
        wij_ = np.zeros_like(v.T)
        dij, wij = v.T, np.logical_not(wij_)
        v, _w, _, _ = fringe.apply_frf(aa,
                                       dij,
                                       wij,
                                       ij[0],
                                       ij[1],
                                       pol=POL,
                                       bins=bins,
                                       firs=fir)

        e = oqe.noise(size=(NCHAN, NSAMP * NTIMES)).T
        r = np.copy(e + v)

        wij_ = np.zeros_like(r)
Ejemplo n.º 18
0
 def test_noise(self):
     n = oqe.noise((1024, 1024))
     self.assertEqual(n.shape, (1024, 1024))
     self.assertAlmostEqual(np.var(n), 1, 2)
Ejemplo n.º 19
0
 def test_noise(self):
     n = oqe.noise((1024,1024))
     self.assertEqual(n.shape, (1024,1024))
     self.assertAlmostEqual(np.var(n), 1, 2)
Ejemplo n.º 20
0
timelen = data_dict[keys[0]].shape[0]
ij = bls_master[0] #ij = (1,4)
if blconj[a.miriad.ij2bl(ij[0],ij[1])]: #makes sure FRP will be the same whether bl is a conjugated one or not
    if ij[0] < ij[1]: temp = (ij[1],ij[0]); ij=temp
bins = fringe.gen_frbins(inttime)
frp, bins = fringe.aa_to_fr_profile(aa, ij, len(afreqs)/2, bins=bins)
timebins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[len(afreqs)/2])
fir = {(ij[0],ij[1],POL):firs}

#If data is replaced by noise
if opts.noise_only:
    if opts.same == None and opts.diff == None: 
        print 'Need to specify if noise is the same on all baselines (--same) or different (--diff)'
        sys.exit()
    if opts.same and opts.frf: NOISE = frf((len(chans),timelen)) #same noise on all bls
    if opts.same and opts.frf == None: NOISE = oqe.noise(size=(len(chans),timelen))
    for key in data_dict:
        if opts.same: thing = NOISE.T
        if opts.diff and opts.frf: thing = frf((len(chans),timelen)).T
        if opts.diff and opts.frf == None: thing = oqe.noise(size=(len(chans),timelen)).T
        if blconj[a.miriad.ij2bl(key[1][0],key[1][1])]: data_dict[key] = n.conj(thing)
        else: data_dict[key] = thing
        flg_dict[key] = n.ones_like(data_dict[key])

#Set data
ds.set_data(dsets=data_dict,conj=conj_dict,wgts=flg_dict)

#Get some statistics
if LST_STATS:
    #collect some metadata from the lst binning process
    cnt, var = {}, {}
Ejemplo n.º 21
0
timelen = data_dict[keys[0]].shape[0]
ij = bls_master[0] #ij = (1,4)
if blconj[a.miriad.ij2bl(ij[0],ij[1])]: #makes sure FRP will be the same whether bl is a conjugated one or not
    if ij[0] < ij[1]: temp = (ij[1],ij[0]); ij=temp
bins = fringe.gen_frbins(inttime)
frp, bins = fringe.aa_to_fr_profile(aa, ij, len(afreqs)/2, bins=bins)
timebins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[len(afreqs)/2])
fir = {(ij[0],ij[1],POL):firs}

#If data is replaced by noise
if opts.noise_only:
    if opts.same == None and opts.diff == None: 
        print 'Need to specify if noise is the same on all baselines (--same) or different (--diff)'
        sys.exit()
    if opts.same and opts.frf: NOISE = frf((len(chans),timelen)) #same noise on all bls
    if opts.same and opts.frf == None: NOISE = oqe.noise(size=(len(chans),timelen))
    for key in data_dict:
        if opts.same: thing = NOISE.T
        if opts.diff and opts.frf: thing = frf((len(chans),timelen)).T
        if opts.diff and opts.frf == None: thing = oqe.noise(size=(len(chans),timelen)).T
        if blconj[a.miriad.ij2bl(key[1][0],key[1][1])]: data_dict[key] = n.conj(thing)
        else: data_dict[key] = thing
        flg_dict[key] = n.ones_like(data_dict[key])

#Set data
ds.set_data(dsets=data_dict,conj=conj_dict,wgts=flg_dict)

#Get some statistics
if LST_STATS:
    #collect some metadata from the lst binning process
    cnt, var = {}, {}
Ejemplo n.º 22
0
qs_e, qs_v, qs_r, qs_ev = [], [], [], []
ps_e, ps_v, ps_r, ps_ev = [], [], [], []
c_nums = []
bar = ProgressBar(maxval=len(v_scale) * NRUN,
                  widgets=['Performing MC:',
                           Bar(),
                           Percentage(), ' ',
                           ETA()]).start()
for cnt, sc in enumerate(v_scale):
    tmp_qs_e, tmp_qs_v, tmp_qs_r, tmp_qs_ev = [], [], [], []
    tmp_ps_e, tmp_ps_v, tmp_ps_r, tmp_ps_ev = [], [], [], []
    tmp_c = []
    for run in xrange(NRUN):
        e, v, r = {}, {}, {}
        #Gen 1 eor for all bls
        v_ = oqe.noise(size=(NCHAN, NSAMP * NFOLDS)) * sc
        wij_ = np.zeros_like(v_.T)
        dij, wij = v_.T, np.logical_not(wij_)
        v_full, _w, _, _ = fringe.apply_frf(aa,
                                            dij,
                                            wij,
                                            ij[0],
                                            ij[1],
                                            pol=POL,
                                            bins=bins,
                                            firs=fir)

        for num, k in enumerate(days):
            e[k], v[k], r[k] = {}, {}, {}
            for n1, bl in enumerate(all_bls):
                e[k][bl], v[k][bl], r[k][bl] = {}, {}, {}
Ejemplo n.º 23
0
def make_eor(shape):  # Create and fringe rate filter noise
    """Generate White Noise and Apply FRF."""
    dij = oqe.noise(size=shape)
    return dij
Ejemplo n.º 24
0
    if blconj[aipy.miriad.ij2bl(ij[0],ij[1])]: fir = {(ij[0],ij[1],POL):np.conj(firs)} #conjugate fir if needed
    else: fir = {(ij[0],ij[1],POL):firs}

qs_e,qs_v,qs_r,qs_ev = [], [], [], []
ps_e,ps_v,ps_r,ps_ev = [], [], [], []
c_nums = []
bar =ProgressBar(maxval=len(v_scale)*NRUN,widgets=['Performing MC:',Bar(),Percentage(),' ',ETA()]).start()
for cnt,sc in enumerate(v_scale):
    tmp_qs_e,tmp_qs_v,tmp_qs_r,tmp_qs_ev = [], [], [], []
    tmp_ps_e,tmp_ps_v,tmp_ps_r,tmp_ps_ev = [], [], [], []
    tmp_c=[]
    for run in xrange(NRUN):
        e,v,r = {} , {}, {}
        #Gen 1 eor for all bls
        v_ = oqe.noise(size=(NCHAN,NSAMP*NFOLDS)) * sc
        wij_ = np.zeros_like(v_.T)
        dij,wij = v_.T , np.logical_not(wij_)
        v_full,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir)

        for num,k in enumerate(days):
            e[k],v[k],r[k] = {}, {} ,{}
            for n1,bl in enumerate(all_bls):
                e[k][bl],v[k][bl],r[k][bl] = {}, {} ,{}


                e_ = oqe.noise(size=(NCHAN,NSAMP*NFOLDS)).T

                wij_ = np.zeros_like(e_)
                dij,wij = e_ , np.logical_not(wij_)
                e_,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir)
Ejemplo n.º 25
0
    timebins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[len(afreqs)/2])#, fr_width_scale=1.3, maxfr=1.3e-3)

    if blconj[aipy.miriad.ij2bl(ij[0],ij[1])]: fir = {(ij[0],ij[1],POL):np.conj(firs)} #conjugate fir if needed
    else: fir = {(ij[0],ij[1],POL):firs}

qs_e,qs_v,qs_r,qs_ev = [], [], [], []
ps_e,ps_v,ps_r,ps_ev = [], [], [], []
c_nums = []
for sc in v_scale:
    tmp_qs_e,tmp_qs_v,tmp_qs_r,tmp_qs_ev = [], [], [], []
    tmp_ps_e,tmp_ps_v,tmp_ps_r,tmp_ps_ev = [], [], [], []
    tmp_c=[]
    for i in xrange(NRUN):

           v = oqe.noise(size=(NCHAN,NSAMP*NTIMES)) * sc
           wij_ = np.zeros_like(v.T)
           dij,wij = v.T , np.logical_not(wij_)
           v,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir)

           e = oqe.noise(size=(NCHAN,NSAMP*NTIMES)).T
           r = np.copy(e + v)

           wij_ = np.zeros_like(r)
           dij,wij = r , np.logical_not(wij_)
           r,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir)

           wij_ = np.zeros_like(e)
           dij,wij = e , np.logical_not(wij_)
           e,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir)
Ejemplo n.º 26
0
    def mk_dly_profile(dbs, slopes):
        prf = 0.
        for db,slope in zip(dbs,slopes):
            prf += 10**((db + slope * np.abs(dly))/10.)
        phs = np.random.uniform(0,2*np.pi,size=NCHAN)
        phs[0] = 0; phs[1:NCHAN/2+1] = phs[NCHAN/2+1:]
        return np.fft.fft(prf*np.exp(1j*phs))
    #bp = mk_dly_profile([0,-10],[-1.,-.1]))
    fg = 0
    for cnt in xrange(NFG):
        fg_ch = 1e3 * (fqs/.150)**np.random.uniform(-2,0); fg_ch.shape = (-1,1)
        bm = mk_dly_profile([np.random.uniform(-10,0),np.random.uniform(-40,0)],[np.random.uniform(-1,-2),np.random.uniform(-.1,-.2)]); bm.shape = (-1,1)
        fg_t = np.sin((cnt+1)*ts); fg_t.shape = (1,-1)
        fg += bm * fg_ch * fg_t
    eor = .01*oqe.noise(size=(NCHAN,NSAMP))

f = 0.3 # inject less eor so pspec goes below the eor signal used for computing ratios
#f = 1 # inject less eor so pspec goes below the eor signal used for computing ratios
dat = {}
for k in fg: dat[k] = (fg[k] + f*eor[k])
NSAMP = fg[k].shape[0]
dat_cut = {}
for k in dat: dat_cut[k] = np.concatenate([dat[k][:54],dat[k][65:]], axis=0)
ds = oqe.DataSet(dsets=dat)
#ds = oqe.DataSet(dsets=dat_cut)

prf_c_final = {.1:100, .15:100, .2:100}
prf_w_final = {.1:100, .15:100, .2:100}
for boot in xrange(1):
    print boot
Ejemplo n.º 27
0
               '(--same) or different (--diff)')
        sys.exit()
    # Prep FRF Stuff
    ij = bls_master[0]  # ij = (1,4)
    if blconj[a.miriad.ij2bl(ij[0], ij[1])]:
        # makes sure FRP will be the same whether bl is a conjugated one or not
        if ij[0] < ij[1]:
            temp = (ij[1], ij[0])
            ij = temp
    timelen = data_dict[keys[0]].shape[0]
    bins = fringe.gen_frbins(inttime)
    frp, bins = fringe.aa_to_fr_profile(aa, ij, len(afreqs)/2, bins=bins)
    timebins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[len(afreqs)/2])
    fir = {(ij[0],ij[1],POL):firs}
    if opts.same and opts.frf: NOISE = frf((len(chans),timelen)) #same noise on all bls
    if opts.same and opts.frf == None: NOISE = oqe.noise((len(chans),timelen))
    for key in data_dict:
        if opts.same: thing = NOISE.T
        if opts.diff and opts.frf: thing = frf((len(chans),timelen)).T
        if opts.diff and opts.frf == None: thing = oqe.noise((len(chans),timelen)).T
        if blconj[a.miriad.ij2bl(key[1][0],key[1][1])]: data_dict[key] = n.conj(thing)
        else: data_dict[key] = thing
        flg_dict[key] = n.ones_like(data_dict[key])

# Set data
ds.set_data(dsets=data_dict, conj=conj_dict, wgts=flg_dict)

# Get some statistics
if LST_STATS:
    # collect some metadata from the lst binning process
    cnt, var = {}, {}