forked from VirtualPlanetaryLaboratory/vplanet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakeplot.py
115 lines (95 loc) · 2.98 KB
/
makeplot.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
import pathlib
import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import vplot as vpl
from matplotlib.ticker import FormatStrFormatter
import vplanet
# Path hacks
path = pathlib.Path(__file__).parents[0].absolute()
sys.path.insert(1, str(path.parents[0]))
from get_args import get_args
class Planet:
a = 0.0
e = 0.0
i = 0.0
LongP = 0.0
LongA = 0.0
MeanA = 0.0
x1 = 0.0
x2 = 0.0
x3 = 0.0
v1 = 0.0
v2 = 0.0
v3 = 0.0
Time = []
Mass = 0.0
def ReadHNBody(FileName):
planet = Planet()
(
planet.Time,
planet.a,
planet.e,
planet.i,
planet.LongP,
planet.LongA,
planet.MeanA,
planet.x1,
planet.x2,
planet.x3,
planet.v1,
planet.v2,
planet.v3,
) = np.loadtxt(FileName, skiprows=17, unpack=True)
planet.MeanA[planet.MeanA < 0] += 360
planet.LongP[planet.LongP < 0] += 360
planet.LongA[planet.LongA < 0] += 360
planet.a = planet.a
return planet
# Run vplanet
SS = vplanet.run(path / "vpl.in", units=False, quiet=True)
# Get hnbody results
hnEarth = ReadHNBody(path / "earth.dat")
hnEarth.Mass = 1.0
fig, ([ax1, ax2], [ax3, ax4], [ax5, ax6]) = plt.subplots(3, 2, figsize=[14, 16])
ax1.plot(hnEarth.Time, hnEarth.a, color=vpl.colors.red)
ax1.plot(SS.Earth.Time, SS.Earth.SemiMajorAxis, "k")
ax1.set_rasterization_zorder(0)
ax1.set_ylabel("Semi-Major Axis (AU)")
ax1.yaxis.set_major_formatter(FormatStrFormatter("%.6f"))
ax2.plot(hnEarth.Time, hnEarth.e, color=vpl.colors.red)
ax2.plot(SS.Earth.Time, SS.Earth.Eccentricity, "k")
ax2.set_ylabel("Eccentricity")
plt.subplot(3, 2, 3)
plt.plot(hnEarth.Time, hnEarth.i, color=vpl.colors.red)
plt.plot(SS.Earth.Time, SS.Earth.SpiNBodyInc, "k")
plt.legend(["HNBody", "VPLanet"], loc="upper left")
plt.ylabel("Inclination ($^\circ$)")
plt.subplot(3, 2, 4)
plt.plot(hnEarth.Time, hnEarth.LongP, color=vpl.colors.red, marker=".", linewidth=0)
plt.plot(SS.Earth.Time, SS.Earth.LongP, "k", marker=".", linewidth=0)
plt.xlabel("Time (yrs)")
plt.ylim(0, 360)
plt.ylabel("Longitude of Pericenter ($^\circ$)")
plt.subplot(3, 2, 5)
plt.plot(hnEarth.Time, hnEarth.LongA, color=vpl.colors.red, marker=".", linewidth=0)
plt.plot(SS.Earth.Time, SS.Earth.SpiNBodyLongA, color="k", marker=".", linewidth=0)
plt.ylim(0, 360)
plt.ylabel("Longitude of Ascending Node ($^\circ$)")
plt.xlabel("Time (yrs)")
etot = (SS.Sun.TotOrbEnergy / SS.Sun.TotOrbEnergy[0] - 1) * 1e9
jtot = (SS.Sun.TotAngMom / SS.Sun.TotAngMom[0] - 1) * 1e11
plt.subplot(3, 2, 6)
plt.plot(SS.Sun.Time, etot, color=vpl.colors.orange, label=(r"Energy $\times 10^9$"))
plt.plot(
SS.Sun.Time, jtot, color=vpl.colors.purple, label=(r"Ang. Mom. $\times 10^{11}$")
)
plt.xlabel("Time (yr)", fontsize=16)
plt.ylabel(r"$(\Delta E / E - 1)/10^{9}$", fontsize=16)
plt.ylabel(r"$\Delta$E, $\Delta$J")
plt.xlabel("Time (yrs)")
plt.legend(loc="upper left")
# Save the figure
ext = get_args().ext
fig.savefig(path / f"SS_NBody.{ext}")