1
0
Fork 0
mirror of https://github.com/Findus23/rebound-collisions.git synced 2024-09-19 15:53:48 +02:00
rebound-collisions/collisionhistory.py

78 lines
2.5 KiB
Python
Raw Normal View History

2021-02-03 22:06:37 +01:00
from matplotlib import pyplot as plt
2021-03-03 14:59:14 +01:00
from matplotlib.axes import Axes
from matplotlib.figure import Figure
2021-02-03 22:06:37 +01:00
from rebound import SimulationArchive, Simulation
from extradata import ExtraData, CollisionMeta
2021-05-03 16:31:30 +02:00
from utils import filename_from_argv, earth_mass, earth_water_mass, plot_settings, is_ci
plot_settings()
2021-02-03 22:06:37 +01:00
fn = filename_from_argv()
2021-02-04 17:29:01 +01:00
ed = ExtraData.load(fn)
2021-02-03 22:06:37 +01:00
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)
2021-03-03 14:59:14 +01:00
fig: Figure = plt.figure()
ax_masses: Axes = fig.add_subplot(2, 1, 1)
ax_wmfs: Axes = fig.add_subplot(2, 1, 2)
2021-03-03 14:59:14 +01:00
2021-02-03 22:06:37 +01:00
for particle in last_sim.particles:
if ed.pd(particle).type in ["sun", "gas giant"]:
continue
masses = []
objects = []
times = []
hash = particle.hash.value
2021-02-04 13:42:06 +01:00
objects.append(ed.pdata[hash])
times.append(ed.meta.current_time)
2021-02-03 22:06:37 +01:00
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)
2021-02-03 22:06:37 +01:00
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) # TODO: check log-x
2021-02-04 13:42:06 +01:00
if len(times) < 3:
2021-02-03 22:06:37 +01:00
continue
masses = [p.total_mass for p in objects]
wmfs = [p.water_mass_fraction for p in objects]
2021-03-03 14:59:14 +01:00
figs = []
ax_masses.step(times, masses, label=particle.hash.value)
ax_wmfs.step(times, wmfs, label=particle.hash.value)
ax_wmfs.set_ylabel("water mass fraction")
ax_masses.set_ylabel("masses [kg]")
for ax in [ax_wmfs, ax_masses]:
ax.set_xlim(1e4, ed.meta.current_time)
2021-03-03 14:59:14 +01:00
ax.set_xlabel("time [yr]")
ax.set_xscale("log")
ax.set_yscale("log")
ax.legend()
twin_ax = ax_masses.twinx()
mn, mx = ax_masses.get_ylim()
twin_ax.set_ylim(mn / earth_mass, mx / earth_mass)
twin_ax.set_ylabel('[$M_\\oplus$]')
twin_ax.set_yscale("log")
ax_wmfs.axhline(earth_water_mass/earth_mass,linestyle="dotted")
2021-03-03 14:59:14 +01:00
fig.tight_layout()
2021-05-03 16:31:30 +02:00
if not is_ci():
fig.savefig("/home/lukas/tmp/collisionhistory.pdf", transparent=True)
2021-02-03 22:06:37 +01:00
plt.show()