Skip to content

Commit d60129e

Browse files
committed
Add cluster features
1 parent bc6ec88 commit d60129e

File tree

2 files changed

+185
-1
lines changed

2 files changed

+185
-1
lines changed

skypy/halos/_colossus.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,137 @@ def colossus_mf(redshift, model, mdef, m_min, m_max, sky_area, cosmology,
203203
cosmology, sigma8, ns, size, resolution)
204204

205205
return z, m
206+
207+
208+
def concentration(mass, mdef, redshift, model, cosmology, sigma8, ns):
209+
r'''Halo concentration calculator.
210+
211+
This function calculates halo concentration(s) using the model of c-M relation
212+
available in colossus.
213+
214+
Parameters
215+
----------
216+
mass : float or array_like
217+
Spherical overdensity halo mass in units of solar mass/h, corresponding
218+
to the mass definition, mdef.
219+
mdef : str
220+
Halo mass definition for spherical overdensities used by colossus.
221+
redshift : float
222+
Halo redshift
223+
model : string
224+
The model of the c-M relation which is available in colossus.
225+
cosmology : astropy.cosmology.Cosmology
226+
Astropy cosmology object
227+
sigma8 : float
228+
Cosmology parameter, amplitude of the (linear) power spectrum on the
229+
scale of 8 Mpc/h.
230+
ns : float
231+
Cosmology parameter, spectral index of scalar perturbation power spectrum.
232+
233+
Returns
234+
-------
235+
concentration : float or array_like
236+
Halo concentration(s); has the same dimensions as mass.
237+
238+
'''
239+
from colossus.cosmology.cosmology import fromAstropy
240+
from colossus.halo import concentration
241+
242+
fromAstropy(cosmology, sigma8=sigma8, ns=ns)
243+
244+
c = concentration.concentration(mass, mdef, redshift, model)
245+
246+
return c
247+
248+
249+
def radius(mass, concentration, redshift, mdef, Delta, cosmology, sigma8, ns):
250+
r'''Calculate the scale radius and the spherical overdensity radius of halo by assuming
251+
the NFW model.
252+
253+
This function calculates the scale radius and any spherical overdensity radius
254+
for NFW dark matter halo.
255+
256+
Parameters
257+
----------
258+
mass : float
259+
A spherical overdensity halo mass in units of solar mass/h, corresponding
260+
to the mass definition, mdef.
261+
concentration : float
262+
The concentration corresponding to the given halo mass and mass definition.
263+
redshift : float
264+
The halo redshift value.
265+
mdef : str
266+
Halo mass definition for spherical overdensities used by colossus.
267+
Delta : str
268+
The mass definition for which the spherical overdensity radius is computed.
269+
cosmology : astropy.cosmology.Cosmology
270+
Astropy cosmology object
271+
sigma8 : float
272+
Cosmology parameter, amplitude of the (linear) power spectrum on the
273+
scale of 8 Mpc/h.
274+
ns : float
275+
Cosmology parameter, spectral index of scalar perturbation power spectrum.
276+
277+
Returns
278+
-------
279+
rs : float
280+
The scale radius in physical kpc/h.
281+
RDelta : float
282+
Spherical overdensity radius of a given mass definition Delta.
283+
284+
'''
285+
from colossus.cosmology.cosmology import fromAstropy
286+
from colossus.halo import profile_nfw
287+
288+
fromAstropy(cosmology, sigma8=sigma8, ns=ns)
289+
290+
prof = profile_nfw.NFWProfile(M=mass, c=concentration, z=redshift, mdef=mdef)
291+
rs = prof.par['rs']
292+
RDelta = prof.RDelta(redshift, Delta)
293+
294+
return rs, RDelta
295+
296+
297+
def Delta_Sigma(mass, concentration, redshift, mdef, radius, cosmology, sigma8, ns):
298+
r'''The excess surface density at given radius by assuming the NFW model.
299+
300+
This function uses Colossus routines to compute the excess surface density profile,
301+
which is defined as Delta_Sigma(R) = Sigma(<R) − Sigma(R).
302+
303+
Parameters
304+
----------
305+
mass : float
306+
A spherical overdensity halo mass in units of solar mass/h, corresponding
307+
to the mass definition, mdef.
308+
concentration : float
309+
The concentration corresponding to the given halo mass and mass definition.
310+
redshift : float
311+
Halo redshift
312+
mdef : str
313+
Halo mass definition for spherical overdensities used by colossus.
314+
radius : float or array_like
315+
Radius in physical kpc/h.
316+
cosmology : astropy.cosmology.Cosmology
317+
Astropy cosmology object
318+
sigma8 : float
319+
Cosmology parameter, amplitude of the (linear) power spectrum on the
320+
scale of 8 Mpc/h.
321+
ns : float
322+
Cosmology parameter, spectral index of scalar perturbation power spectrum.
323+
324+
Returns
325+
-------
326+
DeltaSigma: float or array_like
327+
The excess surface density at the given radius, in units of h physical Msun/kpc^2;
328+
has the same dimensions as radius.
329+
330+
'''
331+
from colossus.cosmology.cosmology import fromAstropy
332+
from colossus.halo import profile_nfw
333+
334+
fromAstropy(cosmology, sigma8=sigma8, ns=ns)
335+
336+
prof = profile_nfw.NFWProfile(M=mass, c=concentration, z=redshift, mdef=mdef)
337+
deltaSigma = prof.deltaSigma(radius)
338+
339+
return deltaSigma

skypy/halos/tests/test_colossus.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test_colossus_mass_sampler():
1111
from astropy.cosmology import WMAP9
1212
from colossus.cosmology.cosmology import fromAstropy
1313
from colossus.lss import mass_function
14-
from skypy.halos.mass import colossus_mass_sampler
14+
from skypy.halos._colossus import colossus_mass_sampler
1515
m_min, m_max, size = 1e+12, 1e+16, 100
1616
sample = colossus_mass_sampler(redshift=0.1, model='despali16',
1717
mdef='500c', m_min=m_min, m_max=m_max,
@@ -105,3 +105,53 @@ def test_colossus_mf():
105105
assert np.all(z_halo <= np.max(z))
106106
assert np.all(m_halo >= m_min)
107107
assert np.all(m_halo <= m_max)
108+
109+
110+
@pytest.mark.skipif(not HAS_COLOSSUS, reason='test requires colossus')
111+
@pytest.mark.flaky
112+
def test_colossus_concentration():
113+
from skypy.halos._colossus import concentration
114+
from astropy.cosmology import Planck15
115+
116+
mass = np.logspace(np.log10(1e+14), np.log10(1e+15), 10)
117+
model, mdef = 'diemer19', '200c'
118+
redshift = 0.5
119+
cosmo = Planck15
120+
sigma8, ns = 0.82, 0.96
121+
c = concentration(mass, mdef, redshift, model, cosmo, sigma8, ns)
122+
123+
assert len(c) == len(mass)
124+
125+
126+
@pytest.mark.skipif(not HAS_COLOSSUS, reason='test requires colossus')
127+
@pytest.mark.flaky
128+
def test_colossus_radius():
129+
from skypy.halos._colossus import radius
130+
from astropy.cosmology import Planck15
131+
132+
mass, c, redshift = 1e+15, 3, 0.5
133+
Delta, mdef = '500c', '200c'
134+
cosmo = Planck15
135+
sigma8, ns = 0.82, 0.96
136+
137+
rs, RDelta = radius(mass, c, redshift, mdef, Delta, cosmo, sigma8, ns)
138+
139+
assert rs > 0
140+
assert RDelta > 0
141+
142+
143+
@pytest.mark.skipif(not HAS_COLOSSUS, reason='test requires colossus')
144+
@pytest.mark.flaky
145+
def test_colossus_Delta_Sigma():
146+
from skypy.halos._colossus import Delta_Sigma
147+
from astropy.cosmology import Planck15
148+
149+
mass, c, redshift = 1e+15, 3, 0.5
150+
mdef = '200c'
151+
cosmo = Planck15
152+
sigma8, ns = 0.82, 0.96
153+
radius = np.logspace(np.log10(300), np.log10(3000), 10)
154+
155+
DeltaSigma = Delta_Sigma(mass, c, redshift, mdef, radius, cosmo, sigma8, ns)
156+
157+
assert len(DeltaSigma) == len(radius)

0 commit comments

Comments
 (0)