<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thank you for the suggestion, but I’m afraid I don’t see how it works.. The given date I have to work from is a date in UTC. By specifying “Time(date, scale=“tai”)” I would be lying to the system: saying the date was TAI when it is UTC. I would expect that to give the wrong answer very near a UTC leap second.<div class=""><br class=""></div><div class="">My code didn’t work at leap second either, but this code does:</div><div class=""><br class=""></div><div class=""><div class="">def tai_from_utc(utc):</div><div class="">    """Return TAI in unix seconds, given UTC in unix seconds.</div><div class="">    """</div><div class="">    astropy_utc = astropy.time.Time(utc, scale="utc", format="unix")</div><div class="">    dt_utc = astropy_utc.utc.to_datetime()</div><div class="">    dt_tai = astropy_utc.tai.to_datetime()</div><div class="">    tai_minus_utc = (dt_tai - dt_utc).total_seconds()</div><div class="">    return utc + tai_minus_utc</div><div class=""><br class=""></div><div class="">It seems quite clumsy to have to use datetime objects *and* astropy. I’d welcome a cleaner solution!</div><div class=""><br class=""></div><div class="">Regards,</div><div class=""><br class=""></div><div class="">Russell<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 24, 2019, at 2:12 PM, Aldcroft, Thomas <<a href="mailto:aldcroft@head.cfa.harvard.edu" class="">aldcroft@head.cfa.harvard.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Russell,<div class=""><br class=""></div><div class="">I think what you want is:</div><div class=""><br class=""></div><div class="">In [1]: from astropy.time import Time</div><div class="">In [2]: date = '2019-08-24 00:00:00'<br class=""></div><div class="">In [3]: dt = Time(date, scale='utc') - Time(date, scale='tai')<br class="">In [4]: dt.sec<br class="">Out[4]: 36.99999999999779<br class=""></div><div class=""><br class=""></div><div class="">- Tom</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 23, 2019 at 6:46 PM Russell Owen <<a href="mailto:rowen@uw.edu" class="">rowen@uw.edu</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We do some work with TAI times as unix seconds. Possibly controversial, but it’s what we use.<br class="">
<br class="">
We sometimes need to convert normal unix times (UTC) to this standard.<br class="">
<br class="">
This naive solution does not work:<br class="">
<br class="">
def bogus_tai_from_utc(utc):<br class="">
    “””Failed attempt to return TAI in unix seconds given UTC in unix seconds.<br class="">
<br class="">
    This fails because given an astropy.time.Time astropy_time:<br class="">
    astropy_time.tai.unix == astropy_time.utc.unix<br class="">
    """<br class="">
    return astropy.time.Time(utc, format=“unix”, scale=“utc”).tai.unix<br class="">
<br class="">
Is there a nice way to ask AstroPy the value of TAI-UTC in seconds, given a UTC?<br class="">
If so, this would be perfect:<br class="">
<br class="">
tai_from_utc(utc):<br class="">
    tai_minus_utc = …? (presently 37 seconds)<br class="">
    return utc + tai_minus_utc<br class="">
<br class="">
The following ugly code works, but has error at the microsecond level and may not work at leap seconds:<br class="">
<br class="">
tai_minus_utc = (astropy_utc.tai.mjd - astropy_utc.utc.mjd)*24*60*60 <br class="">
<br class="">
Regards,<br class="">
<br class="">
Russell<br class="">
_______________________________________________<br class="">
AstroPy mailing list<br class="">
<a href="mailto:AstroPy@python.org" target="_blank" class="">AstroPy@python.org</a><br class="">
<a href="https://mail.python.org/mailman/listinfo/astropy" rel="noreferrer" target="_blank" class="">https://mail.python.org/mailman/listinfo/astropy</a><br class="">
</blockquote></div>
_______________________________________________<br class="">AstroPy mailing list<br class=""><a href="mailto:AstroPy@python.org" class="">AstroPy@python.org</a><br class="">https://mail.python.org/mailman/listinfo/astropy<br class=""></div></blockquote></div><br class=""></div></div></body></html>