# Get visible galactic longitudes in astropy

I would like to know which part of the Milky Way is currently up. Preferably using astropy. The ingredients I have are the current time, and my current position on earth. How would I use these to get the minimal and maximal galactic longitude currently up?

(I know how to convert from Alt-Az to Galactic coordinates, but I don't know at which azimuth the galactic plane crosses the horizon at altitude=0.)

The following works for me; it uses the rootfinder from scipy to find the zero.

from astropy.coordinates import EarthLocation, AltAz, Galactic
from astropy.time import Time
from scipy.optimize import newton
import astropy.units as u

dwl = EarthLocation(lat=6.39688*u.deg, lon=52.6275*u.deg)
mytime = Time('2017-09-16T21:00:00')

def altitude_of_longitude(longitude):
''' Give the altitude (in deg) of a galactic longitude (in deg) '''
return Galactic(l=longitude*u.deg, b=0*u.deg).transform_to(
AltAz(location=dwl, obstime=mytime)).alt.value


Now use the rootfinder from scipy, with two different initial guesses, hoping that they end up at the two different solutions where the galactic plane crosses the horizon. This gives:

newton(altitude_of_longitude, 0)
>>> 16.231753986033333
newton(altitude_of_longitude, 180)
>>> 196.23547201834657


The only remaining part is to check which part is visible:

altaz = Galactic(l=0*u.deg, b=0*u.deg).transform_to(AltAz(location=dwl, obstime=mytime))
altaz.alt
>>> −9°08′51.8623′′


Apparently the longitude at 0° is under (negative altitude), so the visible part is between 16° and 196° galactic longitude.