def test_get_beam_w_fr(self): #interps = fringe.get_beam_w_fr(self.aa, (1,4), ref_chan=160) #t,firs, frbins, frspace = fringe.get_fringe_rate_kernels(interps, 42.9, 401) frp, bins = fringe.aa_to_fr_profile(self.aa, (1,4), 100) print "the bins",len(bins), len(frp) timebins, firs = fringe.frp_to_firs(frp, bins, self.aa.get_freqs(), fq0=self.aa.get_freqs()[100]) print len(timebins), len(firs[100]) frp_fit = fringe.fir_to_frp(firs[100]) # print n.ones_like(frspace).sum() # print n.sum(frp**2) p.subplot(121) p.plot(timebins, firs[100]) p.plot(timebins, n.abs(firs[100])) p.subplot(122) print len(bins), bins[0], bins[-1] p.plot(bins, frp, 'k') p.plot(bins, frp_fit, 'b', label='new') p.xlim(-.0005,.0020) p.ylim(0.0,1.0) p.legend() p.show()
def test_get_beam_w_fr(self): #interps = fringe.get_beam_w_fr(self.aa, (1,4), ref_chan=160) #t,firs, frbins, frspace = fringe.get_fringe_rate_kernels(interps, 42.9, 401) frp, bins = fringe.aa_to_fr_profile(self.aa, (1, 4), 100) print "the bins", len(bins), len(frp) timebins, firs = fringe.frp_to_firs(frp, bins, self.aa.get_freqs(), fq0=self.aa.get_freqs()[100]) print len(timebins), len(firs[100]) frp_fit = fringe.fir_to_frp(firs[100]) # print n.ones_like(frspace).sum() # print n.sum(frp**2) p.subplot(121) p.plot(timebins, firs[100]) p.plot(timebins, n.abs(firs[100])) p.subplot(122) print len(bins), bins[0], bins[-1] p.plot(bins, frp, 'k') p.plot(bins, frp_fit, 'b', label='new') p.xlim(-.0005, .0020) p.ylim(0.0, 1.0) p.legend() p.show()
h = a.healpix.HealpixMap(nside=64) #healpix map for the beam xyz = h.px2crd(n.arange( h.npix() ), ncrd=3) tx,ty,tz = n.dot(aa._eq2zen, xyz) #rotate the coordinated system to be centered on the array. This is equatorial centered at the array. _bmx = aa[0].bm_response((tx,ty,tz),pol='x')[0] _bmy = aa[0].bm_response((tx,ty,tz),pol='y')[0] bmI = 0.5 * (_bmx**2 + _bmy**2) bmI = n.where(tz > 0, bmI, 0) # only use beam values above the horizon. bl = aa.get_baseline(0,26,'r') * .151 #baseline length in frequency. print aa.get_baseline(0,26,'r') fng = C.frf_conv.mk_fng(bl, xyz) #get the fringe rate filter in frf_conv. aa only has one channel in it. frp, bins = fringe.aa_to_fr_profile(aa, (1,4), 0) #XXX hard-coded tbins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[0],alietal=True) frp = fringe.fir_to_frp(firs) #frf,bins,wgt,(cen,wid) = C.frf_conv.get_optimal_kernel_at_ref(aa, 0, (0,26)) #bwfrs = C.frf_conv.get_beam_w_fr(aa, (0,26), ref_chan=0) #tbins,firs,frbins,frfs = C.frf_conv.get_fringe_rate_kernels(bwfrs,42.9,403) #need to renormalize to get the proper scaling. firs are properly normalized. #firs = firs[0] #frfs = n.fft.fftshift(n.fft.fft(n.fft.ifftshift(firs), axis=-1)) #get weights. wgts = scipy.interpolate.interp1d(bins, frp, kind='linear') fng_wgt = wgts(fng) #gets weightings at fringes on the sky. fng_bm = bmI * fng_wgt #flat weighting determined by the maximum possible fringe rate for a baseline #and 0. skypass = n.where(n.abs(bins) < n.max(n.abs(fng)), 1., 0) # This is the noise level after being filtered and averaged by the application of this filter.
ij, mychan, bins=frbins, pol=opts.pol, bl_scale=opts.bl_scale) timebins, firs[sep] = fringe.frp_to_firs( frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[mychan], bl_scale=opts.bl_scale, fr_width_scale=opts.fr_width_scale, alietal=opts.alietal, maxfr=opts.maxfr) frp = fringe.fir_to_frp(firs[sep]) if opts.boxcar: print 'Making Boxcar', print 'Width {0}s ...'.format(opts.teff) top_hat = n.zeros_like(firs[sep]) l_hat = len(top_hat[0]) if opts.teff: box_time = opts.teff else: box_time = 2232. start = n.round(l_hat / 2. - box_time / data_inttime / 2.) end = n.round(l_hat / 2. + box_time / data_inttime / 2.) diff = n.round(box_time / data_inttime - (end - start)) if diff != 0: end += diff if (end - start) % 2 == 0: end += 1 top_hat[:, start:end] += 1. if opts.frc:
#DEFAULT_FRBINS = n.arange(-.01+5e-5/2,.01,5e-5) # Hz firs = {} for sep in seps: c = 0 while c != -1: ij = map(int, sep2ij[sep].split(',')[c].split('_')) bl = a.miriad.ij2bl(*ij) if blconj[bl]: c+=1 else: break print mychan,ij,opts.bl_scale frp, bins = fringe.aa_to_fr_profile(aa, ij, mychan, bins=frbins,pol=opts.pol,bl_scale=opts.bl_scale) timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[mychan], bl_scale=opts.bl_scale, fr_width_scale = opts.fr_width_scale, alietal = opts.alietal,maxfr=opts.maxfr) frp = fringe.fir_to_frp(firs[sep]) if opts.boxcar: print 'Making Boxcar', print 'Width {0}s ...'.format(opts.teff) top_hat = n.zeros_like(firs[sep]) l_hat =len(top_hat[0]) if opts.teff: box_time = opts.teff else: box_time = 2232. start = n.round(l_hat/2. - box_time/data_inttime/2.) end = n.round(l_hat/2. + box_time/data_inttime/2.) diff = n.round(box_time/data_inttime - ( end - start)) if diff != 0: end += diff if (end-start) % 2 == 0: end +=1 top_hat[:,start:end] += 1. if opts.frc:
timebins, firs[sep] = fringe.frp_to_firs(frp[scale][frw_scale][sep], bins, aa.get_afreqs(), fq0=aa.get_afreqs()[mychan], limit_xtalk=True, bl_scale = scale, fr_width_scale = frw_scale, maxfr=opts.maxfr) timebins*= opts.data_inttime/opts.inttime if False and scale ==1: delta=prms0[-1]/n.sqrt(1+prms0[-1]**2) print 'model fit parameters: ',prms0 print 'norm is: ', n.sum(frp) print 'mean is: ', n.sum(bins*frp)/n.sum(frp) mn= n.sum(bins*frp)/n.sum(frp) sq= n.sqrt(n.sum((bins-mn)**2*frp)/n.sum(frp)) sk= n.sum(((bins-mn)/sq)**3*frp)/n.sum(frp) ftsk= (4-n.pi)/2.* (delta*n.sqrt(2/n.pi))**3/(1-2*delta**2/n.pi)**(1.5) print 'actual skew is: ', sk print 'fitted skew is: ', ftsk frps[sep], frp_freqs = fringe.fir_to_frp(firs[sep],tbins=timebins) baselines = ''.join(sep2ij[sep] for sep in seps) if PLOT: ax_frp.plot(frp_freqs*1e3,frps[sep][mychan]/n.max(frps[sep][mychan]), label='{0}'.format(scale),color=cmap(cnt)) ax_firs.plot(timebins,n.abs(firs[sep][mychan]),'-', label='{0}'.format(scale),color=cmap(cnt), linewidth=2) ax_firs.plot(timebins,firs[sep][mychan].real,'--', color=cmap(cnt),alpha=.5) ax_firs.plot(timebins,firs[sep][mychan].imag,'-.', color=cmap(cnt),alpha=.5) ax_firs.set_xlabel('s') envelope = n.abs(firs[sep][mychan]) envelope /= n.max(envelope)
limit_xtalk=True) if False and pad == 1: delta = prms0[-1] / n.sqrt(1 + prms0[-1]**2) print 'model fit parameters: ', prms0 print 'norm is: ', n.sum(frp) print 'mean is: ', n.sum(bins * frp) / n.sum(frp) mn = n.sum(bins * frp) / n.sum(frp) sq = n.sqrt(n.sum((bins - mn)**2 * frp) / n.sum(frp)) sk = n.sum(((bins - mn) / sq)**3 * frp) / n.sum(frp) ftsk = (4 - n.pi) / 2. * (delta * n.sqrt(2 / n.pi))**3 / ( 1 - 2 * delta**2 / n.pi)**(1.5) print 'actual skew is: ', sk print 'fitted skew is: ', ftsk frps[sep], frp_freqs = fringe.fir_to_frp(firs[sep], tbins=timebins) baselines = ''.join(sep2ij[sep] for sep in seps) for sep in seps: if PLOT: ax_frp.plot(frp_freqs * 1e3, frps[sep][mychan] / n.max(frps[sep][mychan]), label='{0}'.format(pad), color=cmap(cnt)) ax_firs.plot(timebins, n.abs(firs[sep][mychan]), label='{0}'.format(pad), color=cmap(cnt)) ax_firs.set_xlabel('s') envelope = n.abs(firs[sep][mychan]) envelope /= n.max(envelope)
if False and pad ==1: delta=prms0[-1]/n.sqrt(1+prms0[-1]**2) print 'model fit parameters: ',prms0 print 'norm is: ', n.sum(frp) print 'mean is: ', n.sum(bins*frp)/n.sum(frp) mn= n.sum(bins*frp)/n.sum(frp) sq= n.sqrt(n.sum((bins-mn)**2*frp)/n.sum(frp)) sk= n.sum(((bins-mn)/sq)**3*frp)/n.sum(frp) ftsk= (4-n.pi)/2.* (delta*n.sqrt(2/n.pi))**3/(1-2*delta**2/n.pi)**(1.5) print 'actual skew is: ', sk print 'fitted skew is: ', ftsk frps[sep], frp_freqs = fringe.fir_to_frp(firs[sep],tbins=timebins) baselines = ''.join(sep2ij[sep] for sep in seps) for sep in seps: if PLOT: ax_frp.plot(frp_freqs*1e3,frps[sep][mychan]/n.max(frps[sep][mychan]), label='{0}'.format(pad),color=cmap(cnt)) ax_firs.plot(timebins,n.abs(firs[sep][mychan]), label='{0}'.format(pad),color=cmap(cnt)) ax_firs.set_xlabel('s') envelope = n.abs(firs[sep][mychan]) envelope /= n.max(envelope) dt = n.sqrt(n.sum(envelope*timebins**2)/n.sum(envelope)) dt_50 = (timebins[envelope>0.5].max() - timebins[envelope>0.5].min()) print "pad = ", pad, "variance width = ",sep, print " [s]:",int(n.round(dt)),
timebins *= opts.data_inttime / opts.inttime if False and scale == 1: delta = prms0[-1] / n.sqrt(1 + prms0[-1]**2) print 'model fit parameters: ', prms0 print 'norm is: ', n.sum(frp) print 'mean is: ', n.sum(bins * frp) / n.sum(frp) mn = n.sum(bins * frp) / n.sum(frp) sq = n.sqrt(n.sum((bins - mn)**2 * frp) / n.sum(frp)) sk = n.sum(((bins - mn) / sq)**3 * frp) / n.sum(frp) ftsk = (4 - n.pi) / 2. * (delta * n.sqrt(2 / n.pi))**3 / ( 1 - 2 * delta**2 / n.pi)**(1.5) print 'actual skew is: ', sk print 'fitted skew is: ', ftsk frps[sep], frp_freqs = fringe.fir_to_frp(firs[sep], tbins=timebins) baselines = ''.join(sep2ij[sep] for sep in seps) if PLOT: ax_frp.plot(frp_freqs * 1e3, frps[sep][mychan] / n.max(frps[sep][mychan]), label='{0}'.format(scale), color=cmap(cnt)) ax_firs.plot(timebins, n.abs(firs[sep][mychan]), '-', label='{0}'.format(scale), color=cmap(cnt), linewidth=2) ax_firs.plot(timebins, firs[sep][mychan].real,
#firs = n.tile(gaus, (nchan,1)) #firs = n.zeros_like(firs) #num_t = n.shape(firs)[1] #firs[:,num_t/2-int(opts.teff/42.9499)/2 : num_t/2+int(opts.teff/42.9499)/2] += 1 #firs /= n.sqrt(n.sum(n.abs(firs)**2,axis=1).reshape(-1,1)) # normalize so that n.sum(abs(fir)**2) = 1 #firs = firs[chans] top_hat = n.zeros_like(firs) l_hat = len(top_hat[0]) if opts.teff: top_hat[:, l_hat / 2 - n.int(opts.teff / 42.9499) / 2.:l_hat / 2 + n.int(opts.teff / 42.9499) / 2.] += 1 else: top_hat = n.ones(n.int(2232 / 42.9499)) junk = fringe.fir_to_frp(top_hat) #junk = n.roll(junk, frp[0].argmax() - junk[0].argmax() ,axis=-1) firs = fringe.frp_to_fir(junk) firs /= n.sqrt(n.sum(n.abs(top_hat)**2, axis=-1)).reshape(-1, 1) sys.stdout.flush() for k in days: noise_array[k] = {} un_filt_noise_array[k] = {} for bl in x[k]: noise_shape = list(x[k][bls_master[0]].shape) d_size = noise_shape[1] n_mult = 50. noise_shape[1] *= n_mult ns = noise(noise_shape) * NOISE ns1 = n.copy(ns) #wij = n.transpose( f[days[0]][bls_master[0]], [1,0]) #flags (time,freq)
h = a.healpix.HealpixMap(nside=64) #healpix map for the beam xyz = h.px2crd(n.arange( h.npix() ), ncrd=3) tx,ty,tz = n.dot(aa._eq2zen, xyz) #rotate the coordinated system to be centered on the array. This is equatorial centered at the array. _bmx = aa[0].bm_response((tx,ty,tz),pol='x')[0] _bmy = aa[0].bm_response((tx,ty,tz),pol='y')[0] bmI = 0.5 * (_bmx**2 + _bmy**2) bmI = n.where(tz > 0, bmI, 0) # only use beam values above the horizon. bl = aa.get_baseline(0,26,'r') * .151 #baseline length in frequency. fng = C.frf_conv.mk_fng(bl, xyz) #get the fringe rate filter in frf_conv. aa only has one channel in it. frp, bins = fringe.aa_to_fr_profile(aa, (0,26), 0) tbins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[0]) frp = fringe.fir_to_frp(firs) #frf,bins,wgt,(cen,wid) = C.frf_conv.get_optimal_kernel_at_ref(aa, 0, (0,26)) #bwfrs = C.frf_conv.get_beam_w_fr(aa, (0,26), ref_chan=0) #tbins,firs,frbins,frfs = C.frf_conv.get_fringe_rate_kernels(bwfrs,42.9,403) #need to renormalize to get the proper scaling. firs are properly normalized. #firs = firs[0] #frfs = n.fft.fftshift(n.fft.fft(n.fft.ifftshift(firs), axis=-1)) #get weights. wgts = scipy.interpolate.interp1d(bins, frp, kind='linear') fng_wgt = wgts(fng) #gets weightings at fringes on the sky. fng_bm = bmI * fng_wgt #flat weighting determined by the maximum possible fringe rate for a baseline #and 0. skypass = n.where(n.abs(bins) < n.max(n.abs(fng)), 1., 0) # This is the noise level after being filtered and averaged by the application of this filter.
timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[mychan], limit_xtalk=True,frpad=pad) if False and pad ==1: delta=prms0[-1]/n.sqrt(1+prms0[-1]**2) print 'model fit parameters: ',prms0 print 'norm is: ', n.sum(frp) print 'mean is: ', n.sum(bins*frp)/n.sum(frp) mn= n.sum(bins*frp)/n.sum(frp) sq= n.sqrt(n.sum((bins-mn)**2*frp)/n.sum(frp)) sk= n.sum(((bins-mn)/sq)**3*frp)/n.sum(frp) ftsk= (4-n.pi)/2.* (delta*n.sqrt(2/n.pi))**3/(1-2*delta**2/n.pi)**(1.5) print 'actual skew is: ', sk print 'fitted skew is: ', ftsk frps[sep], frp_freqs = fringe.fir_to_frp(firs[sep], tbins=timebins*opts.lstbintime/opts.inttime) baselines = ''.join(sep2ij[sep] for sep in seps) #print the effective integration time for each seperation for sep in seps: print "sep",sep print " NEBW T_eff = ", print 1.2/noise_equivalent_bandwidth(frp_freqs,frps[sep][mychan]) if NOISE > 0.: # Create a fake EoR signal to inject print 'FILTERING WHITE NOSIE at {0} Jy ...'.format(NOISE) , sys.stdout.flush() ## this last term is to make the power spectrum equal ## to expected noise line if 21cmSense noise only no filter is run ed = noise((nchan,711)) * NOISE ed1 = n.copy(ed)