This repository was archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_size.py
126 lines (108 loc) · 4.18 KB
/
plot_size.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""
Galaxy Size Distributions
=========================
This example demonstrate how to sample sizes for early and late type galaxies
in SkyPy.
"""
# %%
# Size-Magnitude Relation
# -------------------------
#
# In Shen et al. 2003 [1]_, the observed sizes, :math:`R`, of galaxies
# were shown to follow simple analytic relations as a function of their absolute
# magnitudes, :math:`M`.
# For early-type galaxies, their mean radius follows Equation 14:
#
# .. math::
#
# \log_{10} (\bar{R}/{\rm kpc}) = -0.4aM + b,
#
# with :math:`a` and :math:`b` fitting constants. Likewise, late-type galaxies
# follow Equation 15:
#
# .. math::
#
# \log_{10}(\bar{R}/{\rm kpc})=-0.4\alpha M+
# (\beta -\alpha)\log \left[1+10^{-0.4(M-M_0)}\right]+\gamma \, .
#
# The dispersion on these relations is given by Equation 16:
#
# .. math::
#
# \sigma_{ln R} = \sigma_2 + \frac{\sigma_1 - \sigma_2}{1 + 10^{-0.8(M - M_0)}}
#
# where :math:`\alpha`, :math:`\beta`, :math:`\gamma`, :math:`\sigma_1`, :math:`\sigma_2` and
# :math:`M_0` are fitting parameters.
#
# In SkyPy, we can sample physical sizes for each galaxy type from lognormal distributions,
# with median :math:`\bar{R}` and width :math:`\sigma_{ln R}`, using the functions
# :func:`skypy.galaxy.size.early_type_lognormal()` and
# :func:`skypy.galaxy.size.late_type_lognormal()`.
#
# In this example, we simulate the sizes of galaxies with random magnitudes using the
# values for the parameters
# given in Shen et al. 2003 Table 1 [1]_ :
import numpy as np
import matplotlib.pyplot as plt
from skypy.galaxy.size import early_type_lognormal, late_type_lognormal
# Parameters for the late-type and early-type galaxies
alpha, beta, gamma = 0.21, 0.53, -1.31
a, b = 0.6, -4.63
M0 = -20.52
sigma1, sigma2 = 0.48, 0.25
# SkyPy late sample
M_late = np.random.uniform(-16, -24, size=10000)
R_late = late_type_lognormal(M_late, alpha, beta, gamma, M0, sigma1, sigma2).value
# SkyPy early sample
M_early = np.random.uniform(-18, -24, size=10000)
R_early = early_type_lognormal(M_early, a, b, M0, sigma1, sigma2).value
# %%
# Validation against SDSS Data
# ----------------------------
# Here we reproduce Figure 4 from [1]_, comparing our simulated galaxy sizes against
# observational data from SDSS.
# You can download the data files for `early-type
# <https://github.com/skypyproject/skypy/raw/master/examples/galaxies/Shen+03_early.txt>`_
# and `late-type
# <https://github.com/skypyproject/skypy/raw/master/examples/galaxies/Shen+03_late.txt>`_
# SDSS galaxies which have the following columns: magnitudes, median radius, minus error, and
# plus error.
# Load data from figure 4 in Shen et al 2003
sdss_early = np.loadtxt('Shen+03_early.txt')
sdss_late = np.loadtxt('Shen+03_late.txt')
error_late = (sdss_late[:, 2], sdss_late[:, 3])
error_early = (sdss_early[:, 2], sdss_early[:, 3])
# Bins for median radii
M_bins_late = np.arange(-16, -24.1, -0.5)
M_bins_early = np.arange(-18, -24.1, -0.5)
# Center bins
center_late = (M_bins_late[:-1] + M_bins_late[1:]) / 2
center_early = (M_bins_early[:-1] + M_bins_early[1:]) / 2
# Median sizes for SkyPy late- and early-type galaxies
R_bar_early = [np.median(R_early[(M_early <= Ma) & (M_early > Mb)])
for Ma, Mb in zip(M_bins_early, M_bins_early[1:])]
R_bar_late = [np.median(R_late[(M_late <= Ma) & (M_late > Mb)])
for Ma, Mb in zip(M_bins_late, M_bins_late[1:])]
# Plot
plt.plot(center_early, R_bar_early, 'r', label='SkyPy early')
plt.plot(center_late, R_bar_late, 'b', label='SkyPy late')
plt.errorbar(sdss_early[:, 0], sdss_early[:, 1], yerr=error_early, color='coral',
marker='s', label='Shen+03 early', ls='none')
plt.errorbar(sdss_late[:, 0], sdss_late[:, 1], yerr=error_late, color='deepskyblue',
marker='^', label='Shen+03 late', ls='none')
plt.ylim(5e-1, 2e1)
plt.xlim(-16, -24)
plt.xlabel('Magnitude $M$')
plt.ylabel('$R_{50,r} (kpc)$')
plt.legend(frameon=False)
plt.yscale('log')
plt.show()
# %%
# References
# ----------
#
#
# .. [1] S. Shen, H.J. Mo, S.D.M. White, M.R. Blanton, G. Kauffmann, W. Voges,
# Brinkmann, I. Csabai, `Mon. Not. Roy. Astron. Soc. 343, 978 (2003)`_
#
# .. _Mon. Not. Roy. Astron. Soc. 343, 978 (2003): https://arxiv.org/pdf/astro-ph/0301527.pdf