-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_weight_demo.py
112 lines (71 loc) · 2.58 KB
/
run_weight_demo.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#__________________________________#
# GLaSS #
# Peter Taylor #
# Mullard Space Laboratory #
# University College London #
# 2018 #
#__________________________________#
import sys
import os
import GLaSS
import numpy as np
#__________________________________#
# setup and run cosmosis pipeline #
#__________________________________#
cosmosis_path = os.environ['COSMOSIS_SRC_DIR']
sys.path.append(cosmosis_path)
#you can also hard code the path to cosmosis
#in manually if above doesn't work
#sys.path.append('/Users/peter/codes/cosmosis/')
from cosmosis.runtime.config import Inifile
from cosmosis.runtime.pipeline import LikelihoodPipeline
cwd = os.getcwd()
file = cwd + '/demo-spherical-bessel.ini'
ini = Inifile(file)
pipeline = LikelihoodPipeline(ini)
pipeline.quiet = True
pipeline.debug = False
pipeline.timing = True
data = pipeline.run_parameters([])
#__________________________________#
# get back the data #
#__________________________________#
k_samps = data["3d_weak_lensing_output", "k_samps"]
r_samps = data["3d_weak_lensing_output", "r_samps"]
l_input_array = data["3d_weak_lensing_output", "l_input_array"]
resolution = 200
#__________________________________#
# make the weights #
#__________________________________#
# use spherical-bessel for example #
# note the cosmology is not the
# same as for the fiducial bessel
# weight so will not be exactly the
# same as default spherical-bessel
from scipy.special import spherical_jn
print 'computing and saving the weights'
for li in l_input_array:
weight = np.zeros((resolution, resolution))
for i in range(resolution):
for j in range(resolution):
weight[i,j] = spherical_jn(li, k_samps[j] * r_samps[i])
np.savetxt('weights/weight_%s.txt' %li, weight)
#__________________________________#
# run cosmosis with weighted
# lensing
#__________________________________#
file = cwd + '/demo-weighted-lensing.ini'
ini = Inifile(file)
pipeline = LikelihoodPipeline(ini)
pipeline.quiet = True
pipeline.debug = False
pipeline.timing = True
data = pipeline.run_parameters([])
#__________________________________#
# get back the data #
#__________________________________#
c_l_storage_array = data["3d_weak_lensing_output", "c_l_storage_array"]
shot_noise_storage_array = data["3d_weak_lensing_output", "shot_noise_storage_array"]
k_samps = data["3d_weak_lensing_output", "k_samps"]
z_samps = data["3d_weak_lensing_output", "z_samps"]
l_input_array = data["3d_weak_lensing_output", "l_input_array"]