Skip to main content

load_system

load_system(path)

Load a system from a JSON file.

Reads a file written by save_system() and rebuilds the system: the same gravitational constant and the same bodies, in the same order, with the same masses, positions and velocities.

Parameters

Name Type Description Default
path str or path - like The file to read. required

Returns

Name Type Description
OrbitSystem The saved system.

Raises

Name Type Description
FileNotFoundError If there is no file at path.
ValueError If the file is JSON but was not written by save_system().

See Also

Examples

import os
import tempfile

import pyorbiter as orb

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

with tempfile.TemporaryDirectory() as folder:
    path = os.path.join(folder, "mars.json")
    system.save(path)
    restored = orb.load_system(path)

restored.bodies.equals(system.bodies)
True