Skip to content

Commit

Permalink
Tuning knob param for 1-halo 2-point correlations (#883)
Browse files Browse the repository at this point in the history
* Profile2ptR - to be amended

* implemented r_corr in Profile2pt
  • Loading branch information
nikfilippas committed Jun 8, 2021
1 parent 61a13fe commit 17889df
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 18 deletions.
62 changes: 44 additions & 18 deletions pyccl/halos/profiles_2pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,63 @@


class Profile2pt(object):
""" This class implements the 1-halo 2-point correlator between two
halo profiles. In the simplest case, this is just
the product of both profiles in Fourier space.
More complicated cases should be implemented by subclassing
this class and overloading the :meth:`~Profile2pt.fourier_2pt`
method.
""" This class implements the 1-halo 2-point correlator between
two halo profiles.
.. math::
\\langle u_1(k) u_2(k) \\rangle.
In the simplest case the second-order cumulant is just the product
of the individual Fourier-space profiles. More complicated cases
are implemented via the parameters of this class.
Args:
r_corr (float):
Tuning knob for the 1-halo 2-point correlation.
Scale the correlation by :math:`(1+\\rho_{u_1, u_2})`.
This is useful when the individual 1-halo terms
are not fully correlated. Example usecases can be found
in ``arXiv:1909.09102`` and ``arXiv:2102.07701``.
Defaults to ``r_corr=0``, returning simply the product
of the fourier profiles.
"""
def __init__(self):
pass
def __init__(self, r_corr=0.):
self.r_corr = r_corr

def update_parameters(self, r_corr=None):
""" Update any of the parameters associated with this 1-halo
2-point correlator. Any parameter set to `None` won't be updated.
"""
if r_corr is not None:
self.r_corr = r_corr

def fourier_2pt(self, prof, cosmo, k, M, a,
prof2=None, mass_def=None):
""" Returns the Fourier-space two-point moment between
two profiles:
""" Return the Fourier-space two-point moment between
two profiles.
.. math::
\\langle\\rho_1(k)\\rho_2(k)\\rangle.
(1+\\rho_{u_1,u_2})\\langle u_1(k)\\rangle\\langle u_2(k) \\rangle
Args:
prof (:class:`~pyccl.halos.profiles.HaloProfile`):
halo profile for which the second-order moment
is desired.
cosmo (:class:`~pyccl.core.Cosmology`): a Cosmology object.
k (float or array_like): comoving wavenumber in Mpc^-1.
M (float or array_like): halo mass in units of M_sun.
a (float): scale factor.
cosmo (:class:`~pyccl.core.Cosmology`):
a Cosmology object.
k (float or array_like):
comoving wavenumber in Mpc^-1.
M (float or array_like):
halo mass in units of M_sun.
a (float):
scale factor.
prof2 (:class:`~pyccl.halos.profiles.HaloProfile`):
second halo profile for which the second-order moment
is desired. If `None`, the assumption is that you want
an auto-correlation, and `prof` will be used as `prof2`.
mass_def (:obj:`~pyccl.halos.massdef.MassDef`): a mass
definition object.
mass_def (:obj:`~pyccl.halos.massdef.MassDef`):
a mass definition object.
Returns:
float or array_like: second-order Fourier-space
Expand All @@ -44,6 +69,7 @@ def fourier_2pt(self, prof, cosmo, k, M, a,
"""
if not isinstance(prof, HaloProfile):
raise TypeError("prof must be of type `HaloProfile`")

uk1 = prof.fourier(cosmo, k, M, a, mass_def=mass_def)

if prof2 is None:
Expand All @@ -55,7 +81,7 @@ def fourier_2pt(self, prof, cosmo, k, M, a,

uk2 = prof2.fourier(cosmo, k, M, a, mass_def=mass_def)

return uk1 * uk2
return uk1 * uk2 * (1 + self.r_corr)


class Profile2ptHOD(Profile2pt):
Expand Down
23 changes: 23 additions & 0 deletions pyccl/tests/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ def test_hod_2pt_raises():
prof2=pgood, mass_def=M200)


def test_2pt_rcorr_smoke():
c = ccl.halos.ConcentrationDuffy08(M200)
p = ccl.halos.HaloProfileNFW(c_M_relation=c)
F0 = ccl.halos.Profile2pt().fourier_2pt(p, COSMO, 1., 1e13, 1.,
mass_def=M200)
p2pt = ccl.halos.Profile2pt(r_corr=0)
F1 = p2pt.fourier_2pt(p, COSMO, 1., 1e13, 1., mass_def=M200)
assert F0 == F1
F2 = p2pt.fourier_2pt(p, COSMO, 1., 1e13, 1., prof2=p, mass_def=M200)
assert F1 == F2

p2pt.update_parameters(r_corr=-1.)
assert p2pt.r_corr == -1.
F3 = p2pt.fourier_2pt(p, COSMO, 1., 1e13, 1., mass_def=M200)
assert F3 == 0

# Errors
with pytest.raises(TypeError):
p2pt.fourier_2pt(None, COSMO, 1., 1e13, 1., mass_def=M200)
with pytest.raises(TypeError):
p2pt.fourier_2pt(p, COSMO, 1., 1e13, 1., prof2=0, mass_def=M200)


@pytest.mark.parametrize('prof_class',
[ccl.halos.HaloProfileGaussian,
ccl.halos.HaloProfilePowerLaw])
Expand Down

0 comments on commit 17889df

Please sign in to comment.