-
Notifications
You must be signed in to change notification settings - Fork 0
/
collisionhistory.py
120 lines (104 loc) · 3.81 KB
/
collisionhistory.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
import random
from sys import argv
from matplotlib import pyplot as plt
from matplotlib.axes import Axes
from matplotlib.figure import Figure
from rebound import SimulationArchive, Simulation
from scipy.constants import mega
from extradata import ExtraData, CollisionMeta
from utils import filename_from_argv, earth_mass, earth_water_mass, plot_settings, is_ci, is_potentially_habitable
files = argv[1:]
multifile = len(files) > 1
plot_settings()
fig: Figure = plt.figure()
ax_masses: Axes = fig.add_subplot(2, 1, 1)
ax_wmfs: Axes = fig.add_subplot(2, 1, 2)
ax_wmfs.set_ylabel("water mass fraction")
ax_masses.set_ylabel("masses [kg]")
for ax in [ax_wmfs, ax_masses]:
ax.set_xlim(1e4, 200 * mega)
ax.set_xlabel("time [yr]")
ax.set_xscale("log")
ax.set_yscale("log")
earth_mass_ax = ax_masses.secondary_yaxis("right",
functions=(lambda x: x / earth_mass, lambda x: x * earth_mass))
earth_mass_ax.set_ylabel('masses [$M_\\oplus$]')
ax_wmfs.axhline(earth_water_mass / earth_mass, linestyle="dotted")
num_formed_planets = 0
num_large_planets = 0
num_habitable_planets = 0
num_water_rich_planets = 0
random.seed(1)
random.shuffle(files)
for file in files:
fn = filename_from_argv(file)
ed = ExtraData.load(fn)
sa = SimulationArchive(str(fn.with_suffix(".bin")))
last_sim: Simulation = sa[-1]
print([p.hash.value for p in last_sim.particles])
print(last_sim.t)
for particle in last_sim.particles:
if ed.pd(particle).type in ["sun", "gas giant"]:
continue
# if not is_potentially_habitable(particle):
# continue
masses = []
objects = []
times = []
hash = particle.hash.value
objects.append(ed.pdata[hash])
times.append(ed.meta.current_time)
num_formed_planets += 1
if particle.m > .6 * earth_mass:
num_large_planets += 1
if is_potentially_habitable(particle):
num_habitable_planets += 1
if ed.pd(particle).water_mass_fraction > 1e-4:
num_water_rich_planets += 1
while True:
print(f"looking at {hash}")
try:
collision = ed.tree.get_tree()[hash]
except KeyError:
print("found end of the tree")
break
meta: CollisionMeta = collision["meta"]
parents = collision["parents"]
print("mass:", ed.pdata[hash].total_mass / earth_mass)
masses.append(ed.pdata[hash].total_mass)
objects.append(ed.pdata[hash])
times.append(meta.time)
# print(collision)
if ed.pdata[parents[0]].total_mass > ed.pdata[parents[1]].total_mass:
hash = parents[0]
else:
hash = parents[1]
objects.append(ed.pdata[hash])
times.append(0)
if len(times) < 3:
continue
masses = [p.total_mass for p in objects]
wmfs = [p.water_mass_fraction for p in objects]
figs = []
if multifile:
args = {
"linewidth": 1,
"color": "black",
"alpha": .3
}
else:
args = {}
ax_masses.step(times, masses, label=particle.hash.value, **args)
ax_wmfs.step(times, wmfs, label=particle.hash.value, **args)
if not multifile:
for ax in [ax_wmfs, ax_masses]:
ax.legend()
print(num_large_planets / num_formed_planets)
habitable_large_planet_fraction = num_habitable_planets / num_large_planets
water_rich_planet_fraction = num_water_rich_planets / num_habitable_planets
print(habitable_large_planet_fraction)
print(water_rich_planet_fraction)
fig.tight_layout()
if not is_ci():
fig.savefig(f"/home/lukas/tmp/collisionhistory_{fn.name}.pdf", transparent=True)
plt.show()