def frf(shape, loc=0, scale=1): """Generate White Noise and apply FRF.""" shape = shape[1] * 4, shape[0] # (4*times,freqs) dij = noise(shape, loc=loc, scale=scale) # dij = n.ones(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,_w,_,_ = fringe.apply_frf(aa, _d, wij, ij[0] ,ij[1] , # pol=POL,bins=bins,firs=fir) _d = n.transpose(_d) _d = _d[:, shape[0] / 2. - shape[0] / 4. / 2.:shape[0] / 2. + shape[0] / 4. / 2.] return _d
def frf_data(data): #FRF FULL LENGTH DATA aa2 = a.cal.get_aa(opts.cal, freqs) #All freqs for data instead of subset bins = fringe.gen_frbins(inttime) frp, bins = fringe.aa_to_fr_profile(aa2, ij, len(freqs) / 2, bins=bins) timebins, firs = fringe.frp_to_firs(frp, bins, aa2.get_freqs(), fq0=aa2.get_freqs()[len(freqs) / 2]) _, blconj, _ = zsa.grid2ij(aa2.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} dij = n.transpose(data) wij = n.ones(dij.shape, dtype=bool) #XXX flags are all true (times,freqs) #dij and wij are (times,freqs) _d, _w, _, _ = fringe.apply_frf(aa2, dij, wij, ij[0], ij[1], pol=POL, bins=bins, firs=fir) _d = n.transpose(_d) return _d
def frf(shape,loc=0,scale=1): #FRF NOISE shape = shape[1]*2,shape[0] #(2*times,freqs) dij = noise(shape,loc=loc,scale=scale) wij = n.ones(shape,dtype=bool) #XXX flags are all true (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
def frf(shape,doublelen=False): #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) if doublelen: _d = _d else: _d = _d[:,shape[0]/4:shape[0]/2+shape[0]/4] return _d
def frf(shape, loc=0, scale=1): # FRF NOISE """Create Fringe Rate Filtered Noise Sim.""" 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
def frf_data(data): #FRF FULL LENGTH DATA aa2 = a.cal.get_aa(opts.cal, freqs) #All freqs for data instead of subset bins = fringe.gen_frbins(inttime) frp, bins = fringe.aa_to_fr_profile(aa2, ij, len(freqs)/2, bins=bins) timebins, firs = fringe.frp_to_firs(frp, bins, aa2.get_freqs(), fq0=aa2.get_freqs()[len(freqs)/2]) _,blconj,_ = zsa.grid2ij(aa2.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} dij = n.transpose(data) wij = n.ones(dij.shape,dtype=bool) #XXX flags are all true (times,freqs) #dij and wij are (times,freqs) _d,_w,_,_ = fringe.apply_frf(aa2,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir) _d = n.transpose(_d) return _d
def frf(shape,loc=0,scale=1): #FRF NOISE shape = shape[1]*2,shape[0] #(2*times,freqs) dij = noise(shape,loc=loc,scale=scale) #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
def frf(shape, loc=0, scale=1): """Generate White Noise and apply FRF.""" shape = shape[1]*4, shape[0] # (4*times,freqs) dij = noise(shape, loc=loc, scale=scale) # dij = n.ones(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)
def frf(shape, loc=0, scale=1): #FRF NOISE shape = shape[1] * 2, shape[0] #(2*times,freqs) dij = noise(shape, loc=loc, scale=scale) #dij = oqe.noise(size=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
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) r_ = np.copy(e_ + v_full)
def fringe_rate_filter(aa, dij, wij, i, j, pol, bins, fir): """ Apply frf.""" _d, _w, _, _ = fringe.apply_frf(aa, dij, wij, i, j, pol=pol, bins=bins, firs=fir) return _d
ns = noise(x[k][bls_master[0]].shape) * NOISE wij = n.transpose(f[days[0]][bls_master[0]], [1, 0]) #flags (time,freq) if opts.filter_noise: if blconj[a.miriad.ij2bl(ij[0], ij[1])]: fir = { (ij[0], ij[1], POL): n.conj(firs) } #conjugate fir if needed else: fir = {(ij[0], ij[1], POL): firs} dij, wij = n.transpose(ns, [1, 0]), n.logical_not(wij) ns, _w, _, _ = fringe.apply_frf(aa, dij, wij, ij[0], ij[1], pol=POL, bins=bins, firs=fir) ns = n.transpose(ns, [1, 0]) if conj[bl]: ns = n.conj(ns) noise_array[k][bl] = n.transpose(ns.T * jy2T, [1, 0]) for k in days: for bl in x[k]: if opts.noise_only: x[k][bl] = n.copy(noise_array[k][bl]) else: x[k][bl] += noise_array[k][bl] if PLOT and True: fig, axes = p.subplots(nrows=2, ncols=1) p.subplot(211)
#get filter which is baseline dependent m_bl = a.miriad.ij2bl(bl[0],bl[1]) #miriad bl sep = bl2sep[m_bl] i,j = bl #fir = firs[sep] #if blconj[m_bl]: fir = n.conj(fir) #print map(int, a.miriad.bl2ij(m_bl)), sep, blconj[m_bl] print bl for pol in data[bl].keys(): if blconj[m_bl]: fir = {(i,j,pol):n.conj(firs[sep])} #conjugate fir if needed else: fir = {(i,j,pol):firs[sep]} if not _d[bl].has_key(pol): _d[bl][pol], _w[bl][pol] = {}, {} #_d[bl][pol] = n.zeros_like(data[bl][pol]) #_w[bl][pol] = n.zeros_like(data[bl][pol]) dij,wij = data[bl][pol],n.logical_not(flags[bl][pol]) _d[bl][pol],_w[bl][pol],_,_ = fringe.apply_frf(aa,dij,wij,i,j,pol=pol,bins=bins,firs=fir) """ #stuff below is now in fringe.apply_frf for ch in xrange(data[bl][pol].shape[1]): #flg = n.logical_not(flags[bl][pol][:,ch]) #_d[bl][pol][:,ch] = n.convolve(flags[bl][pol][:,ch]*data[bl][pol][:,ch], n.conj(firs[ch,:]), mode='same') _d[bl][pol][:,ch] = n.convolve(flg*data[bl][pol][:,ch], n.conj(fir[ch,:]), mode='same') #_d[bl][pol][:,ch] = n.convolve(flg*data[bl][pol][:,ch], firs[ch,:], mode='same') #_w[bl][pol][:,ch] = n.convolve(flags[bl][pol][:,ch], n.abs(n.conj(firs[ch,:])), mode='same') _w[bl][pol][:,ch] = n.convolve(flg, n.abs(n.conj(fir[ch,:])), mode='same') #_w[bl][pol][:,ch] = n.convolve(flg, n.abs(firs[ch,:]), mode='same') #_d[bl][pol][:,ch] = n.where(flags[bl][pol][:,ch]>0, _d[bl][pol][:,ch]/_w[bl][pol][:,ch], 1) _d[bl][pol][:,ch] = n.where(flg>0, _d[bl][pol][:,ch]/_w[bl][pol][:,ch], 1) """ def mfunc(uv, p, d, f): uvw,t,(i,j) = p
for bl in all_bls: d = noise((nchan,ntimes)).T * NOISE * jy2T flg = n.zeros_like(d) if conj[bl]: d = n.conj(d) #conjugate if necessary x[k][bl] = n.transpose(d, [1,0]) #swap time and freq axes f[k][bl] = n.transpose(flg, [1,0]) #eor = x.pop('eor'); days = x.keys() #make up for putting eor in list above bls_master = x.values()[0].keys() nbls = len(bls_master) print 'Baselines:', nbls if INJECT_SIG > 0.: #Create a fake EoR signal to inject print 'INJECTING SIMULATED SIGNAL' eor1 = noise((nchan,ntimes)).T * INJECT_SIG * jy2T wij_ = n.zeros_like(eor1) dij,wij = eor1 , n.logical_not(wij_) _d,_w,_,_ = fringe.apply_frf(aa,dij,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir) ### OLD CODE TO FRF ### #for cnt,ch in enumerate(chans): # eor1[cnt] = n.convolve(eor1[cnt], n.conj(firs[cnt]), mode='same') #conjugate firs!!! eor2 = n.transpose(_d, [1,0]) # eor2 = clip_array(eor2,x[k][bls_master[0]].shape) eor = n.copy(eor2) # eor1 = clip_array(eor1,x[k][bls_master[0]].shape) for k in days: for bl in x[k]: _x = x[k][bl].copy() + eor.copy() #add injected signal to data wij = n.logical_not(f[k][bl].T) _x_,_,_,_ =fringe.apply_frf(aa,_x.T,wij,ij[0],ij[1],pol=POL,bins=bins,firs=fir) _x_ = n.transpose(_x_,[1,0]) x[k][bl] = clip_array(_x_,ntimes,axis=1)