Skip to content

Commit 646c158

Browse files
authored
Incorporating CMB Lensing Sources and Statistics into Firecrown for 5x2pt (#123)
* read CMBK * adding and testing CCL NK and GK * adding NK & GK * Update sources.py * add documentation * fix lint errors * few fixes * Update sources.py * Update sources.py * Update sources.py * Update sources.py * Add CMBL test * Update test_cmbl_source.py * Update test_cmbl_source.py
1 parent cb3e92c commit 646c158

10 files changed

Lines changed: 7555 additions & 5 deletions

File tree

examples/NK&GK/GK.sacc

Lines changed: 3595 additions & 0 deletions
Large diffs are not rendered by default.

examples/NK&GK/GK.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
parameters:
2+
Omega_k: 0.0
3+
Omega_g: 0.0
4+
w0: -1.0
5+
wa: 0.0
6+
T_CMB: 2.7
7+
Neff: 0
8+
m_nu: 0.0
9+
transfer_function: 'bbks'
10+
mass_function: 'tinker'
11+
12+
Omega_b: 0.045
13+
Omega_c: 0.21
14+
h: 0.71
15+
sigma8: 0.80
16+
n_s: 0.964
17+
18+
bias_lens: 1.0
19+
20+
21+
cosmosis:
22+
sampler: emcee
23+
debug: False
24+
quiet: True
25+
mpi: True
26+
test:
27+
fatal_erros: True
28+
emcee:
29+
walkers: 32
30+
samples: 20
31+
parameters:
32+
Omega_c: [0.1, 0.21, 0.9]
33+
sigma8: [0.4, 0.8, 1.2]
34+
n_s: [0.87, 0.964, 1.07]
35+
h: [0.55, 0.71, 0.91]
36+
Omega_b: [0.03, 0.045, 0.07]
37+
38+
39+
priors:
40+
module: firecrown.priors
41+
42+
Omega_c:
43+
kind: uniform
44+
loc: 0.1
45+
scale: 0.8
46+
47+
n_s:
48+
kind: uniform
49+
loc: 0.87
50+
scale: 0.2
51+
52+
sigma8:
53+
kind: uniform
54+
loc: 0.40
55+
scale: 0.80
56+
57+
h:
58+
kind: uniform
59+
loc: 0.55
60+
scale: 0.36
61+
62+
Omega_b:
63+
kind: uniform
64+
loc: 0.03
65+
scale: 0.04
66+
67+
68+
two_point:
69+
module: firecrown.ccl.two_point
70+
sacc_data: GK.sacc
71+
72+
sources:
73+
{% for i in range(5) %}
74+
src{{i}}:
75+
kind: CMBLSource
76+
sacc_tracer: ck{{i}}
77+
{% endfor %}
78+
79+
{% for i in range(5) %}
80+
lens{{i}}:
81+
kind: WLSource
82+
sacc_tracer: wl{{i}}
83+
{% endfor %}
84+
85+
statistics:
86+
{% for i in range(5) %}
87+
GK{{i}}:
88+
sources: ['lens{{i}}','src{{i}}']
89+
sacc_data_type: 'cmbGalaxy_convergenceShear_xi_t'
90+
{% endfor %}
91+
92+
likelihood:
93+
kind: ConstGaussianLogLike
94+
data_vector:
95+
{% for i in range(5) %}
96+
- GK{{i}}
97+
{% endfor %}
98+

examples/NK&GK/NK.sacc

Lines changed: 3604 additions & 0 deletions
Large diffs are not rendered by default.

examples/NK&GK/NK.yaml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
parameters:
2+
Omega_k: 0.0
3+
Omega_g: 0.0
4+
w0: -1.0
5+
wa: 0.0
6+
T_CMB: 2.7
7+
Neff: 0
8+
m_nu: 0.0
9+
transfer_function: 'bbks'
10+
mass_function: 'tinker'
11+
12+
sigma8: 0.80
13+
14+
Omega_b: 0.045
15+
h: 0.71
16+
Omega_c: 0.21
17+
n_s: 0.964
18+
19+
{% for i in range(5) %}
20+
bias_lens{{i}}: 1.0
21+
{% endfor %}
22+
23+
24+
cosmosis:
25+
sampler: emcee
26+
debug: True
27+
quiet: False
28+
mpi: False
29+
test:
30+
fatal_erros: True
31+
emcee:
32+
walkers: 32
33+
samples: 60
34+
parameters:
35+
Omega_c: [0.1, 0.21, 0.9]
36+
n_s: [0.87, 0.964, 1.07]
37+
h: [0.55, 0.71, 0.91]
38+
Omega_b: [0.03, 0.045, 0.07]
39+
{% for i in range(5) %}
40+
bias_lens{{i}}: [0.2, 1.0, 4.0]
41+
{% endfor %}
42+
43+
44+
priors:
45+
module: firecrown.priors
46+
47+
Omega_c:
48+
kind: uniform
49+
loc: 0.1
50+
scale: 0.8
51+
52+
n_s:
53+
kind: uniform
54+
loc: 0.87
55+
scale: 0.2
56+
57+
h:
58+
kind: uniform
59+
loc: 0.55
60+
scale: 0.36
61+
62+
Omega_b:
63+
kind: uniform
64+
loc: 0.03
65+
scale: 0.04
66+
67+
{% for i in range(5) %}
68+
bias_lens{{i}}:
69+
kind: uniform
70+
loc: 0.2
71+
scale: 3.8
72+
{% endfor %}
73+
74+
75+
two_point:
76+
module: firecrown.ccl.two_point
77+
sacc_data: NK.sacc
78+
79+
sources:
80+
{% for i in range(5) %}
81+
src{{i}}:
82+
kind: CMBLSource
83+
sacc_tracer: ck{{i}}
84+
{% endfor %}
85+
86+
{% for i in range(5) %}
87+
lens{{i}}:
88+
kind: NumberCountsSource
89+
sacc_tracer: gc{{i}}
90+
bias: bias_lens{{i}}
91+
{% endfor %}
92+
93+
statistics:
94+
{% for i in range(5) %}
95+
NK{{i}}:
96+
sources: ['lens{{i}}','src{{i}}']
97+
sacc_data_type: 'cmbGalaxy_convergenceDensity_xi'
98+
{% endfor %}
99+
100+
likelihood:
101+
kind: ConstGaussianLogLike
102+
data_vector:
103+
{% for i in range(5) %}
104+
- NK{{i}}
105+
{% endfor %}
106+

examples/NK&GK/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# NK and GK constraints
2+
3+
This is part of 5x2pt analysis. `NK.yaml` constrains cosmology based on galaxy number count x CMB lensing correlation (data stored in `NK.sacc`). `GK.yanml` constrains cosmology based on galaxy weak lensing x CMB lensing correlation (data stored in `GK.sacc`).
4+
5+
Both constraints use `emcee` as the sampler for MCMC chains.
6+
7+
To run this example, type
8+
9+
```bash
10+
$ firecrown run-cosmosis NK.yaml
11+
```
12+
13+
or for GK, type
14+
15+
```bash
16+
$ firecrown run-cosmosis GK.yaml
17+
```

examples/des_y1_3x2pt/plot_des_chain.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@
486486
"name": "python",
487487
"nbconvert_exporter": "python",
488488
"pygments_lexer": "ipython3",
489-
"version": "3.7.3"
489+
"version": "3.7.4"
490490
}
491491
},
492492
"nbformat": 4,
493-
"nbformat_minor": 2
493+
"nbformat_minor": 4
494494
}

examples/des_y1_3x2pt/plot_des_data_model.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5157,9 +5157,9 @@
51575157
"name": "python",
51585158
"nbconvert_exporter": "python",
51595159
"pygments_lexer": "ipython3",
5160-
"version": "3.7.6"
5160+
"version": "3.7.4"
51615161
}
51625162
},
51635163
"nbformat": 4,
5164-
"nbformat_minor": 2
5164+
"nbformat_minor": 4
51655165
}

firecrown/ccl/sources/sources.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ..systematics import IdentityFunctionMOR, TopHatSelectionFunction
88

99

10-
__all__ = ['WLSource', 'NumberCountsSource', 'ClusterSource']
10+
__all__ = ['WLSource', 'NumberCountsSource', 'ClusterSource', 'CMBLSource']
1111

1212

1313
class WLSource(Source):
@@ -374,3 +374,72 @@ def render(self, cosmo, params, systematics=None):
374374
systematics[systematic].apply(cosmo, params, self)
375375

376376
self.dndz_interp_ = Akima1DInterpolator(self.z_, self.dndz_)
377+
378+
379+
class CMBLSource(Source):
380+
"""A CCL CMB Lensing Source.
381+
382+
Parameters
383+
----------
384+
sacc_tracer : str
385+
The name of the tracer in the SACC file.
386+
scale : float, optional
387+
The default scale for this source. Usually the default of 1.0 is
388+
correct.
389+
systematics : list of str, optional
390+
A list of the source-level systematics to apply to the source. The
391+
default of `None` implies no systematics.
392+
393+
Attributes
394+
----------
395+
scale_ : float
396+
The overall scale associated with the source. Set after a call to
397+
`render`.
398+
tracer_ : `pyccl.CMBLensingTracer`
399+
The CCL tracer associated with this source. Set after a call to
400+
`render`.
401+
402+
Methods
403+
-------
404+
render : apply systematics to this source and build the
405+
`pyccl.CMBLSource`
406+
"""
407+
def __init__(self, *, sacc_tracer, scale=1.0, systematics=None):
408+
self.sacc_tracer = sacc_tracer
409+
self.scale = scale
410+
self.systematics = systematics or []
411+
412+
def read(self, sacc_data):
413+
"""
414+
Read the data for this source from the SACC file.
415+
416+
Parameters
417+
----------
418+
sacc_data : sacc.Sacc
419+
The data in the sacc format.
420+
"""
421+
pass
422+
423+
def render(self, cosmo, params, systematics=None):
424+
"""
425+
Render a source by applying systematics.
426+
427+
Parameters
428+
----------
429+
cosmo : pyccl.Cosmology
430+
A pyccl.Cosmology object.
431+
params : dict
432+
A dictionary mapping parameter names to their current values.
433+
systematics : dict
434+
A dictionary mapping systematic names to their objects. The
435+
default of `None` corresponds to no systematics.
436+
"""
437+
systematics = systematics or {}
438+
439+
self.scale_ = self.scale
440+
441+
for systematic in self.systematics:
442+
systematics[systematic].apply(cosmo, params, self)
443+
444+
tracer = ccl.CMBLensingTracer(cosmo, 1100.)
445+
self.tracer_ = tracer
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import numpy as np
2+
import pytest
3+
4+
import sacc
5+
import pyccl as ccl
6+
7+
from ..sources import CMBLSource
8+
9+
10+
@pytest.fixture
11+
def cmbl_data():
12+
sacc_data = sacc.Sacc()
13+
14+
params = dict(
15+
Omega_c=0.27,
16+
Omega_b=0.045,
17+
Omega_k=0.0,
18+
w0=-1.0,
19+
wa=0.0,
20+
sigma8=0.8,
21+
n_s=0.96,
22+
h=0.67)
23+
cosmo = ccl.Cosmology(**params)
24+
25+
ell = np.arange(3000)
26+
27+
sacc_data.add_tracer('Map', 'trc1', quantity='cmb_convergence', spin=0,
28+
ell=ell, beam=None)
29+
30+
return {
31+
'cosmo': cosmo,
32+
'sacc_tracer': 'trc1',
33+
'sacc_data': sacc_data,
34+
'params': params,
35+
'systematics': [],
36+
'systematics_dict': {},
37+
'scale_': 1.05}
38+
39+
40+
def test_cmbl_source_nosys(cmbl_data):
41+
src = CMBLSource(
42+
sacc_tracer=cmbl_data['sacc_tracer'],
43+
scale=0.5)
44+
src.read(cmbl_data['sacc_data'])
45+
46+
src.render(
47+
cmbl_data['cosmo'],
48+
cmbl_data['params'],
49+
cmbl_data['systematics_dict'])
50+
51+
assert np.allclose(src.scale, 0.5)
52+
assert np.allclose(src.scale_, 0.5)
53+
assert src.systematics == []
54+
55+
assert isinstance(src.tracer_, ccl.CMBLensingTracer)

0 commit comments

Comments
 (0)