-
Notifications
You must be signed in to change notification settings - Fork 0
/
knife.py
47 lines (35 loc) · 1.24 KB
/
knife.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
'''
Make jackknife regions.
'''
from . import utils
from . import kernel
import numpy as np
import healpy as hp
def knife_rand(frand, njr, nra, rra, nside=None):
'''Make jackknife regions with randoms.
Columns: [RA, DEC, redshift, weight].'''
rand = utils.load_data_pd(frand, tp='knife')
d_dec = kernel.knife(rand, njr, nra, rra)
jk_bounds = kernel.make_jk_bounds(d_dec)
if nside is None:
return jk_bounds
else:
jk_map = kernel.make_jk_map(d_dec, nside)
return jk_bounds, jk_map
def knife_mask(fmask, njr, nra, rra, nside):
'''Make jackknife regions with mask.
Value on each pixel should be in range [0, 1] or hp.UNSEEN+(0,1].'''
print('>> Loading mask: {}'.format(fmask))
mask = hp.read_map(fmask)
nside = hp.get_nside(mask)
npix = hp.nside2npix(nside)
ipix = np.array([i for i in range(npix)])
# cut off the pixels with value 0 or UNSEEN
idx = np.where((mask != 0.) & (mask != hp.UNSEEN))
mask, ipix = mask[idx], ipix[idx]
theta, phi = hp.pix2ang(nside, ipix)
ra, dec = utils.get_ra_dec(theta, phi)
data = np.column_stack((ra, dec, mask))
d_dec = kernel.knife(data, njr, nra, rra)
jk_map = kernel.make_jk_map(d_dec, nside)
return jk_map