Esempio n. 1
0
    s += C.dfm.grid2ij(aa.ant_layout)[0][sep] + ','

    for ij in sep2ij[sep]:
        ij2sep[ij] = sep

conj = {}
toconj = C.dfm.grid2ij(aa.ant_layout)[1]
for k in toconj.keys():
    conj['%d_%d'%a.miriad.bl2ij(k)] = toconj[k]

#Get filters with proper conjugation etc. Using one for each baseline type
#too much time to generate al lof them.
filters = {}
for sep in seps.keys():
    beam_w_fr = frf_conv.get_beam_w_fr(aa, seps[sep])
    t, firs, frbins,frspace = frf_conv.get_fringe_rate_kernels(beam_w_fr, inttime, opts.filt_width)
    filters[sep] = firs

#
_d = {}
_w = {}
times, data, flags = C.arp.get_dict_of_uv_data(args, s, pol, verbose=True)

for bl in data.keys():
    if not _d.has_key(bl): _d[bl],_w[bl] = {}, {}
    #get filter which is baseline dependent.
    b1,b2 = map(int,a.miriad.bl2ij(bl))
    sep = ij2sep['%d_%d'%(b1,b2)]
    firs = filters[sep]
    print b1,b2, sep
    for pol in data[bl].keys():
    print 'Zaki method of FR filtering-OLD'
    import frf_conv
    b1,b2 = ubl2bl(opts.sep)
    print 'using basline %d_%d'%(b1,b2)
    t, firs, frbins, frkers = frf_conv.get_oldfilter(aa, (1,4), 42.8, 401, freqs)
    firs = firs.take(chans, axis=0)
    firs = n.conj(firs)
    scalar = scalar/1.9
#if True:
if False:
    print 'Zaki method of FR filtering'
    import frf_conv
    b1,b2 = ubl2bl(opts.sep)
    print 'using basline %d_%d'%(b1,b2)
    beam_w_fr = frf_conv.get_beam_w_fr(aa, (b1,b2)) #I have been using (49,41)
    t, firs, frbins, frkers = frf_conv.get_fringe_rate_kernels(beam_w_fr, 42.8, 401)
    firs = firs.take(chans, axis=0)
    firs = n.conj(firs)
    #Scaling for aggressive fringe rate filtering
    scalar = scalar
if False:
#if True:
    print 'Aaron method of FR filtering'
    t = n.arange(-200,200,1) * 42.8
    w = a.dsp.gen_window(t.size, 'blackman-harris')
    sig = .000288*(fq/.1788)#was found in fr
    cen = .001059 * (fq/.1788)#was found in fr
    firg = n.exp(-(t**2)/(2*(1./(2*n.pi*sig)**2))).astype(n.complex) * w #note that this is in time.
    #firg = n.exp(-(t**2)/(2*(1./(sig)**2))).astype(n.complex) * w #note that this is in time.
    firg /= firg.sum()
    firg *= n.exp(2j*n.pi*cen*t) # need to flip the sign for backward baselines
Esempio n. 3
0
    p.clabel(cs, inline=1, fontsize=10, fmt='%4.2f')#, manual=manual)
    #m.drawmapboundary()
    #m.drawmeridians(n.arange(0,360,30))
    #m.drawparallels(n.arange(0,90,10))
    return cs

xyz = h.px2crd(n.arange(h.npix()), ncrd=3)
top = n.dot(aa._eq2zen, xyz)
bl = aa.get_baseline(0,16,'r') * FQ
print 'Baseline:', bl
fng = frf_conv.mk_fng(bl, *xyz)
#plot_hmap(fng, mode='real'); p.show()

frf,bins,wgt,(cen,wid) = frf_conv.get_optimal_kernel_at_ref(aa, 0, (0,16))
bwfrs = frf_conv.get_beam_w_fr(aa, (0,16), ref_chan=0)
tbins,firs,frbins,frfs = frf_conv.get_fringe_rate_kernels(bwfrs,42.9,403)
wgt = scipy.interpolate.interp1d(frbins, frfs[0], kind='linear', bounds_error=False, fill_value=0)
fng_wgt = wgt(fng)

_bmx = aa[0].bm_response(top,pol='x')[0]
_bmy = aa[0].bm_response(top,pol='y')[0]
bm = 0.5 * (_bmx**2 + _bmy**2)
bm = n.where(top[-1] > 0, bm, 0)
fng_bm = fng_wgt * bm


fig = p.figure(figsize=(5,6.5))
gs = gridspec.GridSpec(2, 1, height_ratios=[3,1])
fig.subplots_adjust(left=.16, top=.95, bottom=.10, wspace=.05, hspace=.05, right=0.90)

p.subplot(gs[0])
hYY = n.sqrt(hYY)

hXX /= hXX.max()
hYY /= hYY.max()
#p.plot(bins, hXX,'k'); p.plot(bins, hYY,'k')#; p.show()
#p.plot(bins, n.where(hXX>0,hYY/hXX,0)); p.show()
bm_pol = polmatch(fng)
bmXXm = bmXX 
bmYYm = bmYY * bm_pol

hpol, bin_edges = n.histogram(fng, bins=bin_edges, weights=(bmXXm-bmYYm)**2)
htot, bin_edges = n.histogram(fng, bins=bin_edges, weights=(bmXXm+bmYYm)**2)
bins = 0.5 * (bin_edges[:-1] + bin_edges[1:])
match = n.where(hpol > 0, n.sqrt(htot/hpol), 0); match /= match.max() # XXX sqrt or no?
wgt_pol = scipy.interpolate.interp1d(bins, match, kind='linear', bounds_error=False, fill_value=0)
tbins,firs,frbins,frfs= frf_conv.get_fringe_rate_kernels(n.array([wgt_pol]),42.9,403)
frfs[0] /= frfs[0].max()
wgt_pol = scipy.interpolate.interp1d(frbins, frfs[0], kind='linear')


frf,bins,wgt,(cen,wid) = frf_conv.get_optimal_kernel_at_ref(aa, 0, (0,16))

bwfrs = frf_conv.get_beam_w_fr(aa, (0,16), ref_chan=0)
tbins,firs,frbins,frfs = frf_conv.get_fringe_rate_kernels(bwfrs,42.9,403)
wgt = scipy.interpolate.interp1d(frbins, frfs[0], kind='linear')

wgt_bins = wgt(bins); wgt_bins /= wgt_bins.max()
wgt_pol_bins = wgt_pol(bins); wgt_pol_bins /= wgt_pol_bins.max()
wgt_both_bins = wgt_bins * wgt_pol_bins; wgt_both_bins /= wgt_both_bins.max()

fig = p.figure(figsize=(6,6))
Esempio n. 5
0
    help='Number of taps to use in FIR filter.')
o.set_usage('fringe_rate_filter.py [options] *.uv')
o.set_description(__doc__)
opts,args = o.parse_args(sys.argv[1:])

uv = a.miriad.UV(args[0])
print "inttime = uv['inttime']*4 #hack for *E files:inttime set incorrectly"
inttime = uv['inttime']*4 #hack for *E files:inttime set incorrectly
nchans = uv['nchan']
aa = a.cal.get_aa(opts.cal, uv['sdf'], uv['sfreq'], uv['nchan'])
del(uv)

#kernels for all frequencies
#beam_w_fr= frf_conv.get_beam_w_fr(aa, (49,41))#, binwidth=5e-6)   
beam_w_fr= frf_conv.get_beam_w_fr(aa, (1,4))#, binwidth=5e-6)   
tb, ks = frf_conv.get_fringe_rate_kernels(beam_w_fr, 42.8, 14*14)
p.figure(100)

p.plot(tb,ks[160].real)
p.plot(tb,ks[160].imag)

#capo.arp.waterfall(beam_w_fr, mx=-1, drng=5)

#take = n.where(n.log10(beam_w_fr) > -5)
#maxtake = n.max(take[1]) 
#mintake = n.min(take[1])
#print maxtake, mintake

#bins = bins[mintake:maxtake]
#beam_w_fr = beam_w_fr[:,mintake:maxtake]
f1, f2 = frates[0] - .5*step, frates[-1]+.5*step

#plot fringe rate transform.
p.figure(3);C.arp.waterfall(vis_tft, extent=(chans[0],chans[-1],f2,f1), drng=5);p.colorbar(shrink=.5)
p.title('Stokes I in Fringe rate domain (mHz)')
p.figure(4);C.arp.waterfall(vis_del);p.colorbar(shrink=.5)
#p.show()


#Now filter with aggressive fringe rate filter. 
b1 = 1; b2 = 4 #sep24 is the 0,1 spacing.
beam_w_fr = frf_conv.get_beam_w_fr(aa, (b1,b2)) #returns the beam weighted fringe rates in fr domain.

test = beam_w_fr[110]
#using a filter that is 3.5785bar hours long = 301 samples.
t, firs, frbins, frspace = frf_conv.get_fringe_rate_kernels(beam_w_fr, 42.8, 51)
fr_bins = n.fft.fftshift(n.fft.fftfreq(51, 42.8))

#show filters in both spaces.
print firs.shape
print frspace.shape
p.figure(20)
C.arp.waterfall(firs,extent=(t[0],t[-1],0,203),mx=0,drng=5);p.colorbar(shrink=.5)
p.figure(21)
C.arp.waterfall(frspace,extent=(f1,f2,203,0), mx=0,drng=4.5);p.colorbar(shrink=.5)


firs = firs.take(chans, axis=0)
fq = n.average(freqs)
print fq
Esempio n. 7
0
    print 'Zaki method of FR filtering-OLD'
    import frf_conv
    b1,b2 = ubl2bl(opts.sep)
    print 'using basline %d_%d'%(b1,b2)
    t, firs, frbins, frkers = frf_conv.get_oldfilter(aa, (1,4), 42.8, 401, freqs)
    firs = firs.take(chans, axis=0)
    firs = n.conj(firs)
    scalar = scalar/1.9
#if True:
if False:
    print 'Zaki method of FR filtering'
    import frf_conv
    b1,b2 = ubl2bl(opts.sep)
    print 'using basline %d_%d'%(b1,b2)
    beam_w_fr = frf_conv.get_beam_w_fr(aa, (b1,b2)) #I have been using (49,41)
    t, firs, frbins, frkers = frf_conv.get_fringe_rate_kernels(beam_w_fr, 42.8, 401)
    firs = firs.take(chans, axis=0)
    firs = n.conj(firs)
    #Scaling for aggressive fringe rate filtering
    scalar = scalar
if False:
#if True:
    print 'Aaron method of FR filtering'
    t = n.arange(-200,200,1) * 42.8
    w = a.dsp.gen_window(t.size, 'blackman-harris')
    sig = .000288*(fq/.1788)#was found in fr
    cen = .001059 * (fq/.1788)#was found in fr
    firg = n.exp(-(t**2)/(2*(1./(2*n.pi*sig)**2))).astype(n.complex) * w #note that this is in time.
    #firg = n.exp(-(t**2)/(2*(1./(sig)**2))).astype(n.complex) * w #note that this is in time.
    firg /= firg.sum()
    firg *= n.exp(2j*n.pi*cen*t) # need to flip the sign for backward baselines