Skip to main content

OrbitSystem.get_bodies

get_bodies(backend=None)

Get the body table of a system as a DataFrame.

Returns the current state of every body: its name, mass, position and velocity. Use it to inspect a system before simulating, or to pull the starting state into your own analysis. The table is a copy, so editing it does not change the system. Also available as orb.get_bodies(system, ...).

Parameters

Name Type Description Default
backend str The kind of DataFrame to return: "pandas" or "polars". The default, None, uses the backend chosen with set_backend(), which is pandas unless you changed it. None

Returns

Name Type Description
DataFrame A pandas DataFrame by default, or a polars DataFrame. One row per body, in the order the bodies were added, with columns:
• id: the body’s name.
• mass: mass in kilograms.
• x, y, z: position in meters.
• vx, vy, vz: velocity in meters per second. An empty system gives a table with these columns and no rows.

Raises

Name Type Description
ValueError If backend is not "pandas" or "polars".
ImportError If backend is "polars" and polars is not installed.

See Also

  • OrbitSystem.bodies: The same table as a property.
  • set_backend: Choose pandas or polars for the whole session.
  • export_bodies: Write the body table to a CSV file.

Examples

import pyorbiter as orb

system = (
    orb.create_system()
    .add_sun()
    .add_planet("Earth", parent="Sun")
    .add_planet("Mars", parent="Sun")
)
system.get_bodies()
id mass x y z vx vy vz
0 Sun 1.989000e+30 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 0.000000 0.000000
1 Earth 5.972000e+24 -3.296559e+10 1.433603e+11 0.000000e+00 -29520.187051 -6788.143346 0.000000
2 Mars 6.417000e+23 1.887900e+11 -8.370696e+10 -6.395443e+09 10749.771467 24226.116460 243.021783

Ask for polars for a single call.

import pyorbiter as orb

system = orb.create_system().add_sun().add_planet("Earth", parent="Sun")
system.get_bodies(backend="polars")
shape: (2, 8)
id mass x y z vx vy vz
str f64 f64 f64 f64 f64 f64 f64
"Sun" 1.9890e30 0.0 0.0 0.0 0.0 0.0 0.0
"Earth" 5.9720e24 -3.2966e10 1.4336e11 0.0 -29520.187051 -6788.143346 0.0