diff --git a/demo/python/astronomy.py b/demo/python/astronomy.py
index baca2cc0..f3778846 100644
--- a/demo/python/astronomy.py
+++ b/demo/python/astronomy.py
@@ -420,6 +420,23 @@ class NoConvergeError(Error):
def __init__(self):
Error.__init__(self, 'Numeric solver did not converge - please report issue at https://github.com/cosinekitty/astronomy/issues')
+def PlanetOrbitalPeriod(body):
+ """Returns the average number of days it takes for a planet to orbit the Sun.
+
+ Parameters
+ ----------
+ body : Body
+ One of the planets: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, or Pluto.
+
+ Returns
+ -------
+ float
+ The mean orbital period of the body in days.
+ """
+ if isinstance(body, Body) and (0 <= body.value < len(_PlanetOrbitalPeriod)):
+ return _PlanetOrbitalPeriod[body.value]
+ raise InvalidBodyError()
+
def _SynodicPeriod(body):
if body == Body.Earth:
raise EarthNotAllowedError()
diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py
index 4125c9e0..2239f8fb 100644
--- a/generate/template/astronomy.py
+++ b/generate/template/astronomy.py
@@ -420,6 +420,23 @@ class NoConvergeError(Error):
def __init__(self):
Error.__init__(self, 'Numeric solver did not converge - please report issue at https://github.com/cosinekitty/astronomy/issues')
+def PlanetOrbitalPeriod(body):
+ """Returns the average number of days it takes for a planet to orbit the Sun.
+
+ Parameters
+ ----------
+ body : Body
+ One of the planets: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, or Pluto.
+
+ Returns
+ -------
+ float
+ The mean orbital period of the body in days.
+ """
+ if isinstance(body, Body) and (0 <= body.value < len(_PlanetOrbitalPeriod)):
+ return _PlanetOrbitalPeriod[body.value]
+ raise InvalidBodyError()
+
def _SynodicPeriod(body):
if body == Body.Earth:
raise EarthNotAllowedError()
diff --git a/generate/test.py b/generate/test.py
index ab6ae1fb..75b8f4fc 100755
--- a/generate/test.py
+++ b/generate/test.py
@@ -1265,24 +1265,12 @@ def Refraction():
#-----------------------------------------------------------------------------------------------------------
-PlanetOrbitalPeriod = {
- astronomy.Body.Mercury: 87.969,
- astronomy.Body.Venus: 224.701,
- astronomy.Body.Earth: 365.256,
- astronomy.Body.Mars: 686.980,
- astronomy.Body.Jupiter: 4332.589,
- astronomy.Body.Saturn: 10759.22,
- astronomy.Body.Uranus: 30685.4,
- astronomy.Body.Neptune: 60189.0,
- astronomy.Body.Pluto: 90560.0
-}
-
def PlanetApsis():
start_time = astronomy.Time.Make(1700, 1, 1, 0, 0, 0)
body = astronomy.Body.Mercury
while body.value <= astronomy.Body.Pluto.value:
count = 1
- period = PlanetOrbitalPeriod[body]
+ period = astronomy.PlanetOrbitalPeriod(body)
filename = os.path.join('apsides', 'apsis_{}.txt'.format(body.value))
min_interval = -1.0
max_diff_days = 0.0
diff --git a/source/python/README.md b/source/python/README.md
index d3012650..663732bb 100644
--- a/source/python/README.md
+++ b/source/python/README.md
@@ -2345,6 +2345,20 @@ A pivoted matrix object.
---
+
+### PlanetOrbitalPeriod(body)
+
+**Returns the average number of days it takes for a planet to orbit the Sun.**
+
+| Type | Parameter | Description |
+| --- | --- | --- |
+| [`Body`](#Body) | `body` | One of the planets: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, or Pluto. |
+
+**Returns**: `float`
+The mean orbital period of the body in days.
+
+---
+
### RefractionAngle(refraction, altitude)
diff --git a/source/python/astronomy/astronomy.py b/source/python/astronomy/astronomy.py
index baca2cc0..f3778846 100644
--- a/source/python/astronomy/astronomy.py
+++ b/source/python/astronomy/astronomy.py
@@ -420,6 +420,23 @@ class NoConvergeError(Error):
def __init__(self):
Error.__init__(self, 'Numeric solver did not converge - please report issue at https://github.com/cosinekitty/astronomy/issues')
+def PlanetOrbitalPeriod(body):
+ """Returns the average number of days it takes for a planet to orbit the Sun.
+
+ Parameters
+ ----------
+ body : Body
+ One of the planets: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, or Pluto.
+
+ Returns
+ -------
+ float
+ The mean orbital period of the body in days.
+ """
+ if isinstance(body, Body) and (0 <= body.value < len(_PlanetOrbitalPeriod)):
+ return _PlanetOrbitalPeriod[body.value]
+ raise InvalidBodyError()
+
def _SynodicPeriod(body):
if body == Body.Earth:
raise EarthNotAllowedError()