-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
294 lines (219 loc) · 10.9 KB
/
models.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
from db import *
##########################################################################################
# MIST - MESA
##########################################################################################
# Tracks and isochrones from MIST are downloaded from:
# https://waps.cfa.harvard.edu/MIST/interp_tracks.html
# https://waps.cfa.harvard.edu/MIST/interp_isos.html
# MIST version 1.2
# For a "list of ages" splitted in two (for Log10 Scale):
# 1) 6.0 6.301 6.477 6.602 6.699 6.778 6.845 6.903 6.954 7.0 7.041 7.079 7.114 7.146 7.176
# 7.204 7.23 7.255 7.279 7.301 7.342 7.38 7.415 7.447 7.477 7.505 7.544 7.58 7.613 7.653
# 2) 7.699 7.778 7.845 7.903 7.954 8.0 8.041 8.079 8.114 8.146 8.176 8.204 8.23 8.255 8.279
# 8.301 8.322 8.342 8.362 8.38 8.398 8.415 8.431 8.447 8.462 8.477 8.491 8.505 8.519 8.531
# 8.544 8.556 8.568 8.58 8.591 8.602
# Synthetic Photometry: UBV(RI)c + 2MASS + Kepler + Hipparcos + Gaia (DR2/MAW/EDR3) + Tess
def isomist(myr=None, logmyr=None, av=1.0, vr=0.4):
'''
Function to retrieve a specific isochrone from the MIST.
Parameters
----------
myr : int/float, optional
Enter the age in Myr of the isochrone you want to retrieve.
logmyr : int/float, optional
Enter the age as log10(Myr) of the isochrone you want to retrieve.
av : float, optional
Enter the extinction (Av) of the isochrone to retrieve. Default is 1.0.
vr : float, optional
Enter the initial v/v_crit value [0.0/0.4]. Default is 0.4.
Returns
-------
MIST isochrone.
'''
myr_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 28, 30, \
32, 35, 38, 41, 45, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, \
220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400]
logmyr_list = [6.0, 6.301, 6.477, 6.602, 6.699, 6.778, 6.845, 6.903, 6.954, 7.0, 7.041, 7.079, \
7.114, 7.146, 7.176, 7.204, 7.23, 7.255, 7.279, 7.301, 7.342, 7.38, 7.415, 7.447, 7.477, 7.505, \
7.544, 7.58, 7.613, 7.653, 7.699, 7.778, 7.845, 7.903, 7.954, 8.0, 8.041, 8.079, 8.114, 8.146, \
8.176, 8.204, 8.23, 8.255, 8.279, 8.301, 8.322, 8.342, 8.362, 8.38, 8.398, 8.415, 8.431, 8.447, \
8.462, 8.477, 8.491, 8.505, 8.519, 8.531, 8.544, 8.556, 8.568, 8.58, 8.591, 8.602]
if av < 1.0: Av = str(av).replace('.','')
else: Av = int(av*10)
vr = str(vr).replace('.','')
if myr != None:
if not myr in myr_list:
print('Age not in list %s' % myr_list)
myr = int(input('Pick a new age from the list: '))
logage = round(np.log10(myr*1e6),3)
if logmyr != None:
logage = min(logmyr_list, key=lambda x:abs(x-logmyr))
if abs(logage-logmyr) > 0.3:
print('Difference to closes isochrone is grater than 0.3 (~2Myr)')
if logage < 7.676: ranage = '1-45'
else: ranage = '50-300'
# NOTE: Edit every new table from MIST removing the first lines before the column names.
t_mist = Table.read(modeldir + 'MIST/ISOCHRONES/ISOC_FeH0_%sMyr_Av%s_V%s.fits' % \
(ranage,Av,vr),format='fits')
t_mist = t_mist[t_mist['log10_isochrone_age_yr'] == logage]
return t_mist
def trackmist(mass=None, av=0.0, vr=0.4):
'''
Function to retrieve a specific track from the MIST.
Parameters
----------
mass : int/float, optional
Enter the mass in M/M_sun of the track you want to retrieve.
If None as input, all the tracks will be selected.
Available masses are: 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.5, 1.7,
2.0, 2.5, 3, 4, 5, 7, 9, 12, 15, 20, 25, 32, 40, 60, 85, 120.
av : float, optional
Enter the extinction (Av) of the isochrone to retrieve. Default is 1.0.
vr : float, optional
Enter the initial v/v_crit value [0.0/0.4]. Default is 0.4.
Returns
-------
MIST isochrone.
'''
if av < 1.0: Av = str(av).replace('.','')
else: Av = int(av*10)
vr = str(vr).replace('.','')
mass_list = [0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.5, 1.7, 2.0, 2.5, 3, 4, 5, 7, 9, 12, 15, 20, 25, 32, 40, 60, 85, 120]
if mass != None and mass in mass_list:
mass = str(float(mass)).replace('.',''); digit = 4-len(mass)
mass = '0'*digit+mass
t_mist = Table.read(modeldir + 'MIST/TRACKS/TRAC_FeH0_Av%s_V%s/TRAC_FeH0_%sMsol_Av%s_V%s.fits' % \
(Av,vr,mass,Av,vr), format='fits')
else:
t_mist = Table.read(modeldir + 'MIST/TRACKS/TRAC_FeH0_Av%s_V%s/TRAC_FeH0_08-120_Av%s_V%s.fits' % \
(Av,vr,Av,vr))
return t_mist
## To generate individual tables from MIST imput files (tracks), and a master FITS
## with all the tracks
## NOTE: Edit every new table from MIST removing the first lines before the column names.
#t_master = Table()
#path = os.path.expanduser('~')+'/Documents/MIST/'
#for file in os.listdir(path):
# if file.endswith('.cmd'):
# try: t_mist = Table.read(path+file, format='ascii')
# except: print(file,' could not be read. Check the file.')
# mass = str(round(t_mist['star_mass'][0],1)).replace('.','')
# digit = 4-len(mass); mass = '0'*digit+mass
# t_mist = t_mist[(t_mist['phase']>=0) & (t_mist['phase']<=4)]
#
# hdu = fits.BinTableHDU(data=t_mist.filled(np.nan))
# hdu.writeto(path+'TRAC_FeH0_%sMsol_Av00_V00.fits' % mass,overwrite=True)
#
# t_master = vstack([t_master,t_mist],join_type='outer')
#
#hdu = fits.BinTableHDU(data=t_master.filled(np.nan))
#hdu.writeto(path+'TRAC_FeH0_08-120_Av00_V00.fits' ,overwrite=True)
##########################################################################################
# GENEVA SYLVIA EKSTROM
##########################################################################################
# Tracks and isochrones from Geneva are downloaded from:
# https://obswww.unige.ch/Research/evol/tables_grids2011/
def trackgene(mass=None, vr=0.4):
'''
Function to retrieve a specific track from the Geneva.
Parameters
----------
mass : int/float, optional
Enter the mass in M/M_sun of the track you want to retrieve.
If None as input, all the tracks will be selected.
vr : float, optional
Enter the initial v/v_crit value [0.0/0.2/0.4]. Default is 0.4.
Returns
-------
Geneva isochrone
Notes 'line' column
-------------------
1: ZAMS
2-84: H burning (first part)
85: minimum of Teff on the MS
86-109: overall contraction phase before the end of the MS
110: Turn-off
111-189: HR diagram crossing and/or pre-He-b core contraction
190: beginning of He burning
191-209: He burning (first part)
210-350: blue loop (if any, maximal extension on point 280)
351-369: He burning (second part)
370: core He exhaustion
371-399: C burning
400: last model
'''
if mass == None:
print('ERROR: No mass given. Please enter a mass in M/M_sun.')
return
if not vr in [0.0, 0.2, 0.4]:
print('WARNING: Geneva tracks are only available for v/vcrit = 0.0, 0.2, and 0.4')
vr = min([0.0, 0.2, 0.4], key=lambda x:abs(x-vr))
print('Choosing %s as the closest value.' % vr)
if vr in [0.0, 0.4]:
mass_list = [0.8, 0.9, 1.0, 1.1, 1.25, 1.35, 1.5, 1.7, 2.0, 2.5, 3, 4, 5, 7, 9, 12, 15, 20, 25, 32, 40, 60, 85, 120]
elif vr == 0.2:
mass_list = [20, 25, 32, 40, 60, 85, 120]
vr = str(vr).replace('0.','')
if type(mass) is not str and not mass in mass_list:
print('WARNING: Mass not in list %s' % mass_list)
mass = min(mass_list, key=lambda x:abs(x-mass))
print('Choosing %s as the closest value.' % mass)
# if mass is a round number, turn it into an integer
if type(mass) is float and mass.is_integer():
mass = str(int(mass))
elif type(mass) is not str and mass in mass_list:
mass = str(mass).replace('.','p')
digit = 3-len(mass)
mass = '0'*digit+mass
t_geneva = Table.read(modeldir + 'GENEVA/M%sZ14V%s.dat' % (mass,vr), format='ascii', data_start=2, delimiter=' ')
# FROM Gonzalo
t_geneva.rename_columns(['lg(Teff)','lg(L)'],['log_Teff','log_L'])
#t_geneva['L'] = (10**t_geneva['lg(L)'])
t_geneva['Teff'] = (10**t_geneva['log_Teff'])/1e4
t_geneva['log_LLsol'] = t_geneva['log_L'] - np.log10(t_geneva['mass']) # NOT SURE ABOUT THIS ONE
t_geneva['log_g'] = 4*t_geneva['log_Teff'] + np.log10(t_geneva['mass']) - t_geneva['log_L'] - 10.61
t_geneva['log_Lspec'] = 4*t_geneva['log_Teff'] - t_geneva['log_g'] - 10.61
t_geneva['He'] = t_geneva['4He_surf']/4/t_geneva['1H_surf']
# missing to implement a table with everything
#else:
# t_geneva = Table.read(modeldir + 'MIST/TRACKS/TRAC_FeH0_Av%s_V%s/TRAC_FeH0_08-120_Av%s_V%s.fits' % \
# (Av,vr,Av,vr))
return t_geneva
##########################################################################################
# BONN BROTT 2011
##########################################################################################
# Models (tracks) and isochrones from Brott et al. are downloaded from:
# https://cdsarc.u-strasbg.fr/viz-bin/qcat?J/A+A/530/A115
def trackbonn(mass=None, vr=np.nan):
'''
Function to retrieve a specific track from the Geneva.
Parameters
----------
[UNDER CONSTRUCTION]
'''
mass_list = [5, 7, 9, 10, 12, 15, 20, 25, 30, 35, 40, 50, 60]
while mass not in mass_list:
print('Mass %s not in list %s' % (str(mass),mass_list))
mass = int(input('Pick a new mass: '))
# find all models starting with f+mass
path = modeldir + 'BONN/'
models = [f for f in os.listdir(path) if f.startswith('f'+str(mass))]
vr_list = [int(m.split('-')[1].split('.mw.fits')[0]) for m in models]
# pick the nearest vsini
tmp_vr = min(vr_list, key=lambda x:abs(x-vr))
if abs(tmp_vr-vr) > 20:
print('WARNING: Difference to closest vsini is grater than 20 km/s')
print('Closest vsini is %s km/s' % tmp_vr)
vr = tmp_vr
#while vr not in vr_list:
# print('vsini not in list %s' % vr_list)
# vr = int(input('Pick a new vsini from %s: ' % vr_list))
t_brott = Table.read(modeldir+'BONN/f%s-%s.mw.fits' % (mass,vr), format='fits')
# log(X/H) + 12
for elem in ['He','C','N','O','Mg','Si']:
t_brott[elem] = 10**(t_brott['eps(%s)' % elem]-12)
t_brott.rename_column('logL','log_L')
t_brott['log_Teff'] = np.log10(t_brott['Teff'])
t_brott['log_g'] = 4*t_brott['log_Teff'] + np.log10(t_brott['Mass']) - t_brott['log_L'] - 10.61
t_brott['log_Lspec'] = 4*t_brott['log_Teff'] - t_brott['log_g'] - 10.61
return t_brott