Planetary Orbital Evolution due to Tides
Orbital evolution of two objects experiencing tides
plot_interpolated_YREC_evolution.py
1 #!/usr/bin/python -u
2 
3 from matplotlib import pyplot
4 from matplotlib.backends.backend_pdf import PdfPages
5 from scipy import array, arange
6 
7 YREC_files={'0.5': '../YREC/m0p5_alpha1p9_Y0p28_GN93.track',
8  '0.6': '../YREC/m0p6_alpha1p9_Y0p28_GN93.track',
9  '0.7': '../YREC/m0p7_alpha1p9_Y0p28_GN93.track',
10  '0.8': '../YREC/m0p8_alpha1p9_Y0p28_GN93.track',
11  '0.9': '../YREC/m0p9_alpha1p9_Y0p28_GN93.track',
12  '1.0': '../YREC/m1p0_alpha1p9_Y0p28_GN93.track',
13  '1.05': '../YREC/m1p05_alpha1p9_Y0p28_GN93.track',
14  '1.1': '../YREC/m1p1_alpha1p9_Y0p28_GN93.track',
15  '1.15': '../YREC/m1p15_alpha1p9_Y0p28_GN93.track',
16  '1.2': '../YREC/m1p2_alpha1p9_Y0p28_GN93.track'}
17 
18 plot_colors=['#FF0000', '#03B402', '#0005F7', '#FF6D00', '#FF00FF',
19  '#8F7000', '#0000FF']
20 
21 def evol_fname(mass) :
22  """ Returns the filename with the interpolated track corresponding to the
23  given mass. """
24 
25  return "test_YREC_interp/test_YREC_interp_M%.3f.evol"%mass
26 
27 def read_YREC_file(fname, mass) :
28  """ Reads a YREC track. """
29 
30  Msun=1.98892e30
31  Rsun=6.955e8
32  Inorm=Msun*Rsun*Rsun*1e7
33 
34  f=open(fname)
35  result={'t':[], 'R':[], 'Iconv':[], 'Irad':[], 'Mrad':[], 'Rcore':[]}
36  for l in f :
37  if l[0]=='#' : continue
38  entries=map(eval, l.split())
39  result['t'].append(entries[2])
40  result['R'].append(10.0**entries[7])
41  result['Mrad'].append(entries[10 if mass<1.01 else 12]*mass)
42  result['Rcore'].append(entries[11 if mass<1.01 else 13]*10.0**entries[7])
43  result['Irad'].append(entries[15 if mass<=1.01 else 17]/Inorm)
44  result['Iconv'].append(entries[16 if mass<=1.01 else 18]/Inorm)
45  return result
46 
47 def read_evol_file(fname) :
48  """ Reads an output interpolated evolution file. """
49 
50  f=open(fname)
51  result={'t':[], 'R':[[], [], []], 'L':[[], [], []], 'Iconv':[[], [], []],
52  'Irad':[[], [], []], 'Mrad':[[], [], []], 'Rcore':[[], [], []]}
53  for l in f :
54  if l[0]=='#' : continue
55  entries=map(eval, l.split())
56  result['t'].append(entries[0])
57  for i in range(3) :
58  result['R'][i].append(entries[1+i])
59  result['L'][i].append(entries[4+i])
60  result['Iconv'][i].append(entries[7+i])
61  result['Mrad'][i].append(entries[13+i])
62  result['Rcore'][i].append(entries[16+i])
63  result['Irad'][i].append(entries[19+i])
64  return result
65 
66 def plot_quantity(quantity, low_mass, high_mass, YREC, evol, pdf, logx=True,
67  logy=True) :
68  """ Plots the tracks of the given quantity (a strintg key) for masses
69  in the given range as a separate page in the given PDF. """
70 
71  if logx and logy : plot_cmd=pyplot.loglog
72  elif logx==True : plot_cmd=pyplot.semilogx
73  elif logy==True : plot_cmd=pyplot.semilogy
74  else : plot_cmd=pyplot.plot
75  plot_cmd(YREC[str(low_mass)]['t'], YREC[str(low_mass)][quantity], '-r')
76  plot_cmd(YREC[str(high_mass)]['t'], YREC[str(high_mass)][quantity], '-b')
77  color_ind=0
78  line_style='--'
79  for m in arange(low_mass, high_mass, 0.001) :
80  plot_cmd(evol[str(m)]['t'], evol[str(m)][quantity][0],
81  color=plot_colors[color_ind], linestyle=line_style)
82  first_t=0
83  while evol[str(m)]['t'][first_t]<0.005 : first_t+=1
84  min_ind=evol[str(m)][quantity][0][first_t:].index(min(evol[str(m)][quantity][0][first_t:]))
85  print q, m, evol[str(m)]['t'][min_ind], evol[str(m)][quantity][0][min_ind]
86  color_ind+=1
87  if color_ind==len(plot_colors) :
88  color_ind=0
89  if line_style=='--' : line_style=':'
90  else : line_style='--'
91  pyplot.suptitle("M="+str(low_mass)+"$M_\odot$ to "+str(high_mass)+
92  "$M_\odot$ "+quantity)
93  pdf.savefig()
94  pyplot.close()
95 
96 if __name__=='__main__' :
97  YREC=dict()
98  for mass, fname in YREC_files.iteritems() :
99  YREC[mass]=read_YREC_file(fname, eval(mass))
100  evol=dict()
101  for mass in arange(0.5, 1.205, 0.001) :
102  evol[str(mass)]=read_evol_file(evol_fname(mass))
103  pdf = PdfPages('test_YREC_interp.pdf')
104  YREC_masses=sorted(map(eval, YREC_files.keys()))
105  for q in ['R', 'Iconv', 'Irad', 'Mrad', 'Rcore'] :
106  for i in range(len(YREC_masses)-1) :
107  plot_quantity(q, YREC_masses[i], YREC_masses[i+1], YREC,
108  evol, pdf, True, q in ['R', 'Iconv'])
109  pdf.close()
110  exit(1)