forked from AaronParsons/fringerate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_fringe_rate_cut.py
executable file
·124 lines (104 loc) · 4.17 KB
/
plot_fringe_rate_cut.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#! /usr/bin/env python
import aipy as a, numpy as n, pylab as p
import capo as C, scipy
import frf_conv
from mpl_toolkits.basemap import Basemap
FQ = .159
aa = a.cal.get_aa('psa898_v003', n.array([FQ]))
h = a.healpix.HealpixMap(nside=64)
def beam_area(dat):
return n.sum(dat) * 4 * n.pi / h.npix()
xyz = h.px2crd(n.arange(h.map.size), ncrd=3)
tx,ty,tz = n.dot(aa._eq2zen, xyz)
_bmx = aa[0].bm_response((tx,ty,tz),pol='x')[0]
_bmy = aa[0].bm_response((tx,ty,tz),pol='y')[0]
bmXX = n.where(tz > 0, _bmx**2, 0)
bmYY = n.where(tz > 0, _bmy**2, 0)
bl = aa.get_baseline(0,16,'r') * FQ
print 'Baseline:', bl
fng = frf_conv.mk_fng(bl, *xyz)
binwidth = .00005
#binwidth = .000015
bin_edges = n.arange(-.01+binwidth/2,.01,binwidth)
hXX, bin_edges = n.histogram(fng, bins=bin_edges, weights=bmXX*bmXX)
hXY, bin_edges = n.histogram(fng, bins=bin_edges, weights=bmXX*bmYY)
hYY, bin_edges = n.histogram(fng, bins=bin_edges, weights=bmYY*bmYY)
bins = 0.5 * (bin_edges[:-1] + bin_edges[1:])
#polmatch = n.where(hYY > 0, hXY / hYY, 0)
print bins
polmatch = n.where(hYY > 0, hXY / hYY, n.where(n.logical_and(bins >= -.0007, bins < 0), 2., 0))
#polmatch = n.where(hYY > 0, n.sqrt(hXX / hYY), 0)
polmatch = scipy.interpolate.interp1d(bins, polmatch, kind='linear', bounds_error=False, fill_value=0)
hXX = n.sqrt(hXX)
hXY = n.sqrt(hXY)
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))
fig.subplots_adjust(left=.15, top=.95, bottom=.12, wspace=.15, hspace=.24, right=0.95)
p.subplot(211)
p.plot(1e3*bins,frf,'k')
p.plot(1e3*bins,wgt_bins,'r')
p.plot(1e3*bins,polmatch(bins),'b--')
p.plot(1e3*bins,wgt_pol_bins,'b')
p.plot(1e3*bins,wgt_both_bins,'g')
p.grid()
p.ylim(-0.1,2.)
p.xlim(-1,1.5)
p.xlabel('Fringe Rate [mHz]')
p.ylabel('Filter Response')
firs[0] /= n.abs(firs[0]).max()
p.subplot(212)
p.plot(tbins, n.abs(firs[0]), '#7f3f0e')
p.plot(tbins, n.real(firs[0]), 'c')
p.plot(tbins, n.imag(firs[0]), 'm')
p.ylim(-1.1,1.1)
p.xlim(-5000,5000)
p.xlabel('Time [s]')
p.ylabel('Filter Response')
p.grid()
p.show()
pol_wgt = wgt_pol(fng).real
fng_wgt = wgt(fng).real
#bmXXm_fng = bmXXm * fng_wgt
#bmYYm_fng = bmYYm * fng_wgt
bmI = 0.5 * (bmXX + bmYY)
bmQ = 0.5 * (bmXX - bmYY)
bmIm = 0.5 * (bmXXm + bmYYm)
bmQm = 0.5 * (bmXXm - bmYYm)
bmIm_fng = bmIm * fng_wgt
bmQm_fng = bmQm * fng_wgt
bmIm_fngpol = bmIm_fng * pol_wgt
bmQm_fngpol = bmQm_fng * pol_wgt
print 'Unweighted:', n.sqrt(n.sum(bmQ**2)/n.sum(bmI**2))
print 'Matched: ', n.sqrt(n.sum(bmQm**2)/n.sum(bmIm**2))
print 'Optimal SN:', n.sqrt(n.sum(bmQm_fng**2)/n.sum(bmIm_fng**2))
print 'Opt pol+SN:', n.sqrt(n.sum(bmQm_fngpol**2)/n.sum(bmIm_fngpol**2))
print 'Unweighted:', (n.sum(bmQ**2)/n.sum(bmI**2))
print 'Matched: ', (n.sum(bmQm**2)/n.sum(bmIm**2))
print 'Optimal SN:', (n.sum(bmQm_fng**2)/n.sum(bmIm_fng**2))
print 'Opt pol+SN:', (n.sum(bmQm_fngpol**2)/n.sum(bmIm_fngpol**2))
print 'Whole PP beam area:', beam_area(bmI**2)
print 'Matched PP beam area:', beam_area(bmIm**2)
print 'Optimal PP beam area:', beam_area(bmIm_fng**2)
print 'Opt pol PP beam area:', beam_area(bmIm_fngpol**2)