Skip to content

Commit

Permalink
Working with CCL v3+
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyowl committed Aug 31, 2023
1 parent 8dc9834 commit 45c19c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
12 changes: 7 additions & 5 deletions soliket/clusters/ccl_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CCL(Theory):
# CCL options
transfer_function: str = 'boltzmann_camb'
matter_pk: str = 'halofit'
baryons_pk: str = 'nobaryons'
baryons_pk: None # CCL v3
md_hmf: str = '200m'
# Params it can accept
params = {'Omega_c': None,
Expand Down Expand Up @@ -126,6 +126,8 @@ def get_can_support_params(self):

def calculate(self, state, want_derived=True, **params_values_dict):
# Generate the CCL cosmology object which can then be used downstream
if self.baryons_pk == 'nobaryons': # For CCL v3, in case people don't want to update SOLikeT .yml configs
self.baryons_pk=None
cosmo = ccl.Cosmology(Omega_c=self.provider.get_param('Omega_c'),
Omega_b=self.provider.get_param('Omega_b'),
h=self.provider.get_param('h'),
Expand All @@ -135,7 +137,7 @@ def calculate(self, state, want_derived=True, **params_values_dict):
m_nu=self.provider.get_param('m_nu'),
transfer_function=self.transfer_function,
matter_power_spectrum=self.matter_pk,
baryons_power_spectrum=self.baryons_pk)
baryonic_effects=self.baryons_pk) # baryonic_effects is CCL v3

state['derived'] = {'H0': cosmo.cosmo.params.H0}
for req_res, attrs in self._required_results.items():
Expand All @@ -149,14 +151,14 @@ def calculate(self, state, want_derived=True, **params_values_dict):
state[req_res] = None
elif req_res == 'nc_data':
if self.md_hmf == '200m':
md = ccl.halos.MassDef200m(c_m='Bhattacharya13')
md = ccl.halos.MassDef(200, 'matter')
elif self.md_hmf == '200c':
md = ccl.halos.MassDef200c(c_m='Bhattacharya13')
md = ccl.halos.MassDef(200, 'critical')
elif self.md_hmf == '500c':
md = ccl.halos.MassDef(500, 'critical')
else:
raise NotImplementedError('Only md_hmf = 200m, 200c and 500c currently supported.')
mf = ccl.halos.MassFuncTinker08(cosmo, mass_def=md)
mf = ccl.halos.MassFuncTinker08(mass_def=md)
state[req_res] = {'HMF': mf,
'md': md}
elif req_res == 'CCL':
Expand Down
15 changes: 8 additions & 7 deletions soliket/clusters/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ def tinker(sgm, z):
h = self.theory.get_param("H0") / 100.0
a = 1./(1+z)
marr = np.exp(marr)
dn_dlog10M = np.array([mf.get_mass_function(cosmo, marr/h, ai) for ai in a])
dn_dlog10M = np.array([mf(cosmo, marr/h, ai) for ai in a])
# For consistency with internal mass function computation
dn_dlog10M /= h**3 * np.log(10.)

Expand Down Expand Up @@ -1246,17 +1246,17 @@ def convert_masses(both, marr, zz):
md_hmf = mf_data['md']

if both.theorypred['md_ym'] == '200m':
md_ym = ccl.halos.MassDef200m(c_m='Bhattacharya13')
md_ym = ccl.halos.MassDef(200, 'matter')
elif both.theorypred['md_ym'] == '200c':
md_ym = ccl.halos.MassDef200c(c_m='Bhattacharya13')
md_ym = ccl.halos.MassDef(200, 'critical')
elif both.theorypred['md_ym'] == '500c':
md_ym = ccl.halos.MassDef(500, 'critical')
else:
raise NotImplementedError('Only md_hmf = 200m, 200c and 500c currently supported.')

cosmo = both.theory.get_CCL()['cosmo']
a = 1. / (1. + zz)
marr_ymmd = np.array([md_hmf.translate_mass(cosmo, marr / h, ai, md_ym) for ai in a]) * h
mass_trans=ccl.halos.mass_translator(mass_in = md_hmf, mass_out = md_ym, concentration = 'Bhattacharya13')
marr_ymmd = np.array([mass_trans(cosmo, marr / h, ai) for ai in a]) * h
else:
if both.theorypred['md_hmf'] == '200m' and both.theorypred['md_ym'] == '500c':
marr_ymmd = both._get_M500c_from_M200m(marr, zz).T
Expand All @@ -1273,10 +1273,11 @@ def get_m500c(both, marr, zz):
cosmo = both.theory.get_CCL()['cosmo']
a = 1. / (1. + zz)

mass_trans=ccl.halos.mass_translator(mass_in = md_hmf, mass_out = md_500c, concentration = 'Bhattacharya13')
if a.ndim == 1:
marr_500c = np.array([md_hmf.translate_mass(cosmo, marr/h, ai, md_500c) for ai in a]) * h
marr_500c = np.array([mass_trans(cosmo, marr/h, ai) for ai in a]) * h
else:
marr_500c = md_hmf.translate_mass(cosmo, marr/h, a, md_500c) * h
marr_500c = mass_trans(cosmo, marr/h, a) * h

return marr_500c

Expand Down

0 comments on commit 45c19c1

Please sign in to comment.