Clock Correction Example

The following is an example of using the tempo module of GODOT, optionally with autodif.

To start using tempo, we import the module:

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

Here is a simple class for computing a correction to an epoch. Three coefficients and a reference epoch are provided and the correction is applied as a quadratic. The correction is applied in the time scale of the reference time, so conversions of the input time to, and from that timescale need to be implement.

In [2]:
#
# a class for computing clock corrections based on polynomial
# 
class clockCorrection:

    def __init__( self, tref , a , b , c ) :
        self.tref = tref
        self.a = a
        self.b = b
        self.c = c

    def eval( self, t ) :
        tc = tempo.convert( self.tref.getTimeScale(),t )
        dt = tc - self.tref
        tc += self.a + self.b * dt + self.c * dt * dt
        return tempo.convert( t.getTimeScale(), tc )

Now we use the class to apply a correction, using Epoch and double for the correction coefficients

In [3]:
# compute correction for coefficient values

tdb0 = tempo.Epoch("0.0 TDB")
tai0 = tempo.convert(tempo.TimeScale.TAI,tdb0)
a=1.0e-4
b=1.0e-7
c=1.0e-12
corr = clockCorrection( tai0, a, b, c )
tcorr = corr.eval(tempo.Epoch("1.0 TDB"))
print(tcorr)
2000-01-02T00:00:00.016205 TDB

But, we can also use XEpoch and autodiff Scalar to perform the same computation, this time with gradients:

In [4]:
# compute correction for coefficient values with partials

tdb0 = tempo.XEpoch("0.0 TDB")
tai0 = tempo.convert(tempo.TimeScale.TAI,tdb0)

import godot.core.autodif as ad

a = ad.Scalar(a,"a")
b = ad.Scalar(b,"b")
c = ad.Scalar(c,"c")

corr = clockCorrection( tai0, a, b, c )
tcorr = corr.eval(tempo.XEpoch("1.0 TDB"))
print(tcorr)
                           Value |             a |             b |             c
  2000-01-02T00:00:00.016205 TDB |  1.000000e+00 |  8.640000e+04 |  7.464960e+09