Search code examples
pythoncoordinate-transformationastronomypyephem

How to compute (alt, az) for given Galactic coordinate (GLON, GLAT) with PyEphem?


For a given observer (lon, lat, time) on Earth and a given Galactic coordinate (GLON, GLAT), how can I compute the corresponding (alt, az) point in the sky with PyEphem?


Solution

  • Given the way that PyEphem currently works, there are two steps to answering your question. First, you have to convert a pair of galactic coordinates into an equatorial RA/dec pair of coordinates instead.

    import ephem
    
    # Convert a Galactic coordinate to RA and dec                          
    
    galactic_center = ephem.Galactic(0, 0)
    eq = ephem.Equatorial(galactic_center)
    print 'RA:', eq.ra, 'dec:', eq.dec
    
    → RA: 17:45:37.20 dec: -28:56:10.2
    

    Those coordinates are pretty close to the ones that the Wikipedia gives for the galactic center.

    Now that we have a normal RA/dec coordinate, we just need to figure out where it is in the sky right now. Since PyEphem is built atop a library that knows only about celestial “bodies” like stars and planets, we simply need to create a fake “star” at that location and ask its azimuth and altitude.

    # So where is that RA and dec above Boston?
    # Pretend that a star or other fixed body is there.
    
    body = ephem.FixedBody()
    body._ra = eq.ra
    body._dec = eq.dec
    body._epoch = eq.epoch
    
    obs = ephem.city('Boston')
    obs.date = '2012/6/24 02:00' # 10pm EDT
    body.compute(obs)
    print 'Az:', body.az, 'Alt:', body.alt
    
    → Az: 149:07:25.6 Alt: 11:48:43.0
    

    And we can check that this answer is reasonable by looking at a sky chart for Boston late that evening: Sagittarius — the location of the Galactic Center — is just rising over the southeastern rim of the sky, which makes perfect sense of a southeast azimuth like 149°, and for an as-yet low altitude like 11°.