Skip to content

Commit

Permalink
Incorporating CMB Lensing Sources and Statistics into Firecrown for 5…
Browse files Browse the repository at this point in the history
…x2pt (#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
  • Loading branch information
zhuoqizhang authored Aug 14, 2020
1 parent cb3e92c commit 646c158
Show file tree
Hide file tree
Showing 10 changed files with 7,555 additions and 5 deletions.
3,595 changes: 3,595 additions & 0 deletions examples/NK&GK/GK.sacc

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions examples/NK&GK/GK.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
parameters:
Omega_k: 0.0
Omega_g: 0.0
w0: -1.0
wa: 0.0
T_CMB: 2.7
Neff: 0
m_nu: 0.0
transfer_function: 'bbks'
mass_function: 'tinker'

Omega_b: 0.045
Omega_c: 0.21
h: 0.71
sigma8: 0.80
n_s: 0.964

bias_lens: 1.0


cosmosis:
sampler: emcee
debug: False
quiet: True
mpi: True
test:
fatal_erros: True
emcee:
walkers: 32
samples: 20
parameters:
Omega_c: [0.1, 0.21, 0.9]
sigma8: [0.4, 0.8, 1.2]
n_s: [0.87, 0.964, 1.07]
h: [0.55, 0.71, 0.91]
Omega_b: [0.03, 0.045, 0.07]


priors:
module: firecrown.priors

Omega_c:
kind: uniform
loc: 0.1
scale: 0.8

n_s:
kind: uniform
loc: 0.87
scale: 0.2

sigma8:
kind: uniform
loc: 0.40
scale: 0.80

h:
kind: uniform
loc: 0.55
scale: 0.36

Omega_b:
kind: uniform
loc: 0.03
scale: 0.04


two_point:
module: firecrown.ccl.two_point
sacc_data: GK.sacc

sources:
{% for i in range(5) %}
src{{i}}:
kind: CMBLSource
sacc_tracer: ck{{i}}
{% endfor %}

{% for i in range(5) %}
lens{{i}}:
kind: WLSource
sacc_tracer: wl{{i}}
{% endfor %}

statistics:
{% for i in range(5) %}
GK{{i}}:
sources: ['lens{{i}}','src{{i}}']
sacc_data_type: 'cmbGalaxy_convergenceShear_xi_t'
{% endfor %}

likelihood:
kind: ConstGaussianLogLike
data_vector:
{% for i in range(5) %}
- GK{{i}}
{% endfor %}

3,604 changes: 3,604 additions & 0 deletions examples/NK&GK/NK.sacc

Large diffs are not rendered by default.

106 changes: 106 additions & 0 deletions examples/NK&GK/NK.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
parameters:
Omega_k: 0.0
Omega_g: 0.0
w0: -1.0
wa: 0.0
T_CMB: 2.7
Neff: 0
m_nu: 0.0
transfer_function: 'bbks'
mass_function: 'tinker'

sigma8: 0.80

Omega_b: 0.045
h: 0.71
Omega_c: 0.21
n_s: 0.964

{% for i in range(5) %}
bias_lens{{i}}: 1.0
{% endfor %}


cosmosis:
sampler: emcee
debug: True
quiet: False
mpi: False
test:
fatal_erros: True
emcee:
walkers: 32
samples: 60
parameters:
Omega_c: [0.1, 0.21, 0.9]
n_s: [0.87, 0.964, 1.07]
h: [0.55, 0.71, 0.91]
Omega_b: [0.03, 0.045, 0.07]
{% for i in range(5) %}
bias_lens{{i}}: [0.2, 1.0, 4.0]
{% endfor %}


priors:
module: firecrown.priors

Omega_c:
kind: uniform
loc: 0.1
scale: 0.8

n_s:
kind: uniform
loc: 0.87
scale: 0.2

h:
kind: uniform
loc: 0.55
scale: 0.36

Omega_b:
kind: uniform
loc: 0.03
scale: 0.04

{% for i in range(5) %}
bias_lens{{i}}:
kind: uniform
loc: 0.2
scale: 3.8
{% endfor %}


two_point:
module: firecrown.ccl.two_point
sacc_data: NK.sacc

sources:
{% for i in range(5) %}
src{{i}}:
kind: CMBLSource
sacc_tracer: ck{{i}}
{% endfor %}

{% for i in range(5) %}
lens{{i}}:
kind: NumberCountsSource
sacc_tracer: gc{{i}}
bias: bias_lens{{i}}
{% endfor %}

statistics:
{% for i in range(5) %}
NK{{i}}:
sources: ['lens{{i}}','src{{i}}']
sacc_data_type: 'cmbGalaxy_convergenceDensity_xi'
{% endfor %}

likelihood:
kind: ConstGaussianLogLike
data_vector:
{% for i in range(5) %}
- NK{{i}}
{% endfor %}

17 changes: 17 additions & 0 deletions examples/NK&GK/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# NK and GK constraints

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`).

Both constraints use `emcee` as the sampler for MCMC chains.

To run this example, type

```bash
$ firecrown run-cosmosis NK.yaml
```

or for GK, type

```bash
$ firecrown run-cosmosis GK.yaml
```
4 changes: 2 additions & 2 deletions examples/des_y1_3x2pt/plot_des_chain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
4 changes: 2 additions & 2 deletions examples/des_y1_3x2pt/plot_des_data_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5157,9 +5157,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
71 changes: 70 additions & 1 deletion firecrown/ccl/sources/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..systematics import IdentityFunctionMOR, TopHatSelectionFunction


__all__ = ['WLSource', 'NumberCountsSource', 'ClusterSource']
__all__ = ['WLSource', 'NumberCountsSource', 'ClusterSource', 'CMBLSource']


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

self.dndz_interp_ = Akima1DInterpolator(self.z_, self.dndz_)


class CMBLSource(Source):
"""A CCL CMB Lensing Source.
Parameters
----------
sacc_tracer : str
The name of the tracer in the SACC file.
scale : float, optional
The default scale for this source. Usually the default of 1.0 is
correct.
systematics : list of str, optional
A list of the source-level systematics to apply to the source. The
default of `None` implies no systematics.
Attributes
----------
scale_ : float
The overall scale associated with the source. Set after a call to
`render`.
tracer_ : `pyccl.CMBLensingTracer`
The CCL tracer associated with this source. Set after a call to
`render`.
Methods
-------
render : apply systematics to this source and build the
`pyccl.CMBLSource`
"""
def __init__(self, *, sacc_tracer, scale=1.0, systematics=None):
self.sacc_tracer = sacc_tracer
self.scale = scale
self.systematics = systematics or []

def read(self, sacc_data):
"""
Read the data for this source from the SACC file.
Parameters
----------
sacc_data : sacc.Sacc
The data in the sacc format.
"""
pass

def render(self, cosmo, params, systematics=None):
"""
Render a source by applying systematics.
Parameters
----------
cosmo : pyccl.Cosmology
A pyccl.Cosmology object.
params : dict
A dictionary mapping parameter names to their current values.
systematics : dict
A dictionary mapping systematic names to their objects. The
default of `None` corresponds to no systematics.
"""
systematics = systematics or {}

self.scale_ = self.scale

for systematic in self.systematics:
systematics[systematic].apply(cosmo, params, self)

tracer = ccl.CMBLensingTracer(cosmo, 1100.)
self.tracer_ = tracer
55 changes: 55 additions & 0 deletions firecrown/ccl/sources/tests/test_cmbl_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import numpy as np
import pytest

import sacc
import pyccl as ccl

from ..sources import CMBLSource


@pytest.fixture
def cmbl_data():
sacc_data = sacc.Sacc()

params = dict(
Omega_c=0.27,
Omega_b=0.045,
Omega_k=0.0,
w0=-1.0,
wa=0.0,
sigma8=0.8,
n_s=0.96,
h=0.67)
cosmo = ccl.Cosmology(**params)

ell = np.arange(3000)

sacc_data.add_tracer('Map', 'trc1', quantity='cmb_convergence', spin=0,
ell=ell, beam=None)

return {
'cosmo': cosmo,
'sacc_tracer': 'trc1',
'sacc_data': sacc_data,
'params': params,
'systematics': [],
'systematics_dict': {},
'scale_': 1.05}


def test_cmbl_source_nosys(cmbl_data):
src = CMBLSource(
sacc_tracer=cmbl_data['sacc_tracer'],
scale=0.5)
src.read(cmbl_data['sacc_data'])

src.render(
cmbl_data['cosmo'],
cmbl_data['params'],
cmbl_data['systematics_dict'])

assert np.allclose(src.scale, 0.5)
assert np.allclose(src.scale_, 0.5)
assert src.systematics == []

assert isinstance(src.tracer_, ccl.CMBLensingTracer)
Loading

0 comments on commit 646c158

Please sign in to comment.