Repository: poliastro/poliastro

Issue:
Add warning if input time for ephemeris is not TDB
Those users that want utter precision might want to check against HORIZONS or SPICE. These systems use TDB as their input, so in the absence of time scale an implicit conversion is made, which makes use of the "wrong" time:

https://space.stackexchange.com/q/22901

Example code:

```
In [17]: EPOCH = Time("2017-09-01 12:05:50")

In [18]: Orbit.from_body_ephem(Venus, EPOCH)
Out[18]: 1 x 1 AU x 24.4 deg orbit around Sun (☉)

In [19]: _.epoch
Out[19]: <Time object: scale='utc' format='iso' value=2017-09-01 12:05:50.000>

In [20]: _.tdb
Out[20]: <Time object: scale='tdb' format='iso' value=2017-09-01 12:06:59.183>

In [21]: _19 == _20
Out[21]: True
```

I would raise a warning if the input scale is not TDB to avoid this confusion, and also set the epoch to TDB to signal this fact. Thoughts? @poliastro/development 


Comments:

Patch:
diff --git a/src/poliastro/ephem.py b/src/poliastro/ephem.py
index e24aebfc..279d0952 100644
--- a/src/poliastro/ephem.py
+++ b/src/poliastro/ephem.py
@@ -6,6 +6,10 @@ from astropy import units as u
 from astropy.coordinates import get_body_barycentric_posvel
 
 
+class TimeScaleWarning(UserWarning):
+    pass
+
+
 def get_body_ephem(body, epoch):
     """Position and velocity vectors of a given body at a certain time.
 
diff --git a/src/poliastro/twobody/orbit.py b/src/poliastro/twobody/orbit.py
index 0bb0a2f7..daef456f 100644
--- a/src/poliastro/twobody/orbit.py
+++ b/src/poliastro/twobody/orbit.py
@@ -1,5 +1,4 @@
-# coding: utf-8
-from datetime import datetime
+from warnings import warn
 
 import numpy as np
 
@@ -8,7 +7,7 @@ from astropy import units as u
 from astropy import time
 
 from poliastro.constants import J2000
-from poliastro.ephem import get_body_ephem
+from poliastro.ephem import get_body_ephem, TimeScaleWarning
 from poliastro.twobody.propagation import propagate
 
 import poliastro.twobody.rv
@@ -125,7 +124,12 @@ class Orbit(object):
 
         """
         if not epoch:
-            epoch = time.Time.now()
+            epoch = time.Time.now().tdb
+        elif epoch.scale != 'tdb':
+            epoch = epoch.tdb
+            warn("Input time was converted to scale='tdb' with value "
+                 "{}. Use Time(..., scale='tdb') instead."
+                 .format(epoch.tdb.value), TimeScaleWarning)
 
         r, v = get_body_ephem(body.name, epoch)
         return cls.from_vectors(body.parent, r, v, epoch)


Test patch:
diff --git a/src/poliastro/tests/tests_twobody/test_orbit.py b/src/poliastro/tests/tests_twobody/test_orbit.py
index c818a5a3..c58ff2ca 100644
--- a/src/poliastro/tests/tests_twobody/test_orbit.py
+++ b/src/poliastro/tests/tests_twobody/test_orbit.py
@@ -1,4 +1,3 @@
-# coding: utf-8
 import pytest
 
 from numpy.testing import assert_allclose
@@ -9,6 +8,7 @@ from astropy.tests.helper import assert_quantity_allclose
 from astropy import time
 
 from poliastro.bodies import Sun, Earth
+from poliastro.ephem import TimeScaleWarning
 from poliastro.twobody import Orbit
 from poliastro.constants import J2000
 
@@ -85,6 +85,17 @@ def test_orbit_from_ephem_with_no_epoch_is_today():
     assert (time.Time.now() - ss.epoch).sec < 1
 
 
+def test_from_ephem_raises_warning_if_time_is_not_tdb_with_proper_time(recwarn):
+    body = Earth
+    epoch = time.Time("2017-09-29 07:31:26", scale="utc")
+    expected_epoch_string = "2017-09-29 07:32:35.182"  # epoch.tdb.value
+
+    Orbit.from_body_ephem(body, epoch)
+
+    w = recwarn.pop(TimeScaleWarning)
+    assert expected_epoch_string in str(w.message)
+
+
 def test_circular_has_proper_semimajor_axis():
     alt = 500 * u.km
     attractor = Earth