AstroDynamics.orbits

Module Contents

Classes

orbit

Numerical techniques for solving the two-body problem.

Functions

return_halley([e, r_aphelion])

Function to return the position and velocity vectors of Halley's comet

_set_style_()

Function to configure the matplotlib.pyplot style. This function is called before any images are saved.

class AstroDynamics.orbits.orbit(M, m, X, x, V, v, dt, tend, integrator, approx=True)[source]

Numerical techniques for solving the two-body problem.

The methods calculate the orbital elements of the system, including the energy and angular momentum at each timestep.

Note: The inputs must be in code units.

Parameters:
  • M (float) – Mass of the star.

  • m (float) – Mass of the planet.

  • X (np.ndarray) – Initial position vector of the star.

  • x (np.ndarray) – Initial position vector of the planet.

  • V (np.ndarray) – Initial velocity vector of the star.

  • v (np.ndarray) – Initial velocity vector of the planet.

  • dt (float) – Timestep to use for the integration.

  • tend (int) – Number of timesteps.

  • integrator (str) – Integrator to use, options include ‘euler’ and …

  • approx (bool) – If True then the acceleration will be calculated using the 1/r^3 approximation in which the unit vector is abosorbed by the denominator. Defaults to True.

integration_time

The integration duration in seconds.

Type:

float

energy

Energy of the system, which should be conserved at all timesteps.

Type:

np.ndarray

energy_error

Energy error of the system.

Type:

np.ndarray

h

Angular momentum of the system, as a function of time.

Type:

np.ndarray

h_error

Angular momentum error of the system, as a function of time.

Type:

np.ndarray

X_vec

X-position of the star as a function of integrated time.

Type:

np.ndarray

Y_vec

Y-position of the star as a function of integrated time.

Type:

np.ndarray

x_vec

X-position of the planet as a function of integrated time.

Type:

np.ndarray

y_vec

Y-position of the planet as a function of integrated time.

Type:

np.ndarray

path

Absolute path to the directory where the images should be saved.

Type:

str

_run_()[source]

Calculates the orbital characteristics.

Parameters:

None

Returns:

None

Raises:

ValueError – If self.integrator is not a string or is not ‘euler’

This method must be called directly if the class parameters are updated after initialization.

euler_integrator()[source]

Executes the Euler integration method and calculates time taken to complete.

Parameters:

None

Returns:

None

Saves time taken to complete in self.integration_time.

runge_kutta_integrator()[source]

Executes the Runge-Kutta integration method and calculates time taken to complete.

Parameters:

None

Returns:

None

Saves time taken to complete in self.integration_time.

leapfrog_integrator()[source]

Executes the leapfrog integration method, also called the Störmer method or the Verlet method.

Parameters:

None

Returns:

None

Saves time taken to complete in self.integration_time.

calc_acceleration(x, X)[source]

Calculates the acceleration of both bodies at a given position.

Parameters:

None

Returns:

Two floats, the acceleration of the planet and the acceleration of the star, respectively.

Return type:

float

calc_energy(Vx, vx, Vy, vy)[source]

Calculates the energy of the two-body system, assuming z-components are zero!

Parameters:
  • Vx (float) – The x-component of the star’s velocity vector.

  • vx (float) – The x-component of the planet’s velocity vector.

  • Vy (float) – The y-component of the star’s velocity vector.

  • vy (float) – The y-component of the planet’s velocity vector.

Returns:

The energy of the two-body system at the input positions.

Return type:

float

calc_com()[source]

Calculates the position vector of the center of mass vector at a given timestep.

Parameters:

None

Returns:

The length of the center of mass position vector.

Return type:

float

calc_comv(Vx, vx, Vy, vy)[source]

Calculates the velocity vector of the center of mass of the two objects.

Parameters:
  • Vx (float) – The x-component of the star’s velocity vector.

  • vx (float) – The x-component of the planet’s velocity vector.

  • Vy (float) – The y-component of the star’s velocity vector.

  • vy (float) – The y-component of the planet’s velocity vector.

Returns:

The velocity of the center of mass.

Return type:

float

calc_momentum(Vx, vx, Vy, vy)[source]

Calculates the angular momentum of the system.

Parameters:
  • vx (float) – The x-component of the planet’s velocity vector.

  • vy (float) – The y-component of the planet’s velocity vector.

Returns:

The angular momentum at the specified timestamp.

Return type:

float

plot_com(savefig=False)[source]

Plots the COM position of the star and the planet’s orbit.

Parameters:

savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.

Returns:

The resulting plot.

Return type:

AxesImage

plot_vcom(savefig=False)[source]

Plots the COM velocity of the star and the planet’s orbit.

Parameters:

savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.

Returns:

The resulting plot.

Return type:

AxesImage

plot_orbit(savefig=False)[source]

Plots the XY position of the star and the planet’s orbit.

Parameters:

savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.

Returns:

The resulting plot.

Return type:

AxesImage

plot_energy(savefig=False)[source]

Plots the energy of the system as a function of the integration timesteps.

Parameters:

savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.

Returns:

The resulting plot.

Return type:

AxesImage

plot_momentum(savefig=False)[source]

Plots the momentum of the system as a function of the integration timesteps.

Parameters:

savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.

Returns:

The resulting plot.

Return type:

AxesImage

AstroDynamics.orbits.return_halley(e=0.967, r_aphelion=1.0)[source]

Function to return the position and velocity vectors of Halley’s comet

Parameters:
  • e (float) – Eccentricity.

  • r_aphelion (float) – Aphelion distance of the comet.

Returns:

Two arrays, the position and velocity vectors (x & y) of the comet, with z=0.

AstroDynamics.orbits._set_style_()[source]

Function to configure the matplotlib.pyplot style. This function is called before any images are saved.