This repository has been archived by the owner on Oct 14, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 276
/
bodies.py
63 lines (44 loc) · 1.48 KB
/
bodies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# coding: utf-8
"""Bodies of the Solar System.
Contains some predefined bodies of the Solar System:
* Sun (☉)
* Earth (♁)
and a way to define new bodies (:py:class:`~Body` class).
TODO: Add more parameters (e.g. J2)
"""
from astropy.constants import R_earth
from astropy import units as u
from poliastro.util import check_units
class Body(object):
"""Class to represent a body of the Solar System.
"""
def __init__(self, k, name=None, symbol=None, R=0 * u.km):
"""Constructor.
Parameters
----------
k : Quantity
Standard gravitational parameter
name : str, optional
Name of the body, default to None.
symbol : str, optional
Symbol for the body, default to None.
R : Quantity, optional
Radius of the body, default to 0 km.
"""
if not check_units((k, R), (u.m ** 3 / u.s ** 2, u.m)):
raise u.UnitsError("Units must be consistent")
self.k = k
self.name = name
self.symbol = symbol
self.R = R
def __str__(self):
return u"{} ({})".format(self.name, self.symbol)
def _repr_latex_(self):
"""Creates a LaTeX representation.
Used by the IPython notebook.
"""
return self.__str__()
Sun = Body(k=132712440018 * u.km ** 3 / u.s ** 2,
name="Sun", symbol=u"\u2609")
Earth = Body(k=398600 * u.km ** 3 / u.s ** 2,
name="Earth", symbol=u"\u2641", R=R_earth)