From 45c19c1316a82cfbcd92e4cde201029d2413be16 Mon Sep 17 00:00:00 2001 From: Matt Hilton Date: Fri, 1 Sep 2023 01:35:43 +0200 Subject: [PATCH] Working with CCL v3+ --- soliket/clusters/ccl_th.py | 12 +++++++----- soliket/clusters/clusters.py | 15 ++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/soliket/clusters/ccl_th.py b/soliket/clusters/ccl_th.py index 56d92192..e1ce3187 100644 --- a/soliket/clusters/ccl_th.py +++ b/soliket/clusters/ccl_th.py @@ -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, @@ -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'), @@ -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(): @@ -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': diff --git a/soliket/clusters/clusters.py b/soliket/clusters/clusters.py index f1dc0986..93d9c81c 100644 --- a/soliket/clusters/clusters.py +++ b/soliket/clusters/clusters.py @@ -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.) @@ -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 @@ -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