<p>I know you said no third-party libraries, but I thought I would throw out an example using Astropy in case the default ephemeris was small enough to fit on your disk.</p>
<p>This example is copy-pasted from the <a href="https://docs.astropy.org/en/stable/coordinates/satellites.html" rel="nofollow noreferrer">Working with Earth Satellites Using Astropy Coordinates</a> tutorial.</p>
<pre><code>from sgp4.api import Satrec
from sgp4.api import SGP4_ERRORS
from astropy import units as u
import astropy.time
import astropy.coordinates

# create representation of satellite trajectory
s = '1 25544U 98067A   19343.69339541  .00001764  00000-0  38792-4 0  9991'
t = '2 25544  51.6439 211.2001 0007417  17.6667  85.6398 15.50103472202482'
satellite = Satrec.twoline2rv(s, t)

# time of observation
t = astropy.time.Time(2458827.362605, format='jd')

# create TEME reference frame
error_code, teme_p, teme_v = satellite.sgp4(t.jd1, t.jd2)  # in km and km/s
if error_code != 0:
    raise RuntimeError(SGP4_ERRORS[error_code])
teme_p = astropy.coordinates.CartesianRepresentation(teme_p*u.km)
teme_v = astropy.coordinates.CartesianDifferential(teme_v*u.km/u.s)
teme = astropy.coordinates.TEME(teme_p.with_differentials(teme_v), obstime=t)

# convert TEME frame to alt-az coordinate frame
location = astropy.coordinates.EarthLocation(lat=45 * u.deg, lon=111 * u.deg, height=1400 * u.m)
itrs_geo = teme.transform_to(astropy.coordinates.ITRS(obstime=t))
topo_itrs_repr = itrs_geo.cartesian.without_differentials() - location.get_itrs(t).cartesian
itrs_topo = astropy.coordinates.ITRS(topo_itrs_repr, obstime = t, location=location)
altaz = itrs_topo.transform_to(astropy.coordinates.AltAz(obstime=t, location=location))

print(altaz.alt.deg, altaz.az.deg)
</code></pre>
<p>which prints</p>
<pre><code>-39.353354041509576 135.79128441980257
</code></pre>

CC BY-SA 4.0
2023-08-28T22:55:29.257Z
@GregMiller, that's weird, it works on my machine and Google Colab, what version of astropy do you have installed? I see that you're still using Python 3.7 which is not supported by recent versions of astropy.
Roy Smart
CC BY-SA 4.0
2023-08-29T07:50:15.770Z
Thanks, it works. And astropy only weighs around 40mb, maybe I could move some stuff around. I'm gonna leave the question open for some more time tho, maybe someone know how to do this using only Erfa and some math-magic.
jlipinski
CC BY-SA 4.0
2023-08-28T17:58:38.760Z
2023-08-28T17:58:38.760Z
Roy Smart
<p>I have TEME coordinates from sgp4 propagation. I can convert those (in python) to ITRF given date and time of observation. How to convert coordinates from one of those two frames to horizontal azimuth and altitude frame given latitude, longitude and elevation of observer?
Preferably I don't want to use (unless I have to) any other third-party  libraries (except sgp4 and pyErfa) as I am really short on disk space for this project. I've tried using skyfield but every tutorial I've found is using somewhat heavy <code>de421.bsp</code> ephemeris file which is kinda slow to load and takes too much space for my use case.</p>

CC BY-SA 4.0
2023-08-28T21:32:51.153Z
The community developed libraries at Celestrak.org have a "rv2razel" to compute az/el.  See link below.  Also, it's possible to modify the .bsp kernels, so if you only need data for a certain time period (like 20 years), you can create a new kernel with only the data you need.

http://celestrak.org/software/vallado-sw.php
Greg Miller
<orbital-mechanics><celestial-mechanics><frame-of-reference>
How to convert TEME (or ITRF) to horizontal
jlipinski
# How to convert TEME (or ITRF) to horizontal

(Asked by: username_0 on 2023-08-28)

I have TEME coordinates from sgp4 propagation. I can convert those (in python) to ITRF given date and time of observation. How to convert coordinates from one of those two frames to horizontal azimuth and altitude frame given latitude, longitude and elevation of observer?
Preferably I don't want to use (unless I have to) any other third-party libraries (except sgp4 and pyErfa) as I am really short on disk space for this project. I've tried using skyfield but every tutorial I've found is using somewhat heavy `de421.bsp` ephemeris file which is kinda slow to load and takes too much space for my use case.

**Tags:** orbital-mechanics, celestial-mechanics, frame-of-reference

> **Comments:**
> **username_1**: The community developed libraries at Celestrak.org have a "rv2razel" to compute az/el.  See link below.  Also, it's possible to modify the .bsp kernels, so if you only need data for a certain time period (like 20 years), you can create a new kernel with only the data you need.  http://celestrak.org/software/vallado-sw.php  

---

## 1 answers

### Answer by username_2 on 2023-08-28. Score: 2 | Accepted answer

I know you said no third-party libraries, but I thought I would throw out an example using Astropy in case the default ephemeris was small enough to fit on your disk.

This example is copy-pasted from the [Working with Earth Satellites Using Astropy Coordinates](https://docs.astropy.org/en/stable/coordinates/satellites.html) tutorial.

```
from sgp4.api import Satrec
from sgp4.api import SGP4_ERRORS
from astropy import units as u
import astropy.time
import astropy.coordinates

# create representation of satellite trajectory
s = '1 25544U 98067A   19343.69339541  .00001764  00000-0  38792-4 0  9991'
t = '2 25544  51.6439 211.2001 0007417  17.6667  85.6398 15.50103472202482'
satellite = Satrec.twoline2rv(s, t)

# time of observation
t = astropy.time.Time(2458827.362605, format='jd')

# create TEME reference frame
error_code, teme_p, teme_v = satellite.sgp4(t.jd1, t.jd2)  # in km and km/s
if error_code != 0:
    raise RuntimeError(SGP4_ERRORS[error_code])
teme_p = astropy.coordinates.CartesianRepresentation(teme_p*u.km)
teme_v = astropy.coordinates.CartesianDifferential(teme_v*u.km/u.s)
teme = astropy.coordinates.TEME(teme_p.with_differentials(teme_v), obstime=t)

# convert TEME frame to alt-az coordinate frame
location = astropy.coordinates.EarthLocation(lat=45 * u.deg, lon=111 * u.deg, height=1400 * u.m)
itrs_geo = teme.transform_to(astropy.coordinates.ITRS(obstime=t))
topo_itrs_repr = itrs_geo.cartesian.without_differentials() - location.get_itrs(t).cartesian
itrs_topo = astropy.coordinates.ITRS(topo_itrs_repr, obstime = t, location=location)
altaz = itrs_topo.transform_to(astropy.coordinates.AltAz(obstime=t, location=location))

print(altaz.alt.deg, altaz.az.deg)

```

which prints

```
-39.353354041509576 135.79128441980257

```

> **Comments:**
> **username_2**: @username_1, that's weird, it works on my machine and Google Colab, what version of astropy do you have installed? I see that you're still using Python 3.7 which is not supported by recent versions of astropy.  
> **username_0**: Thanks, it works. And astropy only weighs around 40mb, maybe I could move some stuff around. I'm gonna leave the question open for some more time tho, maybe someone know how to do this using only Erfa and some math-magic.  

---

