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_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 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()
frbins = fringe.gen_frbins(inttime, fringe_res=1. / (inttime * len(times))) #frbins = n.arange( -.5/inttime+5e-5/2, .5/inttime,5e-5) #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 "Looking for baselines matching ", opts.ant ants = [ b[0] for b in a.scripting.parse_ants(opts.ant, nants) ] seps = [ bl2sep[b] for b in ants ] seps = n.unique(seps) print 'These are the spearations that we are going to use ', seps #Get the fir filters for the separation used. 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 frp, bins = fringe.aa_to_fr_profile(aa, ij, 100,frpad=opts.frpad) timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[100]) baselines = ''.join(sep2ij[sep] for sep in seps) times, data, flags = arp.get_dict_of_uv_data(args, baselines, pol, verbose=True) lsts = [ aa.sidereal_time() for k in map(aa.set_jultime(), times) ] _d = {} _w = {} for bl in data.keys(): if not _d.has_key(bl): _d[bl],_w[bl] = {}, {} #get filter which is baseline dependent. sep = bl2sep[bl] fir = firs[sep] if blconj[bl]: fir = n.conj(fir) print map(int, a.miriad.bl2ij(bl)), sep, blconj[bl]
ants = [ b[0] for b in a.scripting.parse_ants(opts.ant, nants) ] seps = [ bl2sep[b] for b in ants ] seps = n.unique(seps) print 'These are the spearations that we are going to use ', seps print 'This is the channel we are using to build the frf: ',mychan print 'Current inttime use for gen_frbins: ',inttime #Get the fir filters for the separation used. 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 frp, bins = fringe.aa_to_fr_profile(aa, ij, mychan, bins=frbins,frpad=opts.frpad) #frp, bins = fringe.aa_to_fr_profile(aa, ij, mychan) ## for default fr_bins #timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[100],mdl=skew,startprms=(.001,.001,-50),frpad=opts.frpad) timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[mychan], startprms=(.001*opts.frpad,.0001)) #timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[mychan],frpad=opts.frpad, alietal=opts.alietal ) baselines = ''.join(sep2ij[sep] for sep in seps) times, data, flags = zsa.get_dict_of_uv_data(args, baselines, pol, verbose=True) lsts = [ aa.sidereal_time() for k in map(aa.set_jultime(), times) ] _d = {} _w = {} for bl in data.keys(): if not _d.has_key(bl): _d[bl],_w[bl] = {}, {} #get filter which is baseline dependent. sep = bl2sep[bl]
ants = [ b[0] for b in a.scripting.parse_ants(opts.ant, nants) ] seps = [ bl2sep[b] for b in ants ] seps = n.unique(seps) print 'These are the separations that we are going to use:', seps #Get the fir filters for the separation used bins = fringe.gen_frbins(inttime) firs = {} for sep in seps: c = 0 #baseline indices while True: ij = map(int, sep2ij[sep].split(',')[c].split('_')) bl = a.miriad.ij2bl(*ij) if blconj[bl]: c+=1 else: break #find when conjugation isn't necessary frp, bins = fringe.aa_to_fr_profile(aa, ij, 100, pol=pol, bins=bins) timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[100]) baselines = ''.join(sep2ij[sep] for sep in seps) times, data, flags = C.miriad.read_files(args, baselines, pol, verbose=True) #new way of get_dict_of_uv_data #jds = times['times'] #lsts = [ aa.sidereal_time() for k in map(aa.set_jultime(), jds) ] lsts = times['lsts'] lst_order = n.argsort(lsts) #data is not always read in LST order! lsts = n.array(lsts)[lst_order] times['times'] = times['times'][lst_order] for bl in data: #orders data and flags correctly by LST for pol in data[bl]: data[bl][pol] = data[bl][pol][lst_order] flags[bl][pol] = flags[bl][pol][lst_order]
#1e9 to get into hertz. #milli-K. #intime=43s*60days (per even and odd data set), thermal_level = 500e3 / n.sqrt(2 * sdf * 1e9 * 43 * 60) print thermal_level print 'INJECTING SIMULATED SIGNAL' if False: # this hack of a fringe_filter doesn't seem to be representative fringe_filter = n.ones((44, )) # Maintain amplitude of original noise fringe_filter /= n.sqrt(n.sum(fringe_filter)) for ch in xrange(eor1.shape[0]): eor1[ch] = n.convolve(eor1[ch], fringe_filter, mode='same') else: # this one is the exact one ij = a.miriad.bl2ij(bls_master[0]) print 'baseline used to make fringe rate filter is = ', ij frp, bins = fringe.aa_to_fr_profile(aa, ij, 100) timebins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[100]) #beam_w_fr = capo.frf_conv.get_beam_w_fr(aa, bl) #t, firs, frbins,frspace = capo.frf_conv.get_fringe_rate_kernels(beam_w_fr, inttime, FRF_WIDTH) #for cnt,ch in enumerate(chans): # eor1[cnt] = n.convolve(eor1[cnt], firs[ch], mode='same') for k in days: if not eor.has_key(k): eor[k] = {} for bl in x[k]: eor1 = noise(x[days[0]][ bls_master[0]].shape) * INJECT_SIG * thermal_level print eor1.shape print 'STD of noise before frf ', n.std(eor1, axis=1),
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") * 0.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.
noise_array_top_hat = {} noise_array_pre_filter = {} for cnt,pad in enumerate(frpads): firs = {} frps = {} noise_array[pad] = {} noise_array_top_hat[pad] = {} noise_array_pre_filter[pad] = {} 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 frp, bins = fringe.aa_to_fr_profile(aa, ij, mychan,bins=frbins,frpad=pad, pol=opts.pol) #startparms=(.001*pad,.0001) #startparms= tuple([pad*par for par in startparms]) #timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[mychan], limit_xtalk=True,startprms=startparms,frpad=opts.frpad) timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[mychan], limit_xtalk=True,frpad=pad) print 'current sum of n.abs(firs)**2: ', n.sum(n.abs(firs[sep][mychan])**2) 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))
antstr = 'cross' _, blconj, _ = zsa.grid2ij(aa.ant_layout) days = dsets.keys() s,d,f = capo.miriad.read_files([dsets[days[0]][0]], antstr=antstr, polstr=POL) # read first file ij = d.keys()[0] # use first baseline 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 sep_type = bl2sep[a.miriad.ij2bl(ij[0], ij[1])] # convert uvw in light-nanoseconds to m, (cosmo_units.c in m/s) uvw = aa.get_baseline(ij[0], ij[1], src='z') * cosmo_units.c * 1e-9 bins = fringe.gen_frbins(inttime) mychan = 101 # XXX use this to match frf_filter.py frp, bins = fringe.aa_to_fr_profile(aa, ij, mychan, bins=bins) timebins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[mychan]) firs = firs[int(opts.chan.split('_')[0]):int(opts.chan.split('_')[1])+1,:] # chop firs to frequency range of interest fir = {(ij[0], ij[1], POL): firs} fir_conj = {} # fir for conjugated baselines for key in fir: fir_conj[key] = n.conj(fir[key]) aa = a.cal.get_aa(opts.cal, afreqs) # aa is now subset of freqs, for use in apply_frf later # Acquire data data_dict_v = {} data_dict_n = {} flg_dict = {} conj_dict = {} stats, lsts, data, flgs = {}, {}, {}, {}
for cnt,scale in enumerate(bl_scales): firs = {} frps = {} frp[scale] = {} for cn1,frw_scale in enumerate(fr_width_scales): frp[scale][frw_scale] ={} for sep in seps: if opts.baseline: ij = a.miriad.bl2ij(opts.baseline); bl =opts.baseline else: ij_array = sep2ij[sep].split(',') while True: ij = map( int, ij_array.pop().split('_') ) bl = a.miriad.ij2bl(*ij ) if not blconj[bl]: break print "bl_scale = ", scale,"fr_width:", frw_scale, "sep: ",sep,'bl:',bl, 'ant:', ij frp[scale][frw_scale][sep], bins = fringe.aa_to_fr_profile(aa, ij, mychan,bins=frbins, pol=opts.pol, bl_scale=scale) 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 = {} frp[scale] = {} for cn1, frw_scale in enumerate(fr_width_scales): frp[scale][frw_scale] = {} for sep in seps: if opts.baseline: ij = a.miriad.bl2ij(opts.baseline) bl = opts.baseline else: ij_array = sep2ij[sep].split(',') while True: ij = map(int, ij_array.pop().split('_')) bl = a.miriad.ij2bl(*ij) if not blconj[bl]: break print "bl_scale = ", scale, "fr_width:", frw_scale, "sep: ", sep, 'bl:', bl, 'ant:', ij frp[scale][frw_scale][sep], bins = fringe.aa_to_fr_profile( aa, ij, mychan, bins=frbins, pol=opts.pol, bl_scale=scale) 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 "Looking for baselines matching ", opts.ant ants = [ b[0] for b in a.scripting.parse_ants(opts.ant, nants) ] seps = [ bl2sep[b] for b in ants ] seps = n.unique(seps) print 'These are the spearations that we are going to use ', seps #Get the fir filters for the separation used. 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 frp, bins = fringe.aa_to_fr_profile(aa, ij, 100,frpad=1.0) timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_afreqs(), fq0=aa.get_afreqs()[100],mdl=skew,startprms=(.001,.001,-50),frpad=opts.frpad) baselines = ''.join(sep2ij[sep] for sep in seps) times, data, flags = arp.get_dict_of_uv_data(args, baselines, pol, verbose=True) lsts = [ aa.sidereal_time() for k in map(aa.set_jultime(), times) ] _d = {} _w = {} for bl in data.keys(): if not _d.has_key(bl): _d[bl],_w[bl] = {}, {} #get filter which is baseline dependent. sep = bl2sep[bl] fir = firs[sep] if blconj[bl]: fir = n.conj(fir) print map(int, a.miriad.bl2ij(bl)), sep, blconj[bl]
#get antenna array aa = a.cal.get_aa('psa6240_v003', n.array([.151])) 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.
print 'z:', z print 'B:', B print 'scalar:', scalar sys.stdout.flush() if True: #this one is the exact one sep = bl2sep[all_bls[0]] ij_array = sep2ij[sep].split(',') while True: ij = map( int, ij_array.pop().split('_') ) bl = a.miriad.ij2bl(*ij ) if not blconj[bl]: break print 'Using Baseline for FRP:',bl bins = fringe.gen_frbins(inttime) frp, bins = fringe.aa_to_fr_profile(aa, ij, len(afreqs)/2, bins=bins, bl_scale = opts.bl_scale) timebins, firs = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[len(afreqs)/2], bl_scale=opts.bl_scale, fr_width_scale= opt.fr_width_scale) 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} #Extract frequency range of data for each boot for boot in xrange(opts.nboot): print '%d / %d' % (boot+1,opts.nboot) x = {} f = {} for k in days: x[k] = {} f[k] = {} for bl in all_bls:
aa = aipy.cal.get_aa('psa6240_v003', afreqs) sep2ij, blconj, bl2sep = capo.zsa.grid2ij(aa.ant_layout) ijs = sep2ij[SEP].split(',') all_bls= [ aipy.miriad.ij2bl(*map( int,x.split('_'))) for x in ijs] if True: #this one is the exact one sep = bl2sep[all_bls[0]] ij_array = sep2ij[sep].split(',') while True: ij = map( int, ij_array.pop().split('_') ) bl = aipy.miriad.ij2bl(*ij ) if not blconj[bl]: break if False: bl = 11072; ij = aipy.miriad.bl2ij(bl); print 'Using Baseline for FRP:',bl 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])#, 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 = [] 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):
##use calculated inttime to generate correct frf bins frbins = fringe.gen_frbins(inttime,fringe_res=1./(inttime*len(times))) #frbins = n.arange( -.5/inttime+5e-5/2, .5/inttime,5e-5) #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
noise_array_top_hat = {} noise_array_pre_filter = {} for cnt,pad in enumerate(frpads): firs = {} frps = {} noise_array[pad] = {} noise_array_top_hat[pad] = {} noise_array_pre_filter[pad] = {} 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 frp, bins = fringe.aa_to_fr_profile(aa, ij, mychan,bins=frbins,frpad=pad, pol=opts.pol) 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
data[k][bl],flgs[k][bl] = n.array(data[k][bl][:j]),n.array(flgs[k][bl][:j]) data2[k][bl],flgs2[k][bl] = n.array(data2[k][bl][:j]),n.array(flgs2[k][bl][:j]) else: for k in days: for bl in data[k]: data[k][bl], flgs[k][bl] = n.array(data[k][bl][:]), n.array(flgs[k][bl][:]) data2[k][bl], flgs2[k][bl] = n.array(data2[k][bl][:]), n.array(flgs2[k][bl][:]) lsts = lsts.values()[0] #same set of LST values for both even/odd data daykey = data.keys()[0] blkey = data[daykey].keys()[0] ij = a.miriad.bl2ij(blkey) #Prep FRF Stuff bins = fringe.gen_frbins(inttime) frp, bins = fringe.aa_to_fr_profile(aa, ij, len(afreqs)/2, bins=bins) #Extract frequency range of data x = {} x2 = {} #if opts.noise_only: NOISE = frf((len(chans),len(lsts)),loc=0,scale=1) #same noise for all bl for k in days: x = {} x2 = {} f = {} f2 = {} for k in days: x[k] = {} x2[k] = {} f[k] = {} f2[k] = {}
print "Looking for baselines matching ", opts.ant ants = [ b[0] for b in a.scripting.parse_ants(opts.ant, nants) ] seps = [ bl2sep[b] for b in ants ] seps = n.unique(seps) print 'These are the spearations that we are going to use ', seps #Get the fir filters for the separation used. 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 frp, bins = fringe.aa_to_fr_profile(aa, ij, 100) timebins, firs[sep] = fringe.frp_to_firs(frp, bins, aa.get_freqs(), fq0=aa.get_freqs()[100]) baselines = ''.join(sep2ij[sep] for sep in seps) times, data, flags = arp.get_dict_of_uv_data(args, baselines, pol, verbose=True) lsts = [ aa.sidereal_time() for k in map(aa.set_jultime(), times) ] _d = {} _w = {} for bl in data.keys(): if not _d.has_key(bl): _d[bl],_w[bl] = {}, {} #get filter which is baseline dependent. sep = bl2sep[bl] fir = firs[sep] if blconj[bl]: fir = n.conj(fir) print map(int, a.miriad.bl2ij(bl)), sep, blconj[bl]
aa = a.cal.get_aa('psa6240_v003', n.array([.159])) #XXX hard-coded 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.
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 #XXX hard-coded baseline length in frequency. print aa.get_baseline(0, 26, 'r') fng = fringe.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=False) #frp = fringe.fir_to_frp(firs) ## Old way of calculating FRP,FIRS,etc. ## #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))