CosmoWAP 0.5.1__tar.gz → 0.5.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cosmowap-0.5.1 → cosmowap-0.5.2}/PKG-INFO +2 -2
- {cosmowap-0.5.1 → cosmowap-0.5.2}/pyproject.toml +2 -2
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/PNG.py +18 -6
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/combined.py +7 -7
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/forecast/core.py +45 -23
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/forecast/covariances.py +38 -12
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/forecast/forecast.py +3 -3
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/forecast/posterior.py +168 -15
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/integrated.py +12 -4
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/lib/bk_plots.py +1 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/lib/utils.py +6 -2
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/main.py +13 -10
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/peak_background_bias.py +3 -4
- cosmowap-0.5.2/src/cosmo_wap/pk/IxS_components.py +576 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/PNG.py +32 -9
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/combined.py +33 -10
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/cov.py +4 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/int.py +75 -100
- cosmowap-0.5.2/src/cosmo_wap/pk/int_components.py +1124 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/survey_params.py +4 -4
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmowap.egg-info/PKG-INFO +2 -2
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmowap.egg-info/SOURCES.txt +1 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmowap.egg-info/requires.txt +1 -1
- cosmowap-0.5.1/src/cosmo_wap/pk/int_components.py +0 -832
- {cosmowap-0.5.1 → cosmowap-0.5.2}/LICENSE.txt +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/README.md +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/setup.cfg +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/__init__.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/GR0.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/GR1.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/GR2.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/GR_0.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/GR_1.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/GR_2.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/PNG_.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/RR1.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/RR2.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/RR_1.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/WA1.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/WA2.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/WARR.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/WA_1.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/WA_2.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/WSGR.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/__init__.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/bk/cov.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/data_library/SKAO1Data.txt +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/data_library/SKAO2Data.txt +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/data_library/k_modes.txt +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/data_library/snr_surveyparams.txt +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/forecast/__init__.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/forecast/mpi_mcmc.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/lib/__init__.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/lib/betas.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/lib/integrate.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/lib/luminosity_funcs.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/Pk_0.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/Pk_WS.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/Pk_WSGR.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/__init__.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/covWS.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmo_wap/pk/covWSGR.py +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmowap.egg-info/dependency_links.txt +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/src/cosmowap.egg-info/top_level.txt +0 -0
- {cosmowap-0.5.1 → cosmowap-0.5.2}/tests/test-cosmowap.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cosmowap
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Summary: package for computing power spectra and bispectra
|
|
5
5
|
Author-email: Chris Addis <c.l.j.addis@qmul.ac.uk>
|
|
6
6
|
License: MIT
|
|
@@ -16,7 +16,7 @@ Requires-Dist: scipy
|
|
|
16
16
|
Requires-Dist: matplotlib
|
|
17
17
|
Requires-Dist: tqdm
|
|
18
18
|
Requires-Dist: cython
|
|
19
|
-
Requires-Dist: classy
|
|
19
|
+
Requires-Dist: classy<3.3.2.0
|
|
20
20
|
Requires-Dist: chainconsumer
|
|
21
21
|
Requires-Dist: cobaya
|
|
22
22
|
Dynamic: license-file
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cosmowap"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.2"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Chris Addis", email="c.l.j.addis@qmul.ac.uk" },
|
|
10
10
|
]
|
|
@@ -24,7 +24,7 @@ dependencies = [
|
|
|
24
24
|
"matplotlib",
|
|
25
25
|
"tqdm",
|
|
26
26
|
"cython",
|
|
27
|
-
"classy",
|
|
27
|
+
"classy < 3.3.2.0",
|
|
28
28
|
"chainconsumer",
|
|
29
29
|
"cobaya"
|
|
30
30
|
]
|
|
@@ -6,7 +6,9 @@ class Loc:
|
|
|
6
6
|
def ylm(l,m,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,sigma=None):
|
|
7
7
|
return ylm(bk.Loc_,l,m,cosmo_funcs,k1,k2,k3=k3,theta=theta,zz=zz,r=r,s=s,sigma=sigma)
|
|
8
8
|
|
|
9
|
-
def l0(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1):
|
|
9
|
+
def l0(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1,fNL_loc=None,**kwargs):
|
|
10
|
+
if fNL_loc:
|
|
11
|
+
fNL = fNL_loc # if defined use as fNL
|
|
10
12
|
|
|
11
13
|
#get generic cosmology parameters
|
|
12
14
|
k1,k2,k3,theta,Pk1,Pk2,Pk3,_,_,_,_,_,_,_,K,C,f,D1,b1,b2,g2 = cosmo_funcs.get_params(k1,k2,k3,theta,zz)
|
|
@@ -20,7 +22,9 @@ class Loc:
|
|
|
20
22
|
|
|
21
23
|
return tmp_expr
|
|
22
24
|
|
|
23
|
-
def l2(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1):
|
|
25
|
+
def l2(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1,fNL_loc=None,**kwargs):
|
|
26
|
+
if fNL_loc:
|
|
27
|
+
fNL = fNL_loc # if defined use as fNL
|
|
24
28
|
|
|
25
29
|
#get generic cosmology parameters
|
|
26
30
|
k1,k2,k3,theta,Pk1,Pk2,Pk3,_,_,_,_,_,_,_,K,C,f,D1,b1,b2,g2 = cosmo_funcs.get_params(k1,k2,k3,theta,zz)
|
|
@@ -39,7 +43,9 @@ class Eq:
|
|
|
39
43
|
def ylm(l,m,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,sigma=None):
|
|
40
44
|
return ylm(bk.Eq_,l,m,cosmo_funcs,k1,k2,k3=k3,theta=theta,zz=zz,r=r,s=s,sigma=sigma)
|
|
41
45
|
|
|
42
|
-
def l0(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1):
|
|
46
|
+
def l0(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1,fNL_eq=None,**kwargs):
|
|
47
|
+
if fNL_eq:
|
|
48
|
+
fNL = fNL_eq # if defined use as fNL
|
|
43
49
|
|
|
44
50
|
#get generic cosmology parameters
|
|
45
51
|
k1,k2,k3,theta,Pk1,Pk2,Pk3,_,_,_,_,_,_,_,K,C,f,D1,b1,b2,g2 = cosmo_funcs.get_params(k1,k2,k3,theta,zz)
|
|
@@ -53,7 +59,9 @@ class Eq:
|
|
|
53
59
|
|
|
54
60
|
return tmp_expr
|
|
55
61
|
|
|
56
|
-
def l2(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1):
|
|
62
|
+
def l2(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1,fNL_eq=None,**kwargs):
|
|
63
|
+
if fNL_eq:
|
|
64
|
+
fNL = fNL_eq # if defined use as fNL
|
|
57
65
|
|
|
58
66
|
#get generic cosmology parameters
|
|
59
67
|
k1,k2,k3,theta,Pk1,Pk2,Pk3,_,_,_,_,_,_,_,K,C,f,D1,b1,b2,g2 = cosmo_funcs.get_params(k1,k2,k3,theta,zz)
|
|
@@ -72,7 +80,9 @@ class Orth:
|
|
|
72
80
|
def ylm(l,m,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,sigma=None):
|
|
73
81
|
return ylm(bk.Orth_,l,m,cosmo_funcs,k1,k2,k3=k3,theta=theta,zz=zz,r=r,s=s,sigma=sigma)
|
|
74
82
|
|
|
75
|
-
def l0(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1):
|
|
83
|
+
def l0(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1,fNL_orth=None,**kwargs):
|
|
84
|
+
if fNL_orth:
|
|
85
|
+
fNL = fNL_orth # if defined use as fNL
|
|
76
86
|
|
|
77
87
|
#get generic cosmology parameters
|
|
78
88
|
k1,k2,k3,theta,Pk1,Pk2,Pk3,_,_,_,_,_,_,_,K,C,f,D1,b1,b2,g2 = cosmo_funcs.get_params(k1,k2,k3,theta,zz)
|
|
@@ -86,7 +96,9 @@ class Orth:
|
|
|
86
96
|
|
|
87
97
|
return tmp_expr
|
|
88
98
|
|
|
89
|
-
def l2(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1):
|
|
99
|
+
def l2(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,fNL=1,fNL_orth=None,**kwargs):
|
|
100
|
+
if fNL_orth:
|
|
101
|
+
fNL = fNL_orth # if defined use as fNL
|
|
90
102
|
|
|
91
103
|
#get generic cosmology parameters
|
|
92
104
|
k1,k2,k3,theta,Pk1,Pk2,Pk3,_,_,_,_,_,_,_,K,C,f,D1,b1,b2,g2 = cosmo_funcs.get_params(k1,k2,k3,theta,zz)
|
|
@@ -4,14 +4,14 @@ import cosmo_wap.lib.integrate as integrate
|
|
|
4
4
|
import numpy as np
|
|
5
5
|
|
|
6
6
|
#so we want create a general bispectrum function like COV.cov()
|
|
7
|
-
def bk_func(term,l,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,m=0,sigma=None
|
|
7
|
+
def bk_func(term,l,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,m=0,sigma=None,**kwargs):
|
|
8
8
|
"""Convenience function to call bispectrum terms in a standardised format including FoG."""
|
|
9
9
|
|
|
10
10
|
if isinstance(term, list):# so we can pass term as a list of contribtuions
|
|
11
11
|
# then call recursively for each term
|
|
12
12
|
tot = []
|
|
13
13
|
for x in term:
|
|
14
|
-
tot.append(bk_func(x,l,cosmo_funcs,k1,k2,k3,theta,zz=zz,r=r,s=s,m=m,sigma=sigma
|
|
14
|
+
tot.append(bk_func(x,l,cosmo_funcs,k1,k2,k3,theta,zz=zz,r=r,s=s,m=m,sigma=sigma,**kwargs))
|
|
15
15
|
|
|
16
16
|
return np.sum(tot,axis=0)
|
|
17
17
|
|
|
@@ -21,14 +21,14 @@ def bk_func(term,l,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,m=0,sigma=N
|
|
|
21
21
|
else:
|
|
22
22
|
bk_class = term
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
if
|
|
26
|
-
|
|
24
|
+
wargs = {}
|
|
25
|
+
if term in ['Loc','Eq','Orth']: # then pass fNL as keyword argument
|
|
26
|
+
wargs = kwargs
|
|
27
27
|
|
|
28
28
|
if sigma is None:
|
|
29
|
-
return getattr(bk_class, f'l{l}')(cosmo_funcs,k1,k2,k3,theta,zz,r,s,**
|
|
29
|
+
return getattr(bk_class, f'l{l}')(cosmo_funcs,k1,k2,k3,theta,zz,r,s,**wargs)
|
|
30
30
|
else:
|
|
31
|
-
return bk.ylm(l,m,cosmo_funcs,k1,k2,k3,theta,zz,r,s,sigma=sigma,**
|
|
31
|
+
return bk.ylm(l,m,cosmo_funcs,k1,k2,k3,theta,zz,r,s,sigma=sigma,**wargs)
|
|
32
32
|
|
|
33
33
|
def ylm_picker(l,m,terms,*args,**kwargs):
|
|
34
34
|
"""Sums the contribution using ylm method from terms provided.
|
|
@@ -47,7 +47,7 @@ class Forecast(ABC):
|
|
|
47
47
|
z_bin (List[float]): Redshift bin as [z_min, z_max].
|
|
48
48
|
cosmo_funcs (Any): ClassWAP object has main functionality.
|
|
49
49
|
k_max (float, optional): Maximum k value. Defaults to 0.1.
|
|
50
|
-
s_k (float, optional): Scaling for k-bin width. Defaults to
|
|
50
|
+
s_k (float, optional): Scaling for k-bin width in units of k_f. Defaults to 2.
|
|
51
51
|
verbose (bool, optional): Verbosity flag. Defaults to False.
|
|
52
52
|
"""
|
|
53
53
|
|
|
@@ -149,41 +149,63 @@ class Forecast(ABC):
|
|
|
149
149
|
# so X is survey1 bias, Y survey2 bias and A both
|
|
150
150
|
h = dh
|
|
151
151
|
|
|
152
|
+
def deriv_bias(cf,param,h,tracers=['X','Y']):
|
|
153
|
+
"""Set-up to compute derivate wrt to bias amplitudes - return cosmo_funcs objects for small changes in bias"""
|
|
154
|
+
if False: #'b_1' in param: # so this does not really effect anything and is much slower
|
|
155
|
+
"""So linear bias set other biases - namely b_01 but potentially b_2 etc..."""
|
|
156
|
+
obj = [] # start as empty list and will fill with survey_params object(s)
|
|
157
|
+
for i,cf_survey in enumerate([cf.survey,cf.survey1]):
|
|
158
|
+
if cf.multi_tracer:
|
|
159
|
+
if cf_survey.t in tracers: # if we altering this tracer
|
|
160
|
+
obj.append(utils.modify_func(cf.survey_params[i], param, lambda f: f*(1+h)))
|
|
161
|
+
else:
|
|
162
|
+
obj.append(cf.survey_params[i]) # then is unchanged
|
|
163
|
+
else: # in single tracer
|
|
164
|
+
if cf_survey.t in tracers:
|
|
165
|
+
obj = utils.modify_func(cf.survey_params, param, lambda f: f*(1+h))
|
|
166
|
+
else:
|
|
167
|
+
obj = cf.survey_params # then is unchanged
|
|
168
|
+
|
|
169
|
+
cf = cf.update_survey(obj,verbose=False) # update cosmo_funcs with new survey_params
|
|
170
|
+
|
|
171
|
+
else:
|
|
172
|
+
# now for the case of working with Q and be
|
|
173
|
+
for cf_survey in [cf.survey,cf.survey1]:
|
|
174
|
+
if cf_survey.t in tracers:
|
|
175
|
+
cf_survey = utils.modify_func(cf_survey, param, lambda f: f*(1+h),copy=False)
|
|
176
|
+
|
|
177
|
+
return cf
|
|
178
|
+
|
|
152
179
|
def get_func_h(h,l):
|
|
153
180
|
cosmo_funcs_h = utils.create_copy(cosmo_funcs) # make copy is good
|
|
154
181
|
tmp_param = param[2:] # i.e get b_1 from X_b_1
|
|
155
|
-
|
|
156
|
-
if param[0]
|
|
157
|
-
|
|
158
|
-
cosmo_funcs_h.survey = utils.modify_func(cosmo_funcs_h.survey, tmp_param, lambda f: f*(1+h))
|
|
159
|
-
if cosmo_funcs_h.survey1.t1: # is tracer1?
|
|
160
|
-
cosmo_funcs_h.survey1 = utils.modify_func(cosmo_funcs_h.survey1, tmp_param, lambda f: f*(1+h))
|
|
161
|
-
elif param[0] == 'Y': # Y - so we affect tracer2
|
|
162
|
-
if not cosmo_funcs_h.survey.t1:
|
|
163
|
-
cosmo_funcs_h.survey = utils.modify_func(cosmo_funcs_h.survey, tmp_param, lambda f: f*(1+h))
|
|
164
|
-
if not cosmo_funcs_h.survey1.t1:
|
|
165
|
-
cosmo_funcs_h.survey1 = utils.modify_func(cosmo_funcs_h.survey1, tmp_param, lambda f: f*(1+h))
|
|
182
|
+
|
|
183
|
+
if param[0] in ['X','Y']:
|
|
184
|
+
cosmo_funcs_h = deriv_bias(cosmo_funcs_h,tmp_param,h,tracers=param[0])
|
|
166
185
|
else: # so affects both tracers (affect or effect)
|
|
167
|
-
cosmo_funcs_h
|
|
168
|
-
cosmo_funcs_h.survey1 = utils.modify_func(cosmo_funcs_h.survey1, tmp_param, lambda f: f*(1+h))
|
|
186
|
+
cosmo_funcs_h = deriv_bias(cosmo_funcs_h,tmp_param,h,tracers=['X','Y'])
|
|
169
187
|
|
|
170
188
|
if tmp_param in ['be','Q']: # reset betas - as they need to be recomputed with the new biases
|
|
171
189
|
cosmo_funcs_h.survey.betas = None
|
|
172
190
|
cosmo_funcs_h.survey1.betas = None
|
|
173
|
-
elif tmp_param in ['b_1']: # reset deriv - could make so we dont do it for both but it not time cosuming
|
|
174
|
-
cosmo_funcs_h.survey.deriv = {}
|
|
175
|
-
cosmo_funcs_h.survey1.deriv = {}
|
|
176
191
|
|
|
177
192
|
return func(term,l,cosmo_funcs_h, *args[1:], **kwargs) # args normally contains cosmo_funcs
|
|
178
193
|
|
|
179
|
-
elif param in ['fNL','t','r','s']:
|
|
194
|
+
elif param in ['fNL','fNL_loc','fNL_eq','fNL_orth','t','r','s']:
|
|
180
195
|
# mainly for fnl but for any kwarg. fNL shape is determine by whats included in base terms...
|
|
181
196
|
# also could make broadcastable....
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
197
|
+
if param in kwargs:
|
|
198
|
+
h = kwargs[param]*dh
|
|
199
|
+
def get_func_h(h,l):
|
|
200
|
+
wargs = copy.copy(kwargs)
|
|
201
|
+
wargs[param] += h
|
|
202
|
+
return func(term,l,*args, **wargs)
|
|
203
|
+
else: # then assume parameter is 0
|
|
204
|
+
h = 0.1
|
|
205
|
+
def get_func_h(h,l):
|
|
206
|
+
wargs = copy.copy(kwargs)
|
|
207
|
+
wargs[param] = h
|
|
208
|
+
return func(term,l,*args, **wargs)
|
|
187
209
|
|
|
188
210
|
elif param in ['Omega_m','Omega_cdm','Omega_b','A_s','sigma8','n_s','h']:
|
|
189
211
|
# so for cosmology we recall ClassWAP with updated class cosmology
|
|
@@ -5,7 +5,8 @@ from scipy.special import eval_legendre
|
|
|
5
5
|
import cosmo_wap.pk as pk
|
|
6
6
|
from cosmo_wap.lib import utils
|
|
7
7
|
|
|
8
|
-
from matplotlib import pyplot as plt
|
|
8
|
+
from matplotlib import pyplot as plt
|
|
9
|
+
from matplotlib.colors import LogNorm, SymLogNorm
|
|
9
10
|
|
|
10
11
|
class FullCov:
|
|
11
12
|
def __init__(self,fc,cosmo_funcs_list,cov_terms,sigma=None,n_mu=64,fast=False,nonlin=False):
|
|
@@ -120,7 +121,7 @@ class FullCov:
|
|
|
120
121
|
C[P^ab_{l1}, P^cd_{l2}](k) = ((2*l1 + 1)(2*l2 + 1) / N_k) ( Int (d(Omega_k) / 4*pi) * L_1(mu) *
|
|
121
122
|
[L_2(mu)*P^ac(k,mu)*P^bd(k,mu)^* + L_2(-mu)*P^ad(k,mu)*P^bc(k,mu)^*]"""
|
|
122
123
|
|
|
123
|
-
return (self.integrate_mu(a,c,b,d,terms,l1,l2,self.mu) + self.integrate_mu(a,d,b,c,terms,l1,l2,-self.mu))
|
|
124
|
+
return (1/2)*(self.integrate_mu(a,c,b,d,terms,l1,l2,self.mu) + self.integrate_mu(a,d,b,c,terms,l1,l2,-self.mu))
|
|
124
125
|
|
|
125
126
|
def get_single_tracer_ll(self,terms,l1,l2):
|
|
126
127
|
"""Get full single-tracer covariance for multipole pair"""
|
|
@@ -182,28 +183,53 @@ class FullCov:
|
|
|
182
183
|
|
|
183
184
|
return cov_mt
|
|
184
185
|
|
|
185
|
-
def plot_cov(self,ln,kn=0,real=True):
|
|
186
|
+
def plot_cov(self,ln,kn=0,real=True,log=True,vmin=None,vmax=None,cmap='RdBu',lnrwidth=None,**kwargs):
|
|
186
187
|
"""Lets plot the covariance"""
|
|
187
188
|
cov = self.get_cov(ln)
|
|
188
189
|
|
|
189
190
|
labels = []
|
|
190
|
-
ln = [0,1,2,3]
|
|
191
191
|
for l in ln:
|
|
192
192
|
if l & 1:
|
|
193
|
-
labels.append(rf"$P^{{
|
|
193
|
+
labels.append(rf"$P^{{BF}}_{l}$")
|
|
194
194
|
else: # If even
|
|
195
195
|
labels.extend([
|
|
196
|
-
rf"$P^{{
|
|
197
|
-
rf"$P^{{
|
|
198
|
-
rf"$P^{{
|
|
196
|
+
rf"$P^{{BB}}_{{{l}}}$",
|
|
197
|
+
rf"$P^{{BF}}_{{{l}}}$",
|
|
198
|
+
rf"$P^{{FF}}_{{{l}}}$"
|
|
199
199
|
])
|
|
200
200
|
|
|
201
|
-
plt.figure(figsize=(
|
|
201
|
+
plt.figure(figsize=(10,7))
|
|
202
202
|
if real:
|
|
203
|
-
|
|
203
|
+
if log:
|
|
204
|
+
if not vmin:
|
|
205
|
+
vmin = np.abs(cov[...,kn].real).min()
|
|
206
|
+
if not vmax:
|
|
207
|
+
vmax = np.abs(cov[...,kn].real).max()
|
|
208
|
+
|
|
209
|
+
if lnrwidth:
|
|
210
|
+
plt.pcolormesh(cov[...,kn].real, cmap=cmap,norm=SymLogNorm(linthresh=lnrwidth, linscale=1, vmin=-vmin, vmax=vmax))
|
|
211
|
+
else:
|
|
212
|
+
plt.pcolormesh(np.abs(cov[...,kn].real), cmap=cmap,norm=LogNorm(vmin, vmax=vmax))
|
|
213
|
+
|
|
214
|
+
else:
|
|
215
|
+
plt.pcolormesh(cov[...,kn].real, cmap=cmap)
|
|
204
216
|
else:
|
|
205
|
-
|
|
217
|
+
if log:
|
|
218
|
+
if not vmin:
|
|
219
|
+
vmin = np.abs(cov[...,kn].imag).min()
|
|
220
|
+
if not vmax:
|
|
221
|
+
vmax = np.abs(cov[...,kn].imag).max()
|
|
222
|
+
|
|
223
|
+
if lnrwidth:
|
|
224
|
+
plt.pcolormesh(cov[...,kn].imag, cmap=cmap,norm=SymLogNorm(linthresh=lnrwidth, linscale=1, vmin=-vmin, vmax=vmax))
|
|
225
|
+
else:
|
|
226
|
+
plt.pcolormesh(np.abs(cov[...,kn].imag), cmap=cmap,norm=LogNorm(vmin, vmax=vmax))
|
|
227
|
+
|
|
228
|
+
else:
|
|
229
|
+
plt.pcolormesh(cov[...,kn].imag, cmap=cmap)
|
|
230
|
+
|
|
206
231
|
plt.xticks(np.arange(0.5, len(labels) + 0.5), labels=labels)
|
|
207
232
|
plt.yticks(np.arange(0.5, len(labels) + 0.5), labels=labels)
|
|
208
|
-
plt.colorbar()
|
|
233
|
+
cbar = plt.colorbar()
|
|
234
|
+
cbar.set_label(r'$|C[P^{ab}_{\ell_i},P^{cd}_{\ell_j}](k)|$', **kwargs)
|
|
209
235
|
|
|
@@ -54,7 +54,7 @@ class FullForecast:
|
|
|
54
54
|
# we create 4 different cosmo_funcs objects for each tracer combination
|
|
55
55
|
cosmo_funcsXX = utils.create_copy(cosmo_funcs) # XX
|
|
56
56
|
cosmo_funcsXX.survey1 = cosmo_funcs.survey
|
|
57
|
-
cosmo_funcsXX.survey_params = cosmo_funcs.survey_params[0]
|
|
57
|
+
cosmo_funcsXX.survey_params = cosmo_funcs.survey_params[0]
|
|
58
58
|
cosmo_funcsXX.multi_tracer = False # now single tracer
|
|
59
59
|
cosmo_funcsXX.n_g = cosmo_funcsXX.survey.n_g
|
|
60
60
|
|
|
@@ -173,7 +173,7 @@ class FullForecast:
|
|
|
173
173
|
for i in tqdm(range(num_bins), disable=not verbose, desc="Bin Loop"):
|
|
174
174
|
# --- Covariance Calculation (once per bin) ---New method to compute and cache all derivatives and inverse covariances once.
|
|
175
175
|
if pkln:
|
|
176
|
-
pk_fc = PkForecast(self.z_bins[i], self.cosmo_funcs, k_max=self.k_max_list[i], s_k=self.s_k, cache=cache, all_tracer=all_tracer, cov_terms=cov_terms,cosmo_funcs_list=cosmo_funcs_list)
|
|
176
|
+
pk_fc = PkForecast(self.z_bins[i], self.cosmo_funcs, k_max=self.k_max_list[i], s_k=self.s_k, cache=cache, all_tracer=all_tracer, cov_terms=cov_terms, cosmo_funcs_list=cosmo_funcs_list)
|
|
177
177
|
if compute_cov:
|
|
178
178
|
pk_cov_mat = pk_fc.get_cov_mat(pkln, sigma=sigma)
|
|
179
179
|
inv_covs[i]['pk'] = pk_fc.invert_matrix(pk_cov_mat)
|
|
@@ -287,7 +287,7 @@ class FullForecast:
|
|
|
287
287
|
fish_mat = self.get_fish(param,terms=terms, pkln=pkln, bkln=bkln, t=t, r=r, s=s, verbose=verbose, sigma=sigma, bias_list=bias_term)
|
|
288
288
|
|
|
289
289
|
bfb = fish_mat.bias[-1] # is list containing a dictionary for each bias term
|
|
290
|
-
fish = np.diag(fish_mat.fisher_matrix) # is array
|
|
290
|
+
fish = np.diag(fish_mat.fisher_matrix) # is array - ignore marginalisation
|
|
291
291
|
|
|
292
292
|
return bfb,fish
|
|
293
293
|
|
|
@@ -13,6 +13,7 @@ from cosmo_wap.lib import utils
|
|
|
13
13
|
from matplotlib import pyplot as plt
|
|
14
14
|
import pickle
|
|
15
15
|
import warnings
|
|
16
|
+
from scipy import stats
|
|
16
17
|
|
|
17
18
|
from chainconsumer import ChainConsumer, Chain, Truth, PlotConfig, ChainConfig # plots with chainconsumer - https://samreay.github.io/ChainConsumer/
|
|
18
19
|
from cobaya import run
|
|
@@ -153,7 +154,7 @@ class BasePosterior(ABC):
|
|
|
153
154
|
|
|
154
155
|
return c,name
|
|
155
156
|
|
|
156
|
-
def add_chain_cov(self,c=None,bias_values=None,name=None,cov=None):
|
|
157
|
+
def add_chain_cov(self,c=None,bias_values=None,name=None,cov=None,param_list=None):
|
|
157
158
|
"""
|
|
158
159
|
Get chain from a covariance matrix - defualt is planck-covaraince-
|
|
159
160
|
But later uses inverse fisher matrices
|
|
@@ -164,15 +165,19 @@ class BasePosterior(ABC):
|
|
|
164
165
|
bias_values (dict, optional): Best fit bias on parameter mean - calculate using get_bias etc.
|
|
165
166
|
Keys should match parameter names, e.g., {'b_1': 1.0, 'sigma_8': 0.1}.
|
|
166
167
|
If not provided then default is 0.
|
|
168
|
+
name - name of chain
|
|
169
|
+
cov - covariance matrix, if none then defaults to planck parameter covariance
|
|
170
|
+
param_list - parameters to use, can take submatrix in full covariance
|
|
167
171
|
|
|
168
172
|
Returns:
|
|
169
173
|
ChainConsumer: ChainConsumer object with a brand new chain!
|
|
170
174
|
"""
|
|
171
175
|
if cov is None:
|
|
172
|
-
cov = self.planck_cov()
|
|
176
|
+
cov = self.planck_cov() # so if no covaraince provided then defaults is planck parameter covariance
|
|
173
177
|
param_list = [param for param in self.param_list if param in ['Omega_b','Omega_cdm','theta','tau','A_s','n_s']]
|
|
174
178
|
else:
|
|
175
|
-
|
|
179
|
+
if not param_list:
|
|
180
|
+
param_list = self.param_list
|
|
176
181
|
|
|
177
182
|
if bias_values:
|
|
178
183
|
if isinstance(bias_values, list):
|
|
@@ -238,12 +243,13 @@ class BasePosterior(ABC):
|
|
|
238
243
|
else:
|
|
239
244
|
# Auto-generate extents to fit all chains and truth lines
|
|
240
245
|
extents = {}
|
|
241
|
-
|
|
246
|
+
param_list = c.get_chain(name=c.get_names()[0]).data_columns
|
|
247
|
+
for i,param in enumerate(param_list):
|
|
242
248
|
mins, maxs = [], []
|
|
243
249
|
largest_error = 0
|
|
244
250
|
|
|
245
251
|
for chain_name in c.get_names():
|
|
246
|
-
samps = c.get_chain(name=chain_name).samples[
|
|
252
|
+
samps = c.get_chain(name=chain_name).samples[param]
|
|
247
253
|
mean, error = samps.mean(), samps.std()
|
|
248
254
|
mins.append(mean - width * error)
|
|
249
255
|
maxs.append(mean + width * error)
|
|
@@ -272,6 +278,29 @@ class BasePosterior(ABC):
|
|
|
272
278
|
fig.set_size_inches(current_size + 3)
|
|
273
279
|
|
|
274
280
|
return fig, c
|
|
281
|
+
|
|
282
|
+
def _setup_1Dplot(self,param,fontsize=22):
|
|
283
|
+
_, ax = plt.subplots(figsize=(8, 6))
|
|
284
|
+
# --- Customize the plot ---
|
|
285
|
+
ax.set_xlabel(self.latex[param], fontsize=fontsize)
|
|
286
|
+
ax.set_ylabel('')
|
|
287
|
+
ax.yaxis.set_ticks([]) # Hide y-axis ticks and labels
|
|
288
|
+
|
|
289
|
+
# Set x-axis limits and rotate ticks
|
|
290
|
+
#ax.set_xlim(min(x_values), max(x_values))
|
|
291
|
+
ax.tick_params(axis='x', labelsize=fontsize-8, rotation=45)
|
|
292
|
+
|
|
293
|
+
# Remove the box border (spines) for a cleaner look
|
|
294
|
+
ax.spines['top'].set_visible(False)
|
|
295
|
+
ax.spines['right'].set_visible(False)
|
|
296
|
+
ax.spines['left'].set_visible(False)
|
|
297
|
+
|
|
298
|
+
# Add vertical line at 0
|
|
299
|
+
ax.axvline(0, color='black', linestyle='--', linewidth=1.5)
|
|
300
|
+
|
|
301
|
+
#ax.autoscale(enable=True, axis='y', tight=True)
|
|
302
|
+
#ax.set_ylim(bottom=0)
|
|
303
|
+
return ax
|
|
275
304
|
|
|
276
305
|
class FisherMat(BasePosterior):
|
|
277
306
|
"""
|
|
@@ -440,6 +469,50 @@ class FisherMat(BasePosterior):
|
|
|
440
469
|
plt.tight_layout()
|
|
441
470
|
|
|
442
471
|
return fig, ax
|
|
472
|
+
|
|
473
|
+
def plot_1D(self, param, ci=0.68, ax=None, label=None, shade=True, color='royalblue', **kwargs):
|
|
474
|
+
"""
|
|
475
|
+
Plots a 1D Gaussian (Normal) PDF given a mean and standard deviation.
|
|
476
|
+
|
|
477
|
+
Args:
|
|
478
|
+
param (str): parameter to plot
|
|
479
|
+
ci (float, optional): The confidence interval to shade (e.g., 0.68 for 1-sigma). Defaults to 0.68.
|
|
480
|
+
ax (matplotlib.axes.Axes, optional): The axes object to plot on. If None, a new figure is created.
|
|
481
|
+
label (str, optional): The label for the x-axis.
|
|
482
|
+
shade (bool, optional): If True, shades the confidence interval.
|
|
483
|
+
color (str, optional): The color for the plot line and shade.
|
|
484
|
+
**kwargs: Additional keyword arguments passed to ax.plot().
|
|
485
|
+
"""
|
|
486
|
+
# --- 1. Set up the plot if an axis isn't provided ---
|
|
487
|
+
if not ax:
|
|
488
|
+
ax = self._setup_1Dplot(param,fontsize=22)
|
|
489
|
+
|
|
490
|
+
mean = self.bias[-1][param]
|
|
491
|
+
std_dev = self.get_error(param)
|
|
492
|
+
|
|
493
|
+
# --- 2. Define the Normal distribution using the provided mean and std_dev ---
|
|
494
|
+
norm_dist = stats.norm(loc=mean, scale=std_dev)
|
|
495
|
+
|
|
496
|
+
# --- 3. Determine the x-range for plotting ---
|
|
497
|
+
# A range of ±4 standard deviations from the mean covers >99.9% of the distribution
|
|
498
|
+
x_eval = np.linspace(mean - 4 * std_dev, mean + 4 * std_dev, 500)
|
|
499
|
+
pdf_values = norm_dist.pdf(x_eval)
|
|
500
|
+
|
|
501
|
+
# --- 4. Plot the main PDF curve ---
|
|
502
|
+
ax.plot(x_eval, pdf_values, color=color, **kwargs)
|
|
503
|
+
|
|
504
|
+
# --- 5. Shade the confidence interval ---
|
|
505
|
+
if shade:
|
|
506
|
+
# Calculate the interval boundaries using the Percent Point Function (inverse of CDF)
|
|
507
|
+
# This is more robust than assuming ci=0.68 is always 1-sigma
|
|
508
|
+
lower_bound, upper_bound = norm_dist.interval(ci)
|
|
509
|
+
|
|
510
|
+
# Create x values just for the shaded region
|
|
511
|
+
x_fill = np.linspace(lower_bound, upper_bound, 100)
|
|
512
|
+
y_fill = norm_dist.pdf(x_fill)
|
|
513
|
+
ax.fill_between(x_fill, y_fill, color=color, alpha=0.2)
|
|
514
|
+
|
|
515
|
+
return ax
|
|
443
516
|
|
|
444
517
|
def save(self, filename):
|
|
445
518
|
"""Save Fisher result to file."""
|
|
@@ -465,7 +538,7 @@ class FisherMat(BasePosterior):
|
|
|
465
538
|
class Sampler(BasePosterior):
|
|
466
539
|
"""MCMC Sampler with cobaya with ChainConsumer plots.
|
|
467
540
|
Assumes gaussian likelihood with parameter independent covariances."""
|
|
468
|
-
def __init__(self, forecast, param_list, terms=None, bias_list=None, pkln=None,bkln=None, R_stop=0.005, max_tries=200, name=None, planck_prior=False, **kwargs):
|
|
541
|
+
def __init__(self, forecast, param_list, terms=None, cov_terms=None, bias_list=None, pkln=None,bkln=None, R_stop=0.005, max_tries=200, name=None, planck_prior=False, **kwargs):
|
|
469
542
|
super().__init__(forecast, param_list, name=name)
|
|
470
543
|
|
|
471
544
|
self.pkln = pkln
|
|
@@ -487,7 +560,7 @@ class Sampler(BasePosterior):
|
|
|
487
560
|
|
|
488
561
|
all_terms = [term for term in terms+param_list+bias_list if term in self.cosmo_funcs.term_list] # get list of needed terms to compute full 'true' theory
|
|
489
562
|
# so this just gets total contribution - i.e. true theory - and also parameter independent covariance
|
|
490
|
-
self.data, self.inv_covs = forecast._precompute_derivatives_and_covariances([all_terms],pkln=pkln,bkln=bkln,verbose=False,fNL=0)
|
|
563
|
+
self.data, self.inv_covs = forecast._precompute_derivatives_and_covariances([all_terms],pkln=pkln,bkln=bkln,verbose=False,cov_terms=cov_terms,fNL=0)
|
|
491
564
|
|
|
492
565
|
# set up cobaya sampler - define priors, starting value and initial step
|
|
493
566
|
#standard term:
|
|
@@ -643,11 +716,18 @@ class Sampler(BasePosterior):
|
|
|
643
716
|
theory = self.get_theory(param_vals)
|
|
644
717
|
|
|
645
718
|
chi2 = 0
|
|
646
|
-
for bin_idx in range(len(self.forecast.z_bins)):
|
|
647
|
-
|
|
648
|
-
|
|
719
|
+
for bin_idx in range(len(self.forecast.z_bins)): # so loop over redshift bins...
|
|
720
|
+
if self.pkln: # for power spectrum
|
|
721
|
+
d1 = self.data[0][bin_idx]['pk'] - theory[bin_idx]['pk']
|
|
722
|
+
InvCov = self.inv_covs[bin_idx]['pk']
|
|
723
|
+
|
|
724
|
+
chi2 += np.sum(np.einsum('ik,ijk,jk->k', d1, InvCov, d1)).real
|
|
649
725
|
|
|
650
|
-
|
|
726
|
+
if self.bkln: # for bispectrum
|
|
727
|
+
d1 = self.data[0][bin_idx]['bk'] - theory[bin_idx]['bk']
|
|
728
|
+
InvCov = self.inv_covs[bin_idx]['bk']
|
|
729
|
+
|
|
730
|
+
chi2 += np.sum(np.einsum('ik,ijk,jk->k', d1, InvCov, d1)).real
|
|
651
731
|
|
|
652
732
|
return - (1/2)*chi2
|
|
653
733
|
|
|
@@ -655,32 +735,105 @@ class Sampler(BasePosterior):
|
|
|
655
735
|
"""Run cobaya sampler"""
|
|
656
736
|
self.updated_info, self.mcmc = run(self.info)
|
|
657
737
|
|
|
658
|
-
def add_chain(self,c=None,name=None,bins=12,skip_samples=0.3):
|
|
738
|
+
def add_chain(self,c=None,name=None,bins=12,skip_samples=0.3,param_list=None,**kwargs):
|
|
659
739
|
"""
|
|
660
740
|
Add MCMC sample as a chain to a ChainConsumer object.
|
|
661
741
|
|
|
662
742
|
Args:
|
|
663
743
|
c (ChainConsumer, optional): Existing ChainConsumer object to add chain to.
|
|
664
744
|
If None, creates a new ChainConsumer object.
|
|
745
|
+
name - name of chain
|
|
746
|
+
bins - Number of bins to plot posterior - more bins higher resolution
|
|
747
|
+
skip_samples - skip burn in of chains
|
|
748
|
+
param_list - plot subset of parameters
|
|
665
749
|
|
|
666
750
|
Returns:
|
|
667
751
|
ChainConsumer: ChainConsumer object with MCMC sample added as a chain.
|
|
668
752
|
"""
|
|
669
753
|
c,name = self._name_chain(c,name)
|
|
670
754
|
|
|
755
|
+
if not param_list:
|
|
756
|
+
param_list = self.param_list
|
|
757
|
+
|
|
671
758
|
# get pandas dataframe of samples
|
|
672
759
|
if hasattr(self,'mcmc'):
|
|
673
|
-
data_frame = self.mcmc.samples(skip_samples=skip_samples).data[
|
|
760
|
+
data_frame = self.mcmc.samples(skip_samples=skip_samples).data[param_list]
|
|
674
761
|
elif hasattr(self,'dataframe'):
|
|
675
762
|
data_frame = self.dataframe # loaded samples
|
|
676
763
|
else:
|
|
677
764
|
raise ValueError("Run/load a sample first!")
|
|
678
765
|
|
|
679
|
-
c.add_chain(Chain(samples=data_frame, name=name))
|
|
766
|
+
c.add_chain(Chain(samples=data_frame, name=name,**kwargs))
|
|
680
767
|
c.set_override(ChainConfig(bins=bins))
|
|
681
768
|
|
|
682
|
-
return c
|
|
769
|
+
return c
|
|
683
770
|
|
|
771
|
+
def get_summary(self,param,skip_samples=0.3,ci=0.68):
|
|
772
|
+
"""Get Median and n-sigma errors"""
|
|
773
|
+
# samples DataFrame
|
|
774
|
+
samples_df = self.mcmc.samples(skip_samples=skip_samples).data
|
|
775
|
+
|
|
776
|
+
param_series = samples_df[param]
|
|
777
|
+
|
|
778
|
+
# Determine the lower and upper quantiles from the confidence interval
|
|
779
|
+
lower_quantile = (1.0 - ci) / 2.0 # For ci=0.68, this is 0.16
|
|
780
|
+
upper_quantile = 1.0 - lower_quantile # For ci=0.68, this is 0.84
|
|
781
|
+
|
|
782
|
+
# Calculate the median and the bounds of the interval
|
|
783
|
+
median = param_series.quantile(0.50)
|
|
784
|
+
lower_bound = param_series.quantile(lower_quantile)
|
|
785
|
+
upper_bound = param_series.quantile(upper_quantile)
|
|
786
|
+
|
|
787
|
+
# Calculate the positive and negative errors
|
|
788
|
+
positive_error = upper_bound - median
|
|
789
|
+
negative_error = median - lower_bound
|
|
790
|
+
|
|
791
|
+
return median,positive_error,negative_error
|
|
792
|
+
|
|
793
|
+
def print_summary(self,skip_samples=0.3,ci=0.68):
|
|
794
|
+
"""Summarize chain"""
|
|
795
|
+
|
|
796
|
+
#samples dataframe
|
|
797
|
+
samples_df = self.mcmc.samples(skip_samples=skip_samples).data
|
|
798
|
+
|
|
799
|
+
print("---------------------------------------------------------")
|
|
800
|
+
# 3. Iterate through the list of parameter names
|
|
801
|
+
for param in self.param_list:
|
|
802
|
+
if param in samples_df.columns:
|
|
803
|
+
median,positive_error,negative_error = self.get_summary(param,skip_samples=skip_samples,ci=ci)
|
|
804
|
+
|
|
805
|
+
if False: # could use matplotlib to render strings...
|
|
806
|
+
print(rf"{self.latex[param]}: ${median:.2f}^{{+{positive_error:.2f}}}_{{-{negative_error:.2f}}}$")
|
|
807
|
+
else:
|
|
808
|
+
print(f"{param}: {median:.2f} (+{positive_error:.2f} / -{negative_error:.2f})")
|
|
809
|
+
|
|
810
|
+
def plot_1D(self,param,skip_samples=0.3,ci=0.68,ax=None,shade=True,color='royalblue',**kwargs):
|
|
811
|
+
"""1D PDF plots"""
|
|
812
|
+
if not ax:
|
|
813
|
+
ax = self._setup_1Dplot(param,fontsize=22)
|
|
814
|
+
|
|
815
|
+
# get sample for given param
|
|
816
|
+
sample_data = self.mcmc.samples(skip_samples=skip_samples).data[param]
|
|
817
|
+
# get approximate pdf function
|
|
818
|
+
kde = stats.gaussian_kde(sample_data)
|
|
819
|
+
|
|
820
|
+
if shade:
|
|
821
|
+
# get median and 1-sigma errors
|
|
822
|
+
m,uq,lq = self.get_summary(param)
|
|
823
|
+
|
|
824
|
+
# shade 1 sigma region
|
|
825
|
+
x_fill = np.linspace(m-lq, m+uq, 100)
|
|
826
|
+
y_fill = kde(x_fill)
|
|
827
|
+
ax.fill_between(x_fill, y_fill, color=color, alpha=0.2)
|
|
828
|
+
|
|
829
|
+
x_eval = np.linspace(sample_data.min() - 1, sample_data.max() + 1, 500)
|
|
830
|
+
pdf_values = kde(x_eval)
|
|
831
|
+
|
|
832
|
+
# Plot the main KDE curve
|
|
833
|
+
ax.plot(x_eval, pdf_values, color=color, **kwargs)
|
|
834
|
+
|
|
835
|
+
return ax
|
|
836
|
+
|
|
684
837
|
def save(self, filepath):
|
|
685
838
|
"""
|
|
686
839
|
Saves the Sampler's state to a file using pickle.
|
|
@@ -126,7 +126,7 @@ class BaseInt:
|
|
|
126
126
|
return np.where(x >K_MAX,self.cosmo_funcs.Pk(K_MAX)*(x/K_MAX)**(-3),self.cosmo_funcs.Pk(x))
|
|
127
127
|
|
|
128
128
|
@staticmethod
|
|
129
|
-
def single_int(func, *args, n=128, remove_div=True,**kwargs):
|
|
129
|
+
def single_int(func, *args, n=128, remove_div=True, source_func=None,**kwargs):
|
|
130
130
|
"""Do single integral for RSDxIntegrated term"""
|
|
131
131
|
|
|
132
132
|
nodes, weights = np.polynomial.legendre.leggauss(n) # legendre gauss - get nodes and weights for given n
|
|
@@ -147,11 +147,19 @@ class BaseInt:
|
|
|
147
147
|
int_grid = func(xd_nodes, *args,**kwargs)
|
|
148
148
|
|
|
149
149
|
if remove_div:
|
|
150
|
-
#
|
|
150
|
+
# Excise the numerical divergence
|
|
151
151
|
# at this point it's good enough of me - we can show it is legit compared to the mu terms
|
|
152
152
|
# so remove so nodes and replace them with the value before it diverges
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
if remove_div == 'turbo':
|
|
154
|
+
x = int(n/8) # remove more modes - mainly for l=4
|
|
155
|
+
else:
|
|
156
|
+
x = int(n/16) # so remove this many nodes
|
|
157
|
+
|
|
158
|
+
if source_func: # this returns value of integrand at source
|
|
159
|
+
xd_cut = xd_nodes[-x] # so lets just create a linear array from the cut to source and interpolate values in our LG array
|
|
160
|
+
int_grid[...,-x:] = np.apply_along_axis(lambda arr_1d: np.interp(xd_nodes[-x:], np.linspace(xd_cut,d), arr_1d), axis=-1, arr=np.linspace(int_grid[...,-x],source_func(*args,**kwargs),axis=-1))
|
|
161
|
+
else:
|
|
162
|
+
int_grid[...,-x:] = int_grid[...,-x][...,np.newaxis] # remove divergence in last axis
|
|
155
163
|
|
|
156
164
|
# (x1-x0)/2
|
|
157
165
|
return (d) / 2.0 * np.sum(weights * int_grid, axis=(-1)) # sum over last
|