Skip to main content

export_bodies

export_bodies(system, path)

Export the body table of a system to a CSV file.

Writes one row per body with its name, mass, position and velocity. A CSV file opens in a spreadsheet or any other tool, which makes this the way to take a system’s starting state out of Python. The gravitational constant is not written, so to save a system you intend to load again, use save_system(). Also available as the chained method system.export_bodies(path).

Parameters

Name Type Description Default
system OrbitSystem The system whose bodies to export. required
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, unchanged, so the call can sit in the middle of a chain.

Raises

Name Type Description
TypeError If system is not an OrbitSystem.

See Also

Notes

The file has a header row, id,mass,x,y,z,vx,vy,vz, and no index column. Mass is in kilograms, positions in meters and velocities in meters per second.

Examples

import os
import tempfile

import pyorbiter as orb

system = orb.create_system().add_sun().add_planet("Earth", parent="Sun")

with tempfile.TemporaryDirectory() as folder:
    path = os.path.join(folder, "bodies.csv")
    orb.export_bodies(system, path)
    with open(path) as fh:
        text = fh.read()

print(text)
id,mass,x,y,z,vx,vy,vz
Sun,1.989e+30,0.0,0.0,0.0,0.0,0.0,0.0
Earth,5.972e+24,-32965585120.94338,143360295955.52682,0.0,-29520.18705135016,-6788.143345695552,0.0