A set of bodies and the gravitational constant that binds them.
An OrbitSystem holds the starting state of a simulation: a table with one row per body (name, mass, position, velocity) and the value of G. You normally start one with create_system() rather than calling the class directly, then build it up with the add_* methods.
A system is never changed in place. Every add_* method and remove_body returns a new system and leaves the original untouched, so calls chain with dots, from an empty system through to a finished simulation. Printing a system shows G and the body table.
Parameters
Name
Type
Description
Default
G
float
The gravitational constant in m^3 kg^-1 s^-2. The default is the measured value, orb.gravitational_constant (6.6743e-11). Use G=0 to turn gravity off.
gravitational_constant
bodies
DataFrame
A body table with columns id, mass, x, y, z, vx, vy, vz (pandas or polars). The default, None, starts the system with no bodies. You rarely need this: add bodies with the methods instead, which validate their input.
None
Attributes
Name
Type
Description
G
float
The gravitational constant the system was created with.
bodies
DataFrame
The body table, one row per body, with columns id, mass, x, y, z, vx, vy, vz. A copy; the same as get_bodies() with no arguments.
The chained form of simulate_system(), which has the full description of each argument and of the integration methods.
Parameters
Name
Type
Description
Default
time_step
float
Seconds between recorded states. Default one hour (orb.seconds_per_hour).
seconds_per_hour
duration
float
Total simulated time in seconds. Default one year (orb.seconds_per_year).
seconds_per_year
method
str
The integrator: "verlet" (the default), "euler_cromer" or "euler".
'verlet'
softening
float
Softening length in meters. Default 0, which is plain Newtonian gravity.
0
backend
str
"pandas" or "polars". The default, None, uses the backend chosen with set_backend().
None
Returns
Name
Type
Description
DataFrame
A pandas DataFrame by default, or a polars DataFrame. One row per body per recorded time, with columns id, mass (kg), x, y, z (m), vx, vy, vz (m/s) and time (s).
See Also
simulate_system: The same thing as a function, documented in full.
run_settings: Read back the settings a simulation was run with.
import osimport tempfileimport pyorbiter as orbwith tempfile.TemporaryDirectory() as folder: path = os.path.join(folder, "earth.json") orb.create_system().add_sun().add_planet("Earth", parent="Sun").save(path) restored = orb.load_system(path)restored
───────────────────────────────── orbit_system ─────────────────────────────────
G: 6.6743e-11 (standard)
Bodies: 2
id mass x y z vx vy vz
Sun 1.989000e+30 0.000000e+00 0.000000e+00 0.0 0.000000 0.000000 0.0
Earth 5.972000e+24 -3.296559e+10 1.433603e+11 0.0 -29520.187051 -6788.143346 0.0
export_bodies
export_bodies(path)
Write the body table to a CSV file.
The chained form of export_bodies().
Parameters
Name
Type
Description
Default
path
str or path - like
The CSV file to write. It is overwritten if it exists.
required
Returns
Name
Type
Description
OrbitSystem
The same system, so the chain can continue.
See Also
export_bodies: The same thing as a function, documented in full.
OrbitSystem.save: Save the whole system, including G.
Examples
import osimport tempfileimport pyorbiter as orbwith tempfile.TemporaryDirectory() as folder: path = os.path.join(folder, "bodies.csv") orb.create_system().add_sun().add_planet("Earth", parent="Sun").export_bodies(path)withopen(path) as fh: text = fh.read()print(text)