Basic Tempo Examples

To start using tempo, we import the module:

In [1]:
import godot.core.tempo as tempo

Lets construct an Epoch from a string:

In [2]:
epoch = tempo.Epoch("2012-12-23T18:23:23.00 TDB")

There are a few other ways to construct an epoch

In [3]:
# MJD in days
e1 = tempo.Epoch("1020.0 TDB")
# Specify the Julian day type in the string
e2 = tempo.Epoch("1020.0 MJD1950 TDB")
# Integer and float days to be added together
e3 = tempo.Epoch(1,123.234544444,tempo.TimeScale.TDB)
# Integer and float days to be added together with Julian day type
e4 = tempo.Epoch(1,123.342598888,tempo.TimeScale.TDB,tempo.JulianDay.MJD1950)

print(e1)
print(e2)
print(e3)
print(e4)
2002-10-17T00:00:00.000000 TDB
1952-10-17T00:00:00.000000 TDB
2000-05-04T05:37:44.639962 TDB
1950-05-05T08:13:20.543923 TDB

To convert to another time scale is straightforward:

In [4]:
epochTAI = epoch.convertTo(tempo.TimeScale.TAI)

Now we can print out the two epochs

In [5]:
print(epoch)
print(epochTAI)
2012-12-23T18:23:23.000000 TDB
2012-12-23T18:22:50.816306 TAI

or add seconds to the epoch

In [6]:
epoch += 30.0
epochTAI += 30.0

print(epoch)
print(epochTAI)
2012-12-23T18:23:53.000000 TDB
2012-12-23T18:23:20.816306 TAI

or compare epochs - including implicit time scale conversions, for example:

In [7]:
epoch < epochTAI
Out[7]:
True

We can create an epoch range and iterate over a grid of values

In [8]:
rng = tempo.EpochRange(epoch,epoch+360)
for t in rng.createGrid(20.123):
    print(t)
2012-12-23T18:23:53.000000 TDB
2012-12-23T18:24:13.123000 TDB
2012-12-23T18:24:33.246000 TDB
2012-12-23T18:24:53.369000 TDB
2012-12-23T18:25:13.492000 TDB
2012-12-23T18:25:33.615000 TDB
2012-12-23T18:25:53.738000 TDB
2012-12-23T18:26:13.861000 TDB
2012-12-23T18:26:33.984000 TDB
2012-12-23T18:26:54.107000 TDB
2012-12-23T18:27:14.230000 TDB
2012-12-23T18:27:34.353000 TDB
2012-12-23T18:27:54.476000 TDB
2012-12-23T18:28:14.599000 TDB
2012-12-23T18:28:34.722000 TDB
2012-12-23T18:28:54.845000 TDB
2012-12-23T18:29:14.968000 TDB
2012-12-23T18:29:35.091000 TDB
2012-12-23T18:29:53.000000 TDB

And many other things.

We want to look at how to make use of automatic differentiation with times. For that purpose we construct an XEpoch

In [9]:
xepoch = tempo.XEpoch("2012-12-23T18:23:23.00 TDB")

we can also add a delta time in seconds to this, but we need to use an autodiff scalar

In [10]:
import godot.core.autodif as ad

delta = ad.Scalar(30.0,"a")

xepoch += delta

print(xepoch)
                           Value |             a
  2012-12-23T18:23:53.000000 TDB |  1.000000e+00

Note that the time scale conversion does not affect the gradient. This is an intended simplfication in the code

In [11]:
xepochTAI = tempo.convert(tempo.TimeScale.TAI,xepoch)

print(xepochTAI)
                           Value |             a
  2012-12-23T18:23:20.816306 TAI |  1.000000e+00

It is possible to extract the gradient using the gradient function, and to convert to a numpy.ndarray

In [12]:
g = tempo.gradient(xepochTAI)

print(g)

print(g[delta.leaf()])
             a
  1.000000e+00

[1.]