#! /usr/bin/env python import numpy as np import aipy as a from capo.pspec import jy2T from PolSim import * from healpy import * from pylab import * Niter = 100 Nside = 64 aa = a.cal.get_aa('psa_null', np.array([0.165])) D = Distributions.Dist('scripts/6C.cf', 0.76, 'data/Oppermann.copy.npz') jy2T = jy2T(0.165) Cell = [] for i in range(Niter): print "Working on iteration %d/%d"%(i+1,Niter) print "\t with %d sources"%D.Nsrc prms = D.SimSkyParams() x,y = prms['L'], prms['M'] z = np.sqrt(1.-x**2 - y**2) m = np.zeros(nside2npix(Nside)) for pi,fi,xi,yi,zi in zip(prms['P'],prms['F'],x,y,z): m[vec2pix(Nside, xi, yi, zi)] += jy2T*fi*pi Cell.append(anafast(m, lmax=1000)) Cell = np.array(Cell) dCell = np.std(Cell, axis=0) Cell = np.mean(Cell, axis=0)
if n.round(w.max())%2:#if we had an odd number of points dif += n.ma.array(D).squeeze() * S #sum with signs (opposing if --dt) w += n.logical_not(f).astype(n.float).squeeze() print "evening it up!" print dif.shape #if we diffed over baselines we should just have a spectrum if opts.bl: dif = dif.squeeze() var = n.real(dif*n.conj(dif)) elif len(dif.shape)>1: #if not, then we need to average over them var = n.mean(dif*n.conj(dif),axis=0) #this should be the zero axis else: var = dif*n.conj(dif) print len(freqs),len(var) Trms = n.sqrt(var)/w.squeeze()*jy2T(freqs) n.savez('diff_uv.npz',freqs=freqs,dif=dif.filled(0),weights=w,Trms=Trms.filled(0),mask=Trms.mask) if opts.plot: #theoretical noise level F = n.load('diff_uv.npz') freqs = F['freqs'] Trms = n.ma.masked_where(F['mask'],F['Trms']) print Trms.shape,freqs.shape plot(freqs*1e3,Trms,'k') savefig('diff_uv.png') grid() ylabel('mK') xlabel('MHz') # show()
Nann = 3 for i in range(Nann): if i == 0 or i+1 == Nann: continue #if i%4 != 0: continue nchan_i = int(Nchan/Nann) ntaps = 3 ch1,ch2 = i*nchan_i,(i+1)*nchan_i ch_in,ch_out = ch1-nchan_i, ch2+nchan_i freqs_i = freqs[ch_in:ch_out] dnu = freqs_i[1] - freqs_i[0] eta = np.fft.fftshift(np.fft.fftfreq(nchan_i,dnu)) z_mid = np.median(pspec.f2z(freqs_i)) k = np.abs(eta*pspec.dk_deta(z_mid)) V_nu = RMvis(freqs_i,RM) V_nu *= pspec.jy2T(freqs_i) Trms = pfb.pfb(V_nu,taps=ntaps,window=window,fft=np.fft.ifft) Trms = np.fft.fftshift(Trms) DELTA = k3pk(Trms,k=k,fq=np.mean(freqs_i),B=0.1/Nann) valid = k!=0. DELTA = np.extract(valid,DELTA) DELTA /= DELTA.sum() k = np.extract(valid,k) _k,_DELTA = rebin_log(k,DELTA) ax = fig.add_subplot(len(RMs),1,j+1) #ax.step(k,DELTA,where='mid',color='k',label='z = %2.1f'%z_mid)
D = n.ma.diff(D, axis=0) / n.sqrt(2) if opts.v: print "diffing baselines" if opts.t: D = n.ma.diff(D, axis=1) / n.sqrt(2) if opts.f: D = n.ma.diff(D, axis=2) / n.sqrt(2) W = W[:, :, : -1] #if we're diffing by freqs drop the topmost channel flag var = n.abs(n.ma.sum(n.ma.sum(D * n.conj(D), axis=0), axis=0)) #bl=0,time=1 w = n.sum(n.sum(W, axis=0), axis=0) #bl=0,time=1 Trms = var Trms[w > 0] /= w[w > 0] Trms = n.sqrt(Trms) * jy2T(freqs) if opts.v: mypoint = w.argmax() print var[mypoint] print w[mypoint] print Trms[mypoint] print "writing uv_rms.npz" n.savez('uv_rms.npz', freqs=freqs, weights=w, Trms=Trms.filled(0), mask=Trms.mask, label=opts.label) if opts.v:
#see Eq 4.16 of Jacobs thesis if opts.bl and not (D.shape[0]%2): D = n.ma.diff(D,axis=0)/n.sqrt(2) if opts.v: print "diffing baselines" if opts.t: D = n.ma.diff(D,axis=1)/n.sqrt(2) if opts.f: D = n.ma.diff(D,axis=2)/n.sqrt(2) W = W[:,:,:-1]#if we're diffing by freqs drop the topmost channel flag var = n.abs(n.ma.sum(n.ma.sum(D*n.conj(D),axis=0),axis=0)) #bl=0,time=1 w = n.sum(n.sum(W,axis=0),axis=0) #bl=0,time=1 Trms = var Trms[w>0] /= w[w>0] Trms = n.sqrt(Trms)*jy2T(freqs) if opts.v: mypoint = w.argmax() print var[mypoint] print w[mypoint] print Trms[mypoint] print "writing uv_rms.npz" n.savez('uv_rms.npz',freqs=freqs,weights=w,Trms=Trms.filled(0),mask=Trms.mask,label=opts.label) if opts.v: rows,cols = intsquare(D.shape[0]) for i in xrange(D.shape[0]): subplot(rows,cols,i+1) title(a.miriad.bl2ij(bls[i])) imshow(n.abs(D[i])*jy2T(freqs),aspect='auto',vmin=0,vmax=30)