-
Notifications
You must be signed in to change notification settings - Fork 0
/
mu_from_maps.py
89 lines (73 loc) · 2.81 KB
/
mu_from_maps.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
import time, sys, os
import numpy as np
import warnings
warnings.filterwarnings('ignore')
from astropy.table import Table
from astropy.io import fits
from astropy.wcs import WCS
from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.cosmology import FlatLambdaCDM
cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
def rt_dir():
rt_roar = '/storage/home/bbw5389/group/'
rt_mac = '/Users/bwang/research/'
dat_dirs = [rt_roar, rt_mac]
for _dir in dat_dirs:
if os.path.isdir(_dir): return _dir
gamma_fname = rt_dir()+'uncover_sps_gen1/phot_catalog/low_res/hlsp_uncover_model_a2744_zitrin-dPIE-PIEMD_gamma.fits'
if not os.path.exists(gamma_fname):
gamma_fname = rt_dir()+'uncover_sps_gen1/phot_catalog/low_res/hlsp_uncover_model_a2744_zitrin-dPIE-PIEMD_gamma.fits.gz'
gamma_map = fits.getdata(gamma_fname, ext=0)
wcs = WCS(fits.getheader(gamma_fname))
kappa_fname = rt_dir()+'uncover_sps_gen1/phot_catalog/low_res/hlsp_uncover_model_a2744_zitrin-dPIE-PIEMD_kappa.fits'
if not os.path.exists(kappa_fname):
kappa_fname = rt_dir()+'uncover_sps_gen1/phot_catalog/low_res/hlsp_uncover_model_a2744_zitrin-dPIE-PIEMD_kappa.fits.gz'
kappa_map = fits.getdata(kappa_fname, ext=0)
def mu_from_kappa_gamma(kappa, gamma):
res = (1-kappa)**2 - gamma**2
res = np.absolute(1.0/res)
return res
def xy_in_kappa_and_gamma(ra, dec, verbose=False):
'''get pixel coords for the maps
'''
px, py = wcs.wcs_world2pix(ra, dec, 0)
px = int(np.round(px, 0))
py = int(np.round(py, 0))
if verbose:
print('px, py', px, py)
return (px, py)
def scale_mu(zred, px, py, lens_zred=0.308, verbose=False):
if zred <= lens_zred:
if verbose:
print('scale_mu:', zred, '<=', lens_zred)
return 1
try:
_kappa = kappa_map[py, px]
_gamma = gamma_map[py, px]
if verbose:
print(_kappa, _gamma)
dds = cosmo.angular_diameter_distance_z1z2(lens_zred, zred)
ds = cosmo.angular_diameter_distance(zred)
dist_ratio = dds/ds
kappa_scaled = _kappa * dist_ratio
gamma_scaled = _gamma * dist_ratio
if verbose:
print(kappa_scaled, gamma_scaled)
mu = mu_from_kappa_gamma(kappa=kappa_scaled, gamma=gamma_scaled)
if verbose:
print('mu', mu)
return mu.value
except:
if verbose:
print('outside lensing model FoV')
return 1
if __name__ == "__main__":
# example
idx = 41611 - 1
cat = Table.read(rt_dir()+'uncover_sps_gen1/sps_catalog/UNCOVER_v5.2.0_LW_SUPER_SPScatalog_spsv0.1.fits')
obj_from_cat = cat[idx]
ra, dec = obj_from_cat['ra']*u.deg, obj_from_cat['dec']*u.deg
px, py = xy_in_kappa_and_gamma(ra, dec)
mu = scale_mu(obj_from_cat['z_50'], px, py, verbose=True)
print(obj_from_cat['id'], 'mu = ', mu)