<p>Astropy actually has a <a href="https://docs.astropy.org/en/stable/time/#:%7E:text=date%2C%20longdate_hms%2C%20longdate-,gps,-float%2C%20long%2C%20decimal" rel="nofollow noreferrer">GPS format</a> that takes the time since the GPS epoch as an argument.</p>
<p>Also, I would recommend using <a href="https://docs.astropy.org/en/stable/units/" rel="nofollow noreferrer"><code>astropy.units</code></a> to simplify the conversions.</p>
<p>Using these suggestions, your code can be simplified to:</p>
<pre><code>import astropy.units as u
from astropy.time import Time

def gps_week_tow_to_j2000(gps_week, gps_tow):
  j2000_epoch = Time('2000-01-01T12:00:00', scale='tt')
  t = (gps_week * u.wk) + (gps_tow * u.s)
  gps_time = Time(t, format=&quot;gps&quot;)
  timedelta = (gps_time - j2000_epoch)
  return timedelta.sec

gps_week = 2304 
gps_tow = 308536.998852
j2000_seconds = gps_week_tow_to_j2000(gps_week, gps_tow)
print(f&quot;J2000 seconds: {j2000_seconds}&quot;)
</code></pre>
<pre><code>J2000 seconds: 763004588.182852
</code></pre>
<p>I think this is different than your code since the line</p>
<pre><code>gps_time = Time(gps_epoch.utc.jd + time_since_gps_epoch/86400, format='jd', scale='utc')
</code></pre>
<p>should actually be something like</p>
<pre><code>gps_time = Time(gps_epoch.tai.jd + time_since_gps_epoch/86400, format='jd', scale='tai')
</code></pre>
<p>since the UTC timescale takes into account leap seconds, which is probably not what you want.</p>

CC BY-SA 4.0
2024-04-12T23:24:34.430Z
2024-04-12T23:33:11.330Z
2024-04-12T23:33:11.330Z
Roy Smart
<p>I'm new to this, and am trying to convert GPS Time to J2000 time using python and Astropy. Here's what I've come up with:</p>
<pre><code>def gps_week_tow_to_j2000(gps_week, gps_tow):
    gps_epoch = Time('1980-01-06T00:00:00', scale='utc') # GPS Epoch, scale UTC, since UTC = GPS Epoch on 1980-01-06T00:00:00
    j2000_epoch = Time('2000-01-01T12:00:00', scale='tt') # Getting J2000.0 Epoch, scale Terrestrial Time. https://aa.usno.navy.mil/faq/TT#:~:text=The%20epoch%20designated%20%22J2000.,11%3A58%3A55.816%20UTC.
    
    # Since gps_week is counter from gps_epoch, we'll convert it to seconds, and add the time_of_week to it.
    time_since_gps_epoch = gps_week * 7 * 24 * 3600 + gps_tow # Seconds since GPS Epoch in UTC.
    # to get the GPS Time
    gps_time = Time(gps_epoch.utc.jd + time_since_gps_epoch/86400, format='jd', scale='utc') # Time as per GPS, in UTC, format=JD.
    
    j2000_in_seconds = (gps_time - j2000_epoch).sec
    return j2000_in_seconds

gps_week = 2304 
gps_tow = 308536.998852
j2000_seconds = gps_week_tow_to_j2000(gps_week, gps_tow)
print(f&quot;J2000 seconds: {j2000_seconds}&quot;)

</code></pre>
<p>Result is <code>763004606.1828591</code>. Is this accurate?</p>

<time><astropy>
Convert GPS Week and GPS Time of Week to J2000?
AGS
# Convert GPS Week and GPS Time of Week to J2000?

(Asked by: username_0 on 2024-04-12)

I'm new to this, and am trying to convert GPS Time to J2000 time using python and Astropy. Here's what I've come up with:

```
def gps_week_tow_to_j2000(gps_week, gps_tow):
    gps_epoch = Time('1980-01-06T00:00:00', scale='utc') # GPS Epoch, scale UTC, since UTC = GPS Epoch on 1980-01-06T00:00:00
    j2000_epoch = Time('2000-01-01T12:00:00', scale='tt') # Getting J2000.0 Epoch, scale Terrestrial Time. https://aa.usno.navy.mil/faq/TT#:~:text=The%20epoch%20designated%20%22J2000.,11%3A58%3A55.816%20UTC.
    
    # Since gps_week is counter from gps_epoch, we'll convert it to seconds, and add the time_of_week to it.
    time_since_gps_epoch = gps_week * 7 * 24 * 3600 + gps_tow # Seconds since GPS Epoch in UTC.
    # to get the GPS Time
    gps_time = Time(gps_epoch.utc.jd + time_since_gps_epoch/86400, format='jd', scale='utc') # Time as per GPS, in UTC, format=JD.
    
    j2000_in_seconds = (gps_time - j2000_epoch).sec
    return j2000_in_seconds

gps_week = 2304 
gps_tow = 308536.998852
j2000_seconds = gps_week_tow_to_j2000(gps_week, gps_tow)
print(f"J2000 seconds: {j2000_seconds}")

```

Result is `763004606.1828591`. Is this accurate?

**Tags:** time, astropy


---

## 1 answers

### Answer by username_1 on 2024-04-12. Score: 1 | Accepted answer

Astropy actually has a [GPS format](https://docs.astropy.org/en/stable/time/#:%7E:text=date%2C%20longdate_hms%2C%20longdate-,gps,-float%2C%20long%2C%20decimal) that takes the time since the GPS epoch as an argument.

Also, I would recommend using [`astropy.units`](https://docs.astropy.org/en/stable/units/) to simplify the conversions.

Using these suggestions, your code can be simplified to:

```
import astropy.units as u
from astropy.time import Time

def gps_week_tow_to_j2000(gps_week, gps_tow):
  j2000_epoch = Time('2000-01-01T12:00:00', scale='tt')
  t = (gps_week * u.wk) + (gps_tow * u.s)
  gps_time = Time(t, format="gps")
  timedelta = (gps_time - j2000_epoch)
  return timedelta.sec

gps_week = 2304 
gps_tow = 308536.998852
j2000_seconds = gps_week_tow_to_j2000(gps_week, gps_tow)
print(f"J2000 seconds: {j2000_seconds}")

```

```
J2000 seconds: 763004588.182852

```

I think this is different than your code since the line

```
gps_time = Time(gps_epoch.utc.jd + time_since_gps_epoch/86400, format='jd', scale='utc')

```

should actually be something like

```
gps_time = Time(gps_epoch.tai.jd + time_since_gps_epoch/86400, format='jd', scale='tai')

```

since the UTC timescale takes into account leap seconds, which is probably not what you want.


---

