Skip to main content

system_from_simulation

system_from_simulation(sim_data, time=None, G=None)

Rebuild a system from one time step of a simulation.

Takes the positions, velocities and masses recorded at one time and turns them back into an OrbitSystem. Use it to restart a run from a chosen moment, to change something partway through (add a body, remove one) and simulate on, or to save the final state with save_system. The default is the last recorded step.

Parameters

Name Type Description Default
sim_data DataFrame The output of simulate_system or continue_simulation, as a pandas or polars DataFrame. required
time float or None The time to take the state from, in seconds since the start of the run. The recorded step closest to this time is used. The default None uses the last recorded step. None
G float or None Gravitational constant of the new system, in m^3 kg^-1 s^-2. The default None uses the value recorded with the run, or the standard value orb.gravitational_constant if none was recorded. None

Returns

Name Type Description
OrbitSystem A system holding every body present at the chosen time, with its mass in kilograms, position in meters and velocity in meters per second. Bodies are in the order they appear in sim_data.

Raises

Name Type Description
TypeError If sim_data is not a pandas or polars DataFrame with the columns id, mass, x, y, z, vx, vy, vz, time.

See Also

Notes

The new system starts its own clock: simulating it gives times that begin again at 0. continue_simulation keeps the clock running instead.

A polars DataFrame only carries the recorded G if it is the exact DataFrame pyorbiter returned. If you ran with a non-standard G and have filtered or transformed the polars result since, pass G here.

Examples

The state of the Sun and the Earth at the end of a one-year run.

import pyorbiter as orb

sim = orb.create_system().add_sun().add_planet("Earth", parent="Sun").simulate(
    time_step=orb.seconds_per_day, duration=orb.seconds_per_year)

orb.system_from_simulation(sim)
───────────────────────────────── orbit_system ─────────────────────────────────
G: 6.6743e-11 (standard)
Bodies: 2

   id         mass             x             y   z            vx           vy  vz
  Sun 1.989000e+30 -2.797054e+06 -6.431760e+05 0.0      0.000087    -0.000381 0.0
Earth 5.972000e+24 -3.234357e+10  1.435019e+11 0.0 -29549.046043 -6661.380200 0.0

The state 100 days in, with Mars added before simulating on.

import pyorbiter as orb

sim = orb.create_system().add_sun().add_planet("Earth", parent="Sun").simulate(
    time_step=orb.seconds_per_day, duration=orb.seconds_per_year)

system = orb.system_from_simulation(sim, time=100 * orb.seconds_per_day)
system = system.add_planet("Mars", parent="Sun")
system.simulate(time_step=orb.seconds_per_day, duration=orb.seconds_per_year).tail()
id mass x y z vx vy vz time
1093 Earth 5.972000e+24 -1.388730e+11 -5.663421e+10 6.462275e+03 10762.545778 -27696.786944 0.000950 31449600.0
1094 Mars 6.417000e+23 -2.404256e+11 6.393378e+10 7.250924e+09 -5319.759672 -21351.592141 -316.354820 31449600.0
1095 Sun 1.989000e+30 -2.997864e+06 -1.175312e+04 -1.921205e+03 -0.117235 0.076908 0.000182 31536000.0
1096 Earth 5.972000e+24 -1.379227e+11 -5.901889e+10 6.543419e+03 11232.915176 -27500.250880 0.000928 31536000.0
1097 Mars 6.417000e+23 -2.408775e+11 6.208694e+10 7.223358e+09 -5140.685794 -21398.480745 -321.740231 31536000.0