# [AstroPy] How to compute TAI-UTC using Astropy?

Sat Aug 24 17:12:16 EDT 2019

Hi Russell,

I think what you want is:

In [1]: from astropy.time import Time
In [2]: date = '2019-08-24 00:00:00'
In [3]: dt = Time(date, scale='utc') - Time(date, scale='tai')
In [4]: dt.sec
Out[4]: 36.99999999999779

- Tom

On Fri, Aug 23, 2019 at 6:46 PM Russell Owen <rowen at uw.edu> wrote:

> We do some work with TAI times as unix seconds. Possibly controversial,
> but it’s what we use.
>
> We sometimes need to convert normal unix times (UTC) to this standard.
>
> This naive solution does not work:
>
> def bogus_tai_from_utc(utc):
>     “””Failed attempt to return TAI in unix seconds given UTC in unix
> seconds.
>
>     This fails because given an astropy.time.Time astropy_time:
>     astropy_time.tai.unix == astropy_time.utc.unix
>     """
>     return astropy.time.Time(utc, format=“unix”, scale=“utc”).tai.unix
>
> Is there a nice way to ask AstroPy the value of TAI-UTC in seconds, given
> a UTC?
> If so, this would be perfect:
>
> tai_from_utc(utc):
>     tai_minus_utc = …? (presently 37 seconds)
>     return utc + tai_minus_utc
>
> The following ugly code works, but has error at the microsecond level and
> may not work at leap seconds:
>
> tai_minus_utc = (astropy_utc.tai.mjd - astropy_utc.utc.mjd)*24*60*60
>
> Regards,
>
> Russell
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20190824/23ecc96f/attachment.html>