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

<pre><code>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
</code></pre>

<p>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:</p>

<pre><code>newton(altitude_of_longitude, 0)
&gt;&gt;&gt; 16.231753986033333
newton(altitude_of_longitude, 180)
&gt;&gt;&gt; 196.23547201834657
</code></pre>

<p>The only remaining part is to check which part is visible:</p>

<pre><code>altaz = Galactic(l=0*u.deg, b=0*u.deg).transform_to(AltAz(location=dwl, obstime=mytime))
altaz.alt
&gt;&gt;&gt; −9°08′51.8623′′
</code></pre>

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

CC BY-SA 3.0
2017-09-16T19:12:28.480Z
2017-09-17T17:09:54.717Z
2017-09-17T17:09:54.717Z
tammojan
<p>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?</p>

<p>(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.)</p>

<milky-way><coordinate><astropy>
Get visible galactic longitudes in astropy
tammojan
# Get visible galactic longitudes in astropy

(Asked by: username_0 on 2017-09-15)

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.)

**Tags:** milky-way, coordinate, astropy


---

## 1 answers

### Answer by username_0 on 2017-09-16. Score: 0 | Accepted answer

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.


---

