Skip to content

Commit

Permalink
bug fixing halo model theory for cobaya
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiazagatti committed Aug 18, 2024
1 parent 2317ac4 commit e624818
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 153 deletions.
32 changes: 32 additions & 0 deletions soliket/halo_model/halo_model_fe/HaloModel_fe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
read_matterPS: False #if True, reads pre-computed linear matter PS
#if False, computes the linear matter PS using CAMB
gal_mod: False
matter_matter: 'mm'
galaxy_galaxy: #'gg'
matter_galaxy: "gm"
redshift: './tabulated/redshift.txt'

z : [0,1,2]

kmax: 10.0

Mmin: 11
Mmax: 15
nm: 200

Dc: 200

T_CMB: 2.725
tau: 0.0544
ns: 0.9649
As: 1.97448e-9 #2.101e-9
pivot_scalar: 0.05
matter_PS:
sigma_EP: 0.1
sigma_LP: 0.1
scale_EP: 10.0
scale_LP: 10.0
alpha_EP: 1.0
alpha_LP: 1.0
LogMmin_EP: 12.0
LogMmin_LP: 10.8
4 changes: 2 additions & 2 deletions soliket/halo_model/halo_model_fe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .halo_model_fe import paramfile_halomod
from .halo_model_fe import HaloModel_fe

__all__ = {
"paramfile_halomod"
"HaloModel_fe"
}
27 changes: 17 additions & 10 deletions soliket/halo_model/halo_model_fe/halo_model_fe.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np
from cobaya.theory import Theory
from utils import *
from HODS import *
from power_spectrum import *
from lin_matterPS import *
from cosmology import *
from .utils import *
from .HODS import *
from .power_spectrum import *
from .lin_matterPS import *
from .cosmology import *

class HaloModel(Theory):
_logz = np.linspace(-3, np.log10(1100), 150)
Expand Down Expand Up @@ -37,7 +37,8 @@ def get_Pk_gm_grid(self):
class HaloModel_fe(HaloModel):
def initialize(self):
super().initialize()
self.logmass = np.linspace(self.Mmin, self.mmax, self.nm)
self.logmass = np.linspace(self.Mmin, self.Mmax, self.nm)
#self.k = np.linspace(0, self.kmax, 1)
self.clust_param = {'sigma_EP': self.sigma_EP,
'sigma_LP': self.sigma_LP,
'scale_EP': self.scale_EP,
Expand All @@ -48,8 +49,8 @@ def initialize(self):
'LogMmin_LP': self.LogMmin_LP,
'Dc': self.Dc,
}
self.isinstance_200 = u_p_nfw_hmf_bias(self.k, self._get_Pk_mm_lin(), self.logmass, self.z, self.Dc)
self.instance_HOD = hod_ngal(self.logmass, self.z, self.clust_param, self.instance_200)
#self.instance_200 = u_p_nfw_hmf_bias(self.k, self._get_Pk_mm_lin(), self.logmass, self.z, self.Dc)
#self.instance_HOD = hod_ngal(self.logmass, self.z, self.clust_param, self.instance_200)

def must_provide(self, **requirements):

Expand Down Expand Up @@ -79,10 +80,16 @@ def must_provide(self, **requirements):
}
return needs

def calculate(self, state: dict):
def calculate(self, state: dict, want_derived: bool = True,
**params_values_dict):
Pk_mm_lin = self._get_Pk_mm_lin()

self.instance_200 = u_p_nfw_hmf_bias(self.k, Pk_mm_lin, self.logmass, self.z, self.Dc)
self.instance_HOD = hod_ngal(self.logmass, self.z, self.clust_param, self.instance_200)

spectra = mm_gg_mg_spectra(
self.k,
self._get_Pk_mm_lin(),
Pk_mm_lin,
self.logmass,
self.z,
self.instance_HOD,
Expand Down
102 changes: 0 additions & 102 deletions soliket/halo_model/halo_model_fe/halomodel_ps.py

This file was deleted.

37 changes: 0 additions & 37 deletions soliket/halo_model/halo_model_fe/paramfile_halomod.yaml

This file was deleted.

8 changes: 6 additions & 2 deletions soliket/halo_model/halo_model_fe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def sigma(self, rad, red, zeta):
lnk = np.log(k)
uW = self.W(rk)
integ = rest * uW ** 2
sigm = (0.5 / np.pi ** 2) * scipy.integrate.simps(integ, x=lnk, axis=-1)
sigm = (0.5 / np.pi ** 2) * trapz(integ, x=lnk, axis=-1) ####################################### gz
#sigm = (0.5 / np.pi ** 2) * scipy.integrate.simps(integ, x=lnk, axis=-1)
return np.sqrt(sigm)

# sigma depends on z from the linear power spectrum
Expand Down Expand Up @@ -128,7 +129,10 @@ def dlns2_dlnr(self, rad, red, zeta):
inte = w * dw * rest
lnk = np.log(k)
s = self.sigma(rad, red, zeta)
return scipy.integrate.simps(inte, x=lnk, axis=-1, even="avg") / (
#return scipy.integrate.simps(inte, x=lnk, axis=-1, even="avg") / (
# np.pi ** 2 * s ** 2
#)
return trapz(inte, x=lnk, axis=-1) / (
np.pi ** 2 * s ** 2
)

Expand Down

0 comments on commit e624818

Please sign in to comment.