Skip to content

Commit 8410f33

Browse files
authored
Merge branch 'main' into galaxyq
2 parents b9a792d + 1132130 commit 8410f33

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

docs/galaxies.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ The following models are found in the `skypy.galaxies.stellar_mass` package.
9595
schechter_smf_phi_satellite_quenched
9696

9797

98+
Velocity dispersion
99+
-------------------
100+
101+
The following models are found in the `skypy.galaxies.velocity_dispersion` package.
102+
103+
.. currentmodule:: skypy.galaxies.velocity_dispersion
104+
.. autosummary::
105+
:nosignatures:
106+
107+
schechter_vdf
108+
109+
98110
Reference/API
99111
=============
100112

@@ -107,3 +119,4 @@ Reference/API
107119
.. automodapi:: skypy.galaxies.spectrum
108120
:include-all-objects:
109121
.. automodapi:: skypy.galaxies.stellar_mass
122+
.. automodapi:: skypy.galaxies.velocity_dispersion

skypy/galaxies/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from . import redshift # noqa F401,F403
1414
from . import spectrum # noqa F401,F403
1515
from . import stellar_mass # noqa F401,F403
16+
from . import velocity_dispersion # noqa F401,F403
1617

1718
from ._schechter import schechter_lf # noqa
1819
from ._schechter import schechter_smf # noqa
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import numpy as np
2+
from scipy.stats import kstest
3+
from scipy.special import gamma
4+
from scipy.integrate import cumtrapz
5+
6+
7+
def test_schechter_vdf():
8+
from skypy.galaxies.velocity_dispersion import schechter_vdf
9+
10+
# test schechter velocity dispersion function
11+
vd_min = 1
12+
vd_max = 300
13+
size = 5000
14+
alpha = 2.32
15+
beta = 2.67
16+
vd_star = 161
17+
resolution = 3000
18+
phi_star = 8e-3
19+
samples = schechter_vdf(alpha=alpha, beta=beta, vd_star=vd_star,
20+
vd_min=vd_min, vd_max=vd_max, size=size, resolution=resolution)
21+
22+
# test output is within limits and size
23+
assert len(samples) == size
24+
assert vd_min <= samples.all() <= vd_max
25+
26+
# test that sampling corresponds to sampling from the right pdf
27+
def calc_pdf(vd):
28+
return phi_star*(vd/vd_star)**alpha*np.exp(-(vd/vd_star)**beta) * \
29+
(beta/gamma(alpha/beta))*(1/vd)
30+
31+
def calc_cdf(m):
32+
pdf = calc_pdf(m)
33+
cdf = cumtrapz(pdf, m, initial=0)
34+
cdf /= cdf[-1]
35+
return cdf
36+
37+
p_value = kstest(samples, calc_cdf)[1]
38+
assert p_value > 0.01

skypy/galaxies/velocity_dispersion.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
r"""Models of galaxy velocity dispersion.
2+
3+
"""
4+
5+
import numpy as np
6+
from skypy.utils.random import schechter
7+
8+
__all__ = [
9+
'schechter_vdf',
10+
]
11+
12+
13+
def schechter_vdf(alpha, beta, vd_star, vd_min, vd_max, size=None, resolution=1000):
14+
r"""Sample velocity dispersion of elliptical galaxies in the local universe
15+
following a Schecter function.
16+
17+
Parameters
18+
----------
19+
alpha: int
20+
The alpha parameter in the modified Schechter equation.
21+
beta: int
22+
The beta parameter in the modified Schechter equation.
23+
vd_star: int
24+
The characteristic velocity dispersion.
25+
vd_min, vd_max: int
26+
Lower and upper bounds of random variable x. Samples are drawn uniformly from bounds.
27+
resolution: int
28+
Resolution of the inverse transform sampling spline. Default is 100.
29+
size: int
30+
Number of samples returned. Default is 1.
31+
32+
Returns
33+
-------
34+
velocity_dispersion: array_like
35+
Velocity dispersion drawn from Schechter function.
36+
37+
Notes
38+
-----
39+
The probability distribution function :math:`p(\sigma)` for velocity dispersion :math:`\sigma`
40+
can be described by a Schechter function (see eq. (4) in [1]_)
41+
42+
.. math::
43+
44+
\phi = \phi_* \left(\frac{\sigma}{\sigma_*}\right)^\alpha
45+
\exp\left[-\left( \frac{\sigma}{\sigma_*} \right)^\beta\right]
46+
\frac{\beta}{\Gamma(\alpha/\beta)} \frac{1}{\sigma} \mathrm{d}\sigma \;.
47+
48+
where :math:`\Gamma` is the gamma function, :math:`\sigma_*` is the
49+
characteristic velocity dispersion, :math:`\phi_*` is
50+
number density of all spiral galaxies and
51+
:math:`\alpha` and :math:`\beta` are free parameters.
52+
53+
References
54+
----------
55+
.. [1] Choi, Park and Vogeley, (2007), astro-ph/0611607, doi:10.1086/511060
56+
57+
"""
58+
59+
if np.ndim(alpha) > 0:
60+
raise NotImplementedError('only scalar alpha is supported')
61+
62+
alpha_prime = alpha/beta - 1
63+
x_min, x_max = (vd_min/vd_star)**beta, (vd_max/vd_star)**beta
64+
65+
samples = schechter(alpha_prime, x_min, x_max, resolution=resolution, size=size)
66+
samples = samples**(1/beta) * vd_star
67+
68+
return samples

0 commit comments

Comments
 (0)