forked from telegraphic/leda_analysis_2016
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path05_plot_residuals.py
executable file
·128 lines (92 loc) · 2.85 KB
/
05_plot_residuals.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
124
125
126
127
128
#!/usr/bin/env python
"""
# 05_plot_residuals.py
Fits a polynomial and subtracts it, then plots result.
"""
import matplotlib as mpl
import seaborn as sns
import tables as tb
from leda_cal.leda_cal import *
from leda_cal.skymodel import *
from leda_cal.dpflgr import *
sns.set_style('ticks')
sns.set_context("paper",font_scale=1.5)
def fit_poly(x, y, n=5, log=True):
""" Fit a polynomial to x, y data
x (np.array): x-axis of data (e.g. frequency)
y (np.array): y-axis of data (e.g temperature)
n (int): number of terms in polynomial (defaults to 5)
"""
x_g = x
x = np.ma.array(x, mask=y.mask).compressed()
y = y.compressed()
if log:
print "HERE"
yl = np.log10(y)
else:
yl = y
fit = np.polyfit(x, yl, n)
print fit
p = np.poly1d(fit)
if log:
return 10**(p(x_g))
else:
return p(x_g)
def fit_poly_log(x, y, n=5):
""" Fit a polynomial to x, y data
x (np.array): x-axis of data (e.g. frequency)
y (np.array): y-axis of data (e.g temperature)
n (int): number of terms in polynomial (defaults to 5)
"""
x_g = x
x = np.ma.array(x, mask=y.mask).compressed()
y = y.compressed()
yl = np.log10(y)
fit = np.polyfit(x, yl, n)
print fit
p = np.poly1d(fit)
return 10**(p(x_g))
def quicklook(filename):
h5 = tb.open_file(filename)
T_ant = apply_calibration(h5)
f_leda = T_ant['f']
ant_ids = ['252A', '254A', '255A']
pol_id = 'y'
print("Plotting...")
fig, ax = plt.subplots(figsize=(8, 6))
mid = T_ant["252A"].shape[0]/2
sl = 250
d0 = T_ant[ant_ids[0]][mid-sl:mid+sl]
d1 = T_ant[ant_ids[1]][mid-sl:mid+sl]
d2 = T_ant[ant_ids[2]][mid-sl:mid+sl]
d0 = rfi_flag(d0, freqs=f_leda)
d0 = np.median(d0, axis=0)
d1 = rfi_flag(d1, freqs=f_leda)
d1 = np.median(d1, axis=0)
d2 = rfi_flag(d2, freqs=f_leda)
d2 = np.median(d2, axis=0)
#plt.imshow(d0, cmap='viridis', aspect='auto')
#plt.colorbar()
#plt.show()
#exit()
print d0
plt.plot(f_leda, d0 - fit_poly_log(f_leda, d0, 5), label=ant_ids[0])
plt.plot(f_leda, d1 - fit_poly_log(f_leda, d1, 5), label=ant_ids[1])
plt.plot(f_leda, d2 - fit_poly_log(f_leda, d2, 5), label=ant_ids[2])
plt.xlim(40, 85)
plt.minorticks_on()
#plt.ylim(500, 7000)
ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator())
ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator())
plt.xlabel("Frequency [MHz]")
plt.ylabel("Temperature [K]")
plt.legend(frameon=False)
plt.show()
if __name__ == "__main__":
import sys
try:
filename = sys.argv[1]
except:
print "USAGE: ./quicklook.py filename_of_hdf5_observation"
exit()
quicklook(filename)