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
|
|
|
|
from utils import filename_from_argv
|
|
|
|
|
|
|
|
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-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"]
|
|
|
|
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_xlabel("time [yr]")
|
|
|
|
ax.set_xscale("log")
|
|
|
|
ax.set_yscale("log")
|
|
|
|
ax.legend()
|
|
|
|
fig.tight_layout()
|
2021-02-03 22:06:37 +01:00
|
|
|
plt.show()
|