-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.py
222 lines (199 loc) · 9.48 KB
/
debug.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter, LogLocator
import numpy as np
# def plot_fgmodels( tsz, ksz, cib_p, cib_c, radio, tsz_cib, gal_cirrus ):
#
# total = tsz + ksz + cib_p + cib_c + radio + tsz_cib
#
# # make a plot with 3 columns and 2 rows
# fig = plt.figure(figsize=(10,8))
# plt.rcParams['axes.titley'] = 1.0 # y is in axes-relative coordinates.
# plt.rcParams['axes.titlepad'] = -14
# gs = fig.add_gridspec(2, 3, hspace=0, wspace=0)
# (ax1, ax2, ax3), (ax4, ax5, ax6) = gs.subplots(sharex='col', sharey='row')
#
#
# ind = {0:0, 1:3, 2:5, 3:1, 4:2, 5:4}
# titles = ['90x90', '150x150', '220x220', '90x150', '90x220', '150x220']
#
# for i,ax in enumerate(fig.get_axes()):
#
# ax.set_title(titles[i])
# ax.plot(total[ind[i]], color='black', label='Total')
# ax.plot(tsz[ind[i]], color='blue', label='tSZ')
# ax.plot(ksz[ind[i]], color='blue', linestyle='dashed', label='kSZ')
# ax.plot(cib_p[ind[i]], color='orange', label='CIB')
# ax.plot(cib_c[ind[i]], color='orange', linestyle='dashed', label='CIB Clustering')
# ax.plot(radio[ind[i]], color='lime', label='Radio Poisson')
# ax.plot(tsz_cib[ind[i]], color='violet', label='tsz_cib')
# ax.plot(gal_cirrus[ind[i]], color='red', label='Cirrus')
#
# ax.label_outer()
# ax.set_xlim(2000, 11000)
# ax.set_ylim(0.4, 1200)
# ax.set_yscale('log')
# # ax.yaxis.set_ticks_position('both')
# # ax.yaxis.set_major_formatter(ScalarFormatter())
# # set minor ticks as inout
# ax.tick_params(axis='both', direction='inout')
#
# # Hide x labels and tick labels for last row, last two columns so that they don't overlap
# for ax in [ax5, ax6]:
# ax.xaxis.get_major_ticks()[0].label1.set_visible(False)
#
# # Set super y label
# fig.text(0.04, 0.5, '$\\frac{\ell (\ell+1)}{2 \pi} C_{\ell}^{TT} ( \mu K^2)$', va='center', rotation='vertical', fontsize=18, fontweight='bold')
# fig.text(0.5, 0.12, '$\ell$', ha='center', fontsize=18, fontweight='bold')
#
# plt.subplots_adjust(bottom=0.2)
# plt.legend(loc='lower center', bbox_to_anchor=(-0.5, -0.55),
# ncol=3, fancybox=True, shadow=True)
# plt.savefig('/home/pc/codes/spt/highlTT_likelihood/foregrounds.png')
#
# return
from matplotlib.ticker import ScalarFormatter, FixedLocator
def plot_fgmodels(tsz, ksz, cib_p, cib_c, radio, tsz_cib, gal_cirrus):
total = [tsz[i] + ksz[i] + cib_p[i] + cib_c[i] + radio[i] + tsz_cib[i] for i in range(6)]
# make a plot with 3 columns and 2 rows
fig = plt.figure(figsize=(12, 8))
plt.rcParams['axes.titley'] = 1.0
plt.rcParams['axes.titlepad'] = -14
gs = fig.add_gridspec(2, 3, hspace=0, wspace=0)
(ax1, ax2, ax3), (ax4, ax5, ax6) = gs.subplots(sharex='col', sharey='row')
ind = {0: 0, 1: 3, 2: 5, 3: 1, 4: 2, 5: 4}
titles = ['90x90', '150x150', '220x220', '90x150', '90x220', '150x220']
colors = {
'total': 'black',
'tsz': 'blue',
'ksz': 'teal',
'cib_p': 'orange',
'cib_c': 'darkorange',
'radio': 'limegreen',
'tsz_cib': 'purple',
'gal_cirrus': 'red'
}
for i, ax in enumerate(fig.get_axes()):
ax.set_title(titles[i], fontsize=12)
x = np.arange(len(total[ind[i]])) # Assuming all arrays have the same length
ax.plot(total[ind[i]], color=colors['total'], label='Total', linewidth=1.5)
ax.plot(tsz[ind[i]], color=colors['tsz'], label='tSZ', linewidth=1.2)
ax.plot(ksz[ind[i]], color=colors['ksz'], linestyle='dashed', label='kSZ', linewidth=1.2)
ax.plot(cib_p[ind[i]], color=colors['cib_p'], label='CIB', linewidth=1.2)
ax.plot(cib_c[ind[i]], color=colors['cib_c'], linestyle='dashed', label='CIB Clustering', linewidth=1.2)
ax.plot(radio[ind[i]], color=colors['radio'], label='Radio Poisson', linewidth=1.2)
ax.plot(tsz_cib[ind[i]], color=colors['tsz_cib'], label='tSZ x CIB', linewidth=1.2)
ax.plot(gal_cirrus[ind[i]], color=colors['gal_cirrus'], label='Cirrus', linewidth=1.2)
ax.label_outer()
ax.set_xlim(2000, 11000)
ax.set_ylim(0.4, 1200)
ax.set_yscale('log')
ax.tick_params(axis='both', direction='inout', length=6, width=1.5)
ax.tick_params(axis='both', which='minor', length=4, width=1)
ax.grid(True, which='both', linestyle='--', linewidth=0.5)
# Set the y-axis major ticks to only show specific values
ax.yaxis.set_major_locator(FixedLocator([1, 10, 100, 1000]))
ax.yaxis.set_major_formatter(ScalarFormatter())
for ax in [ax5, ax6]:
ax.xaxis.get_major_ticks()[0].label1.set_visible(False)
fig.text(0.04, 0.5, '$\\frac{\ell (\ell+1)}{2 \pi} C_{\ell}^{TT} ( \mu K^2)$', va='center', rotation='vertical', fontsize=16, fontweight='bold')
fig.text(0.5, 0.06, '$\ell$', ha='center', fontsize=16, fontweight='bold')
plt.subplots_adjust(bottom=0.15)
handles, labels = ax1.get_legend_handles_labels()
fig.legend(handles, labels, loc='lower center', bbox_to_anchor=(0.5, -0.05),
ncol=4, fancybox=True, shadow=True, fontsize=12)
plt.savefig('/home/pc/codes/spt/highlTT_likelihood/foregrounds.png', bbox_inches='tight')
return
# def plot_fgmodels1(tsz, ksz, cib_p, cib_c, radio, tsz_cib, gal_cirrus):
# # Total signal calculation
# total = tsz + ksz + cib_p + cib_c + radio + tsz_cib
#
# # Create a figure with more space and clearer layout
# fig, axes = plt.subplots(2, 3, figsize=(15, 10))
# fig.subplots_adjust(hspace=0.4, wspace=0.3)
#
# labels = ['Total', 'tSZ', 'kSZ', 'CIB', 'CIB Clustering', 'Radio Poisson', 'tsz_cib', 'Cirrus']
# colors = ['black', 'blue', 'blue', 'orange', 'orange', 'lime', 'violet', 'red']
# linestyles = ['-', '-', '--', '-', '--', '-', '-', '-']
#
# # Loop through each subplot
# for i, ax in enumerate(axes.flatten()):
# if i < len(total):
# # Plot the components
# ax.plot(total[i], color='black', label='Total')
# ax.plot(tsz[i], color='blue', label='tSZ')
# ax.plot(ksz, color='blue', linestyle='dashed', label='kSZ')
# ax.plot(cib_p[i], color='orange', label='CIB')
# ax.plot(cib_c[i], color='orange', linestyle='dashed', label='CIB Clustering')
# ax.plot(radio[i], color='lime', label='Radio Poisson')
# ax.plot(tsz_cib[i], color='violet', label='tsz_cib')
# ax.plot(gal_cirrus[i], color='red', label='Cirrus')
#
# # Set titles for each subplot
# resolutions = ['90x90', '90x150', '90x220', '150x150', '150x220', '220x220']
# ax.set_title(resolutions[i])
#
# # Set x and y limits and scale
# ax.set_xlim(2000, 11000)
# ax.set_ylim(0.4, 1200)
# ax.set_yscale('log')
#
# # Customize tick parameters
# ax.tick_params(axis='both', direction='inout', which='both')
#
# # Hide x labels for bottom row except the last column
# if i in [0, 1, 2]:
# ax.set_xlabel('') # Hide x labels for top row
# if i in [3, 4]:
# ax.set_xlabel('') # Hide x labels for bottom row
#
#
# # Set common labels for axes and overall figure text
# fig.text(0.5, 0.04, '$\ell$', ha='center', fontsize=18, fontweight='bold')
# fig.text(0.04, 0.5, '$\\frac{\ell (\ell+1)}{2 \pi} C_{\ell}^{TT} ( \mu K^2)$',
# va='center', rotation='vertical', fontsize=18, fontweight='bold')
#
# # Adjust layout for better visibility
# # plt.tight_layout()
#
# plt.subplots_adjust(bottom=0.2)
# plt.legend(loc='lower center', bbox_to_anchor=(-0.5, -0.55), ncol=3, fancybox=True, shadow=True)
# plt.savefig('/home/pc/codes/spt/highlTT_likelihood/foregrounds.png')
#
# # Save the plot
# plt.savefig('/home/pc/codes/spt/highlTT_likelihood/foregrounds.png')
#
# return
#
# plot the covmat
def plot_covmat(covmat):
spectra = ['90x90', '90x150', '90x220', '150x150', '150x220', '220x220']
# make a figure with 6 subplots of the covariance matrices
fig, axs = plt.subplots(2, 3, figsize=(15, 10))
axs = axs.ravel()
for i, spec in enumerate(spectra):
cov = covmat[ i, :, i, :]
im = axs[i].imshow(cov, cmap='viridis')
axs[i].set_title(f'{spec}')
# fig.colorbar(im, ax=axs[i])
plt.tight_layout()
# plot the 144x144 covariance matrix
# plt.imshow(covmat, cmap='viridis')
plt.savefig('/home/pc/codes/spt/highlTT_likelihood/covmat.png')
return
# plot the bandpowers with the model cls
def plot_bandpowers(bandpowers, model_cls, covmat):
fig, axs = plt.subplots(2, 3, figsize=(15, 10))
axs = axs.ravel()
spectra = ['90x90', '90x150', '90x220', '150x150', '150x220', '220x220']
errs = np.sqrt(np.diag(covmat))
for i, spec in enumerate(spectra):
# axs[i].semilogy( bandpowers[i*24:(i+1)*24], label='Bandpowers')
axs[i].semilogy( model_cls[i*24:(i+1)*24], label='Model Cls')
# add error bars
axs[i].errorbar(np.arange(24), bandpowers[i*24:(i+1)*24], yerr=errs[i*24:(i+1)*24], fmt='none', capsize=3, capthick=2, elinewidth=2, alpha=0.5, color='black')
# axs[i].fill_between(np.arange(24), model_cls[i*24:(i+1)*24]-errs[i*24:(i+1)*24], model_cls[i*24:(i+1)*24]+errs[i*24:(i+1)*24], alpha=0.5,)
axs[i].set_title(f'{spec}')
axs[i].legend()
plt.tight_layout()
plt.savefig('/home/pc/codes/spt/highlTT_likelihood/bandpowers.png')
return