fix utils/index.rst
@@ -16,7 +16,7 @@ Since the various sub-modules of ``gammapy.utils`` are mostly unrelated, they
are not imported into the top-level namespace. Here are some examples of how to
import functionality from the ``gammapy.utils`` sub-modules:
-.. code-block:: python
+.. testcode::
from gammapy.utils.random import sample_sphere
sample_sphere(size=10)
@@ -36,11 +36,10 @@ Time format and scale
In Gammapy, `astropy.time.Time` objects are used to represent times:
-.. code-block:: python
+.. testcode::
- >>> from astropy.time import Time
- >>> Time(['1999-01-01T00:00:00.123456789', '2010-01-01T00:00:00'])
- <Time object: scale='utc' format='isot' value=['1999-01-01T00:00:00.123' '2010-01-01T00:00:00.000']>
+ from astropy.time import Time
+ Time(['1999-01-01T00:00:00.123456789', '2010-01-01T00:00:00'])
Note that Astropy chose ``format='isot'`` and ``scale='utc'`` as default and in
Gammapy these are also the recommended format and time scale.
@@ -61,14 +60,18 @@ E.g. sometimes in astronomy the modified Julian date ``mjd`` is used and for
passing times to matplotlib for plotting the ``plot_date`` format should be
used:
-.. code-block:: python
+.. testcode::
+
+ from astropy.time import Time
+ time = Time(['1999-01-01T00:00:00.123456789', '2010-01-01T00:00:00'])
+ print(time.mjd)
+ print(time.plot_date)
+
+.. testoutput::
+
+ [51179.00000143 55197. ]
+ [729755.00000143 733773. ]
- >>> from astropy.time import Time
- >>> time = Time(['1999-01-01T00:00:00.123456789', '2010-01-01T00:00:00'])
- >>> time.mjd
- array([51179.00000143, 55197. ])
- >>> time.plot_date
- array([10592.00000143, 14610. ])
Converting to other time scales is also easy, see the :ref:`time scale section,
diagram and table in the Astropy docs <astropy:time-scale>`.
