Skip to content

Commit 96560f5

Browse files
author
Louis Thibaut
committed
new alms plotting function
1 parent 04b76a9 commit 96560f5

1 file changed

Lines changed: 33 additions & 28 deletions

File tree

pspy/sph_tools.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,11 @@ def get_pure_alms(so_map, window, niter, lmax):
173173
return np.array([alm,elm_p,blm_b])
174174

175175
def show_alm_triangle(
176-
alms,
177-
lmax,
178-
real=True,
179-
vmin=None,
180-
vmax=None,
181-
cmap="Oranges_r",
182-
xlims=None,
183-
ylims=None,
184-
title="Triangle",
185-
):
186-
r"""
176+
alms, lmax, vmin, vmax, real=True, cmap="seismic",
177+
xlims=None, ylims=None,
178+
title="Triangle", fig_file=None):
179+
180+
"""
187181
This routine is from the spt3g data release
188182
https://pole.uchicago.edu/public/data/quan26/index.html
189183
Parameters
@@ -203,27 +197,26 @@ def show_alm_triangle(
203197
title: str
204198
title, if multiple alm, will appended an integer number 0,1,2...
205199
"""
200+
206201

207202
import warnings
208-
209203
warnings.filterwarnings("ignore")
210-
211-
def triangle_plot(alm, title, vmin, vmax, xlims, ylims):
212-
triangle = np.full((lmax + 1, lmax + 1), np.nan)
213-
for l in range(lmax + 1):
214-
for m in range(0, l + 1):
204+
205+
def triangle_plot(alm, lmax, vmin, vmax, real, cmap, xlims, ylims, title, fig_file):
206+
207+
triangle = np.empty((lmax+1, lmax+1))
208+
triangle[:,:] = np.nan
209+
for l in range(lmax+1):
210+
for m in range(0, l+1):
215211
i = hp.Alm.getidx(lmax, l, m)
216212
if real:
217213
triangle[m, l] = alm[i].real
218214
else:
219215
triangle[m, l] = alm[i]
220216

221217
plt.figure(figsize=(7, 7))
222-
if vmin is None:
223-
vmin = np.min(triangle)
224-
if vmax is None:
225-
vmax = np.max(triangle)
226-
img = plt.imshow(triangle, origin="lower", vmin=vmin, vmax=vmax, cmap=cmap)
218+
img = plt.imshow(
219+
triangle, origin="lower", cmap=cmap, vmin=vmin, vmax=vmax)
227220
if xlims is None:
228221
xlims = [0, triangle.shape[1]]
229222
if ylims is None:
@@ -236,12 +229,24 @@ def triangle_plot(alm, title, vmin, vmax, xlims, ylims):
236229
plt.xlabel(r"$\ell$")
237230
plt.ylabel(r"$m$")
238231
plt.title(title)
239-
plt.show()
240-
plt.close()
241-
242-
kwargs = dict(vmin=vmin, vmax=vmax, xlims=xlims, ylims=ylims)
232+
if fig_file is not None:
233+
plt.savefig(fig_file)
234+
plt.clf()
235+
plt.close()
236+
else:
237+
plt.show()
238+
243239
if alms.ndim != 1:
244240
for i in range(len(alms)):
245-
triangle_plot(alms[i], f"{title}_{i}", **kwargs)
241+
if fig_file is not None:
242+
new_fig_file = fig_file + "_%d.png" % i
243+
else:
244+
new_fig_file = None
245+
if title is not None:
246+
new_title = title + "_%d" % i
247+
else:
248+
new_title = None
249+
250+
triangle_plot(alms[i], lmax, vmin, vmax, real, cmap, xlims, ylims, new_title, new_fig_file)
246251
else:
247-
triangle_plot(alms, title, **kwargs)
252+
triangle_plot(alms, lmax, vmin, vmax, real, cmap, xlims, ylims, title, f"{fig_file}.png")

0 commit comments

Comments
 (0)