-
Notifications
You must be signed in to change notification settings - Fork 1
/
kaiser_squires.py
62 lines (51 loc) · 1.84 KB
/
kaiser_squires.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
# This module contains the code for a simple flat Kaiser-Squires inversion
import numpy as np
import healpy as hp
def flat_KS_map(gmap):
"""Compute kappa maps from binned shear maps.
returns kappa_e and kappa_b
"""
nx = gmap.shape[1]
ny = gmap.shape[2]
# get frequencies
k1, k2 = np.meshgrid(np.fft.fftfreq(nx),
np.fft.fftfreq(ny))
g1 = np.fft.fft2(gmap[0])
g2 = np.fft.fft2(gmap[1])
denom = k1*k1 + k2*k2
denom[0, 0] = 1 # avoid division by 0
kap = ((k1*k1 - k2*k2) - 2j*(k1*k2)) * (g1 + 1j*g2) / denom
kap = np.fft.ifft2(kap)
return np.real(kap), np.imag(kap)
def healpix_KS_map(gmap, lmax=None, sigma=None):
"""
Computes kappa maps from a given healpix shear map (in ring format)
Adapted from `g2k_sphere` DES code:
https://github.com/chihway/massmapping/blob/master/utils/massmapping_utils.py
Parameters
----------
gmap: ndarray
Healpix convergence map (ring format)
lmax: int
Maximum multipole order
sigma: float
Gaussian smoothing applied to the alms [arcmin]
"""
nside = hp.npix2nside(gmap.shape[1])
if sigma is not None:
# convert to radians
sigma = sigma / 60./180*np.pi
if lmax is None:
lmax = 2*nside
KQU_maps = [np.zeros_like(gmap[0]), gmap[0], gmap[1]]
alms = hp.map2alm(KQU_maps, lmax=lmax, pol=True)
ell, emm = hp.Alm.getlm(lmax=lmax)
almsE = alms[1]*((ell*(ell+1.))/((ell+2.)*(ell-1)))**0.5
almsB = alms[2]*((ell*(ell+1.))/((ell+2.)*(ell-1)))**0.5
almsE[ell==0] = 0.0
almsB[ell==0] = 0.0
almsE[ell==1] = 0.0
almsB[ell==1] = 0.0
E_map = hp.alm2map(almsE, nside=nside, lmax=lmax, pol=False, sigma=sigma, verbose=False)
B_map = hp.alm2map(almsB, nside=nside, lmax=lmax, pol=False, sigma=sigma, verbose=False)
return E_map, B_map