-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathhr_diagram.py
191 lines (156 loc) · 5.47 KB
/
hr_diagram.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""
Create a Hertzprung-Russell (temperature-luminosity) diagram and
mass-luminosity and mass-temperature diagrams populating the main sequence only
with data from Ekström+ 2012 (Vizier catalog J/A+A/537/A146/iso).
Colors come from vendian.org.
"""
import numpy as np
import imf
import pylab as pl
from astroquery.vizier import Vizier
from labellines import labelLine, labelLines
# pip install matplotlib-label-lines
pl.rcParams['font.size'] = 20
Vizier.ROW_LIMIT=1e7
tbl = Vizier.get_catalogs('J/A+A/537/A146/iso')[0]
agemass = {}
agelum = {}
for age in np.unique(tbl['logAge']):
agemass[age] = tbl[tbl['logAge']==age]['Mass'].max()
agelum[age] = tbl[tbl['logAge']==age]['logL'].max()
# mass-temperature diagram
pl.figure(2, figsize=(8,8)).clf()
# select a specific population age to plot - this is the youngest, with all
# stars alive and main-sequence
ok = tbl['logAge'] == 6.5
subtbl = tbl[ok]
subtbl.sort('Mass')
lowmass = subtbl[subtbl['Mass'] < 2]
# downsample the high-mass part of the sample to avoid point overlap
subtbl = subtbl[(subtbl['Mass'] < 25) & (subtbl['logTe']<4.6)]
highmass = subtbl[(subtbl['Mass'] > 20) & (subtbl['logTe']<4.6)]
subtbl=subtbl[::20]
# fill in (oversample) the low-mass portion
Lfit = np.polyfit(np.log10(lowmass['Mass']), lowmass['logL'], 1)
# the fit is not exactly right; there's a break at 0.43ish, but it's good enough
masses = np.logspace(np.log10(0.1), np.log10(0.8))
lums = np.poly1d(Lfit)(np.log10(masses))
# this was an old by-hand fit
#lums[masses<(0.43)] = np.log10(0.23*(masses[masses<(0.43)])**2.3)
Tfit = np.polyfit(np.log10(lowmass['Mass']), lowmass['logTe'], 1)
tems = np.poly1d(Tfit)(np.log10(masses))
hmasses = np.logspace(np.log10(25), np.log10(60),5)
Lfit = np.polyfit(np.log10(highmass['Mass']), highmass['logL'], 1)
hlums = np.poly1d(Lfit)(np.log10(hmasses))
#lums[masses<(0.43)] = np.log10(0.23*(masses[masses<(0.43)])**2.3)
Tfit = np.polyfit(np.log10(highmass['Mass']), highmass['logTe'], 1)
htems = np.poly1d(Tfit)(np.log10(hmasses))
# obtain the colors from the vendian-based table
colors = [imf.color_from_mass(m) for m in subtbl['Mass']]
# start plotting
pl.gca().set_yscale('log')
pl.scatter(10**subtbl['logTe'],
subtbl['Mass'],
c=colors,
s=(10**subtbl['logL'])**0.25*45)
colors = [imf.color_from_mass(m) for m in masses]
pl.scatter(10**tems,
masses,
c=colors,
s=(10**lums)**0.25*45)
colors = [imf.color_from_mass(m) for m in hmasses]
pl.scatter(10**htems,
hmasses,
c=colors,
s=(10**hlums)**0.25*45)
# overlay star age horizontal lines
lines = []
for age in (6.5, 7, 8, 10):
L, = pl.plot([10**tems.min(), (10**htems.max())],
[agemass[age]]*2, linestyle='--', color='k',
label="$10^{{{0}}}$ yr".format(age))
lines.append(L)
labelLines(lines)
pl.xlabel("Temperature")
pl.ylabel("Mass")
pl.tight_layout()
pl.savefig("tem_lum_diagram.svg")#, bbox_inches='tight')
# HR diagram (temperature-luminosity)
pl.figure(3, figsize=(8,8)).clf()
colors = [imf.color_from_mass(m) for m in subtbl['Mass']]
#pl.gca().set_xscale('log')
pl.gca().set_yscale('log')
pl.scatter(10**subtbl['logTe'],
10**subtbl['logL'],
c=colors,
s=(subtbl['Mass'])*5)
colors = [imf.color_from_mass(m) for m in masses]
pl.scatter(10**tems,
10**lums,
c=colors,
s=masses*5)
colors = [imf.color_from_mass(m) for m in hmasses]
pl.scatter(10**htems,
10**hlums,
c=colors,
s=hmasses*5)
# I attempted to add age lines, but this approach is incorrect
#suns live 5 Gyr, not 10+ Gyr
# lines = []
# for age in (6.5, 7, 8, 10):
# L, = pl.plot([10**tems.min(), (10**htems.max())],
# [10**agelum[age]]*2,
# linestyle='--', color='k',
# label="$10^{{{0}}}$ yr".format(age))
# lines.append(L)
labelLines(lines)
pl.xlabel("Temperature")
pl.ylabel("Luminosity")
pl.tight_layout()
pl.savefig("HR_diagram.svg")#, bbox_inches='tight')
# mass-luminosity diagram
pl.figure(4, figsize=(8,8)).clf()
colors = [imf.color_from_mass(m) for m in subtbl['Mass']]
#pl.gca().set_xscale('log')
pl.gca().set_yscale('log')
pl.scatter(subtbl['Mass'],
10**subtbl['logL'],
c=colors,
edgecolors='none',
s=10**subtbl['logTe']/100)
colors = [imf.color_from_mass(m) for m in masses]
pl.scatter(masses,
10**lums,
c=colors,
edgecolors='none',
s=10**tems/100)
colors = [imf.color_from_mass(m) for m in hmasses]
pl.scatter(hmasses,
10**hlums,
c=colors,
edgecolors='none',
s=10**htems/100)
#lines = []
#for age in (6.5, 7, 8, 10):
# L, = pl.plot([masses.min(), hmasses.max()],
# [10**agelum[age]]*2,
# linestyle='--', color='k',
# label="$10^{{{0}}}$ yr".format(age))
# lines.append(L)
labelLines(lines)
pl.xlabel("Mass")
pl.ylabel("Luminosity")
pl.tight_layout()
pl.savefig("mass_luminosity.svg")#, bbox_inches='tight')
pl.loglog()
pl.savefig("mass_lum_diagram_loglog.svg")#, bbox_inches='tight')
pl.savefig("mass_lum_diagram_loglog.png", bbox_inches='tight')
# from Zinnecker & Yorke fig 1
pl.plot(np.logspace(0,1),
np.logspace(0,1)**3.7,
'k--')
pl.plot(np.logspace(1,2),
np.logspace(1,2)**1.6 * 1e6/100**1.6,
'k--')
pl.savefig("mass_lum_diagram_loglog_ZinnPlots.svg")#, bbox_inches='tight')
pl.savefig("mass_lum_diagram_loglog_ZinnPlots.png", bbox_inches='tight')