Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

149 add nonlinear galaxy bias models #164

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ pyccl
sacc
fgspectra>=1.1.0
syslibrary
fast-pt
pyhalomodel
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ install_requires =
sacc
fgspectra>=1.1.0
syslibrary
fast-pt
pyhalomodel

[options.package_data]
Expand Down
1 change: 1 addition & 0 deletions soliket-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dependencies:
- camb
- pip:
- -r requirements.txt
- velocileptors @git+https://github.com/sfschen/velocileptors
39 changes: 39 additions & 0 deletions soliket/bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from typing import Optional
from cobaya.theory import Theory

from pyccl import nl_pt as pt


class Bias(Theory):
"""Parent class for bias models."""
Expand Down Expand Up @@ -97,3 +99,40 @@ def calculate(self, state: dict, want_derived: bool = True,

state["Pk_gg_grid"] = params_values_dict["b_lin"] ** 2. * Pk_mm
state["Pk_gm_grid"] = params_values_dict["b_lin"] * Pk_mm


class PTBias(Bias):

_bias_models = ['LagrangianPT', 'EulerianPT', 'BACCO', 'anzu']

def initialize():
super.initialize()

self.bz_model
self._initialize_pt()

def _initialize_pt(self):
"""
Initialize CCL PT calculators.
"""

#TODO: Need to decide what we want to expose
if self.bz_model == 'LagrangianPT':
self.ptc = pt.LagrangianPTCalculator(log10k_min=self.log10k_min,
log10k_max=self.log10k_max,
nk_per_decade=self.nk_per_decade)
# b1_pk_kind='pt', bk2_pk_kind='pt')
elif self.bz_model == 'EulerianPT':
self.ptc = pt.EulerianPTCalculator(with_NC=True, with_IA=True,
log10k_min=self.log10k_min,
log10k_max=self.log10k_max,
nk_per_decade=self.nk_per_decade)
else:
raise LoggedError(self.log,
"Bias model {} not implemented yet.".format(self.bz_model))

def calculate():

# do some checking on tracers?
state["Pk_gg_grid"] = self.ptc._get_pgg(tr1, tr2)
state["Pk_gm_grid"] = self.ptc._get_pgm(tr1)
28 changes: 17 additions & 11 deletions soliket/ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def initialize(self) -> None:
def get_requirements(self) -> set:
# These are currently required to construct a CCL cosmology object.
# Ultimately CCL should depend only on observable not parameters
return {'omch2', 'ombh2'}
return {'omch2', 'ombh2', 'sigma8', 'ns', 'omnuh2'}

def must_provide(self, **requirements) -> dict:
# requirements is dictionary of things requested by likelihoods
Expand Down Expand Up @@ -169,6 +169,10 @@ def calculate(self, state: dict, want_derived: bool = True,

Omega_c = self.provider.get_param('omch2') / h ** 2
Omega_b = self.provider.get_param('ombh2') / h ** 2
sigma8 = self.provider.get_param('sigma8')
n_s = self.provider.get_param('ns')
# mnu = self.provider.get_param('mnu')
mnu = self.provider.get_param('omnuh2') * 93.014
# Array z is sorted in ascending order. CCL requires an ascending scale factor
# as input
# Flip the arrays to make them a function of the increasing scale factor.
Expand All @@ -181,7 +185,6 @@ def calculate(self, state: dict, want_derived: bool = True,
a = 1. / (1 + self.z[::-1])
# growth = ccl.background.growth_factor(cosmo, a)
# fgrowth = ccl.background.growth_rate(cosmo, a)

if self.kmax:
for pair in self._var_pairs:
# Get the matter power spectrum:
Expand All @@ -199,35 +202,38 @@ def calculate(self, state: dict, want_derived: bool = True,
Omega_c=Omega_c,
Omega_b=Omega_b,
h=h,
sigma8=0.8,
n_s=0.96,
sigma8=sigma8,
n_s=n_s,
m_nu=mnu,
background={'a': a,
'chi': distance,
'h_over_h0': E_of_z},
pk_linear={'a': a,
'k': k,
'delta_matter:delta_matter': Pk_lin}, # noqa E501
'delta_matter:delta_matter': Pk_lin}, # noqa E501
pk_nonlin={'a': a,
'k': k,
'delta_matter:delta_matter': Pk_nonlin} # noqa E501
)
'delta_matter:delta_matter': Pk_nonlin} # noqa E501
)

else:
cosmo = self.ccl.CosmologyCalculator(
Omega_c=Omega_c,
Omega_b=Omega_b,
h=h,
sigma8=0.8,
n_s=0.96,
sigma8=sigma8,
n_s=n_s,
m_nu=mnu,
background={'a': a,
'chi': distance,
'h_over_h0': E_of_z},
pk_linear={'a': a,
'k': k,
'delta_matter:delta_matter': Pk_lin} # noqa E501
)
'delta_matter:delta_matter': Pk_lin} # noqa E501
)

state['CCL'] = {'cosmo': cosmo, 'ccl': self.ccl}

for required_result, method in self._required_results.items():
state['CCL'][required_result] = method(cosmo)

Expand Down
1 change: 1 addition & 0 deletions soliket/cross_correlation/CrossCorrelationLikelihood.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
datapath: soliket/tests/data/des_s-act_kappa.toy-sim.sacc.fits
use_spectra: all
ncovsims: null

24 changes: 15 additions & 9 deletions soliket/cross_correlation/GalaxyKappaLikelihood.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
params:
b1:
prior:
min: 0.
max: 10.
latex: b_1
s1:
value: 0.4
latex: s_1
datapath: soliket/tests/data/des_s-act_kappa.toy-sim.sacc.fits
use_spectra: all

bins: gc_cmass
bz_model: LagrangianPT
nz_model: NzShift
z_cmb: 1030
input_params_prefix: '_'

log10k_min: -4
log10k_max: 2
nk_per_decade: 20
defaults:
lmin: 30
lmax: 3000
Loading