Skip to content

Commit 5d4c812

Browse files
committed
reformatting
1 parent bc68d38 commit 5d4c812

1 file changed

Lines changed: 79 additions & 24 deletions

File tree

pycs/sparsity/mrs/mrs_tools.py

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def g2k(g1, g2):
107107
ke = hp.alm2map(ae, nside, pol=False)
108108
return ke
109109

110+
110111
def k2g(ke):
111112
nside = gnside(ke)
112113
ae = hp.map2alm(ke, 1, pol=False)
@@ -244,6 +245,7 @@ def tol(map, lmax_amin, amin=False):
244245

245246
# Spherical harmonic transform : Code from Remi Carloni Gertosio
246247

248+
247249
def map2alm(maps, lmax=None, iter=3):
248250
"""Computes the alm of a Healpix map.
249251
@@ -264,13 +266,15 @@ def map2alm(maps, lmax=None, iter=3):
264266

265267
if len(np.shape(maps)) == 1:
266268
if lmax is None:
267-
lmax = 3*hp.get_nside(maps)
269+
lmax = 3 * hp.get_nside(maps)
268270
return hp.sphtfunc.map2alm(maps, lmax=lmax, iter=iter)
269271

270272
n = np.shape(maps)[0]
271273
if lmax is None:
272-
lmax = 3*hp.get_nside(maps[0, :])
273-
return np.array([hp.sphtfunc.map2alm(maps[i, :], lmax=lmax, iter=iter) for i in range(n)])
274+
lmax = 3 * hp.get_nside(maps[0, :])
275+
return np.array(
276+
[hp.sphtfunc.map2alm(maps[i, :], lmax=lmax, iter=iter) for i in range(n)]
277+
)
274278

275279

276280
def alm2map(alms, nside):
@@ -322,11 +326,23 @@ def alm_product(alms, filters):
322326
n = np.shape(alms)[0]
323327

324328
if dim_filters == 1:
325-
return np.array([hp.sphtfunc.smoothalm(alms[i, :], beam_window=filters, verbose=False, inplace=False)
326-
for i in range(n)])
327-
328-
return np.array([hp.sphtfunc.smoothalm(alms[i, :], beam_window=filters[i, :], verbose=False, inplace=False)
329-
for i in range(n)])
329+
return np.array(
330+
[
331+
hp.sphtfunc.smoothalm(
332+
alms[i, :], beam_window=filters, verbose=False, inplace=False
333+
)
334+
for i in range(n)
335+
]
336+
)
337+
338+
return np.array(
339+
[
340+
hp.sphtfunc.smoothalm(
341+
alms[i, :], beam_window=filters[i, :], verbose=False, inplace=False
342+
)
343+
for i in range(n)
344+
]
345+
)
330346

331347

332348
def convolve(maps, filters, lmax=None, nside=None):
@@ -385,7 +401,7 @@ def anafast(maps, lmax=None, iter=3):
385401

386402
if len(np.shape(maps)) == 1:
387403
if lmax is None:
388-
lmax = 3*hp.get_nside(maps)
404+
lmax = 3 * hp.get_nside(maps)
389405
return hp.sphtfunc.anafast(maps, lmax=lmax, iter=iter)
390406

391407
n = np.shape(maps)[0]
@@ -417,6 +433,7 @@ def alm2cl(alms):
417433

418434
# Alm index computation
419435

436+
420437
def getsize(lmax):
421438
"""Returns the size of the array needed to store alm up to lmax.
422439
@@ -470,10 +487,20 @@ def npix2nside(npix):
470487

471488
return hp.npix2nside(npix)
472489

473-
490+
474491
# Plots
475492

476-
def mollview(maps, maps2=None, log=False, unit='', title='', minimum=None, maximum=None, cbar=True):
493+
494+
def mollview(
495+
maps,
496+
maps2=None,
497+
log=False,
498+
unit="",
499+
title="",
500+
minimum=None,
501+
maximum=None,
502+
cbar=True,
503+
):
477504
"""Plot one or more Healpix maps in Mollweide projection.
478505
479506
Parameters
@@ -513,13 +540,36 @@ def mollview(maps, maps2=None, log=False, unit='', title='', minimum=None, maxim
513540
if maps2 is not None:
514541
maximum = np.max([maximum, np.max(maps2)])
515542
if not log:
516-
def f(x): return x
543+
544+
def f(x):
545+
return x
546+
517547
else:
518-
def f(x): return np.log10(x - minimum + 1)
548+
549+
def f(x):
550+
return np.log10(x - minimum + 1)
551+
519552
for i in range(np.shape(maps)[0]):
520-
hp.mollview(f(maps[i, :]), fig=None, unit=unit, title=title, min=f(minimum), max=f(maximum), cbar=cbar)
553+
hp.mollview(
554+
f(maps[i, :]),
555+
fig=None,
556+
unit=unit,
557+
title=title,
558+
min=f(minimum),
559+
max=f(maximum),
560+
cbar=cbar,
561+
)
521562
if maps2 is not None:
522-
hp.mollview(f(maps2[i, :]), fig=None, unit=unit, title=title, min=f(minimum), max=f(maximum), cbar=cbar)
563+
hp.mollview(
564+
f(maps2[i, :]),
565+
fig=None,
566+
unit=unit,
567+
title=title,
568+
min=f(minimum),
569+
max=f(maximum),
570+
cbar=cbar,
571+
)
572+
523573

524574
def view_spec(inputs, lmax=None, alm_in=False):
525575
"""Plot the angular power spectrum of one or several maps.
@@ -549,14 +599,16 @@ def view_spec(inputs, lmax=None, alm_in=False):
549599

550600
plt.figure()
551601
for i in range(np.shape(inputs)[0]):
552-
plt.semilogy(cls[i, :], label='Source '+str(i+1))
553-
plt.xlabel('$l$')
554-
plt.ylabel('$c_l$')
602+
plt.semilogy(cls[i, :], label="Source " + str(i + 1))
603+
plt.xlabel("$l$")
604+
plt.ylabel("$c_l$")
555605
if np.shape(inputs)[0] != 1:
556606
plt.legend()
557607

608+
558609
# Miscellaneous
559610

611+
560612
def getidealbeam(lmax, cutmin=None, cutmax=None):
561613
"""Compute a beam, with value 1 until a first cutoff frequency and 0 after a second cutoff frequency. The transition
562614
is computed with a spline.
@@ -577,12 +629,12 @@ def getidealbeam(lmax, cutmin=None, cutmax=None):
577629
"""
578630

579631
if cutmin is None:
580-
cutmin = np.int64((lmax+1)/4)
632+
cutmin = np.int64((lmax + 1) / 4)
581633
if cutmax is None:
582-
cutmax = np.int64((lmax+1)/2)
583-
bl = np.zeros(lmax+1)
634+
cutmax = np.int64((lmax + 1) / 2)
635+
bl = np.zeros(lmax + 1)
584636
bl[0:cutmin] = 1
585-
bl[cutmin:cutmax] = spline2(cutmax-cutmin-1, 1, 1)
637+
bl[cutmin:cutmax] = spline2(cutmax - cutmin - 1, 1, 1)
586638
return bl
587639

588640

@@ -601,21 +653,24 @@ def getbeam(fwhm=100, lmax=512):
601653
np.ndarray
602654
(lmax+1,) float array, Gaussian-shaped beam
603655
"""
604-
656+
605657
tor = 0.0174533
606658
if len(np.shape(fwhm)) == 1:
607659
fwhm = np.expand_dims(fwhm, axis=1)
608660
F = fwhm / 60 * tor
609-
l = np.arange(0, lmax+1)
661+
l = np.arange(0, lmax + 1)
610662
ell = l * (l + 1)
611663
bl = np.exp(-ell * F * F / 16 / np.log(2))
612664
return bl
665+
666+
613667
################################################
614668

615669

616670
def mrs_hard_thresholding(alpha, Thres):
617671
alpha[np.abs(alpha) <= Thres] = 0
618672

673+
619674
################################################
620675

621676

0 commit comments

Comments
 (0)