<p>Applying spherical trigonometry, it follows that the conversion from equatorial coordinates <span class="math-container">$\alpha$</span> and <span class="math-container">$\delta$</span> to galactic coordinates <span class="math-container">$l$</span> and <span class="math-container">$b$</span> is:</p>
<p><span class="math-container">$$\left.
\begin{aligned}
\sin b &amp;=\sin \delta_{NGP} \sin \delta + \cos \delta_{NGP} \cos \delta \cos ( \alpha - \alpha_{NGP}) \\
\sin ( l_{NCP}-l) &amp;=\dfrac{\cos \delta \sin ( \alpha - \alpha_{NGP})}{\cos b} \\
\cos ( l_{NCP}-l) &amp;=\dfrac{\cos \delta_{NGP}\sin \delta - \sin \delta_{NGP} \cos \delta \cos ( \alpha - \alpha_{NGP})}{\cos b}
\end{aligned}
\right \}$$</span></p>
<p>The equatorial coordinates (<strong>J2000</strong>) of the North Galactic Pole are:</p>
<p><span class="math-container">$\alpha_{NGP}=12^h 51^m 26.282^s=192.8595º=3.36603 \ rad$</span></p>
<p><span class="math-container">$\delta_{NGP}=+27º 07’ 42.01’’=27.1283º=0.473479 \ rad$</span></p>
<p>And the galactic longitude of the North Celestial Pole is:</p>
<p><span class="math-container">$l_{NCP}=122.932º=2.14557 \ rad$</span></p>
<p>You can check if your code gives the same results as these equations.</p>
<p>Best regards.</p>
<p><strong>PD.</strong> For your example:</p>
<p><span class="math-container">$\alpha = 21^h \ 33^m \ 56.568^s$</span></p>
<p><span class="math-container">$\delta = +04^{\circ} \ 29' \ 07.84''$</span></p>
<p>The equations give as a result:</p>
<p><span class="math-container">$l = 58.720766^{\circ}$</span></p>
<p><span class="math-container">$b = -32.823544^{\circ}$</span></p>

CC BY-SA 4.0
2024-02-19T16:27:40.830Z
Thanks, that is a much simpler way to show the work than what I've been finding online
Alyssa Galicia
CC BY-SA 4.0
2024-02-19T07:01:20.183Z
2024-02-19T12:06:25.827Z
2024-02-19T12:06:25.827Z
Albert
<p><a href="https://i.sstatic.net/Dkvea.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Dkvea.png" alt="Format of RA/DEC that I am working with" /></a></p>
<p>Hello, I am collecting some data and need to convert some units, so I built a small script to convert RA/DEC to galactic coordinates. The data has specifically formatted the coordinates as shown in the photo. I have an example in the code, but I don't really have anything to compare my answer to so I don't even know if it is correct. I don't really have familiarity with this so please let me know if I am overlooking something! Here is the code:</p>
<pre><code>from astropy import units as u
from astropy.coordinates import SkyCoord

ra=&quot;21:33:56.568&quot;
dec=&quot;+04:29:07.84&quot;


#The following function takes str arguments for ra and dec measured as formatted in the TNS #data, and outputs galactic coordinates l and b (l,b)

def ICRStoGal(ra,dec):
    
    coord = ra + dec

    c_icrs = SkyCoord((coord), unit=(u.hourangle, u.deg))

    c_gal =c_icrs.galactic
    l,b=c_gal.l.degree, c_gal.b.degree
    return l,b

ICRStoGal(ra,dec)[0]

</code></pre>
<p>As an output to this, I got (58.720664132924085, -32.823605289663924). Or, if anyone has any practice problems with this conversion where I can look at the solutions that would also be amazing. Thank you to anyone who takes a look!</p>

CC BY-SA 4.0
2024-02-18T09:05:17.047Z
First hit on Google: https://ned.ipac.caltech.edu/forms/calculator.html
ProfRob
<coordinate-systems>
Can anyone check my code that converts RA/DEC to galactic coordinates?
Alyssa Galicia
# Can anyone check my code that converts RA/DEC to galactic coordinates?

(Asked by: username_0 on 2024-02-18)

Hello, I am collecting some data and need to convert some units, so I built a small script to convert RA/DEC to galactic coordinates. The data has specifically formatted the coordinates as shown in the photo. I have an example in the code, but I don't really have anything to compare my answer to so I don't even know if it is correct. I don't really have familiarity with this so please let me know if I am overlooking something! Here is the code:
from astropy import units as u
from astropy.coordinates import SkyCoord

ra="21:33:56.568"
dec="+04:29:07.84"


#The following function takes str arguments for ra and dec measured as formatted in the TNS #data, and outputs galactic coordinates l and b (l,b)

def ICRStoGal(ra,dec):
    
    coord = ra + dec

    c_icrs = SkyCoord((coord), unit=(u.hourangle, u.deg))

    c_gal =c_icrs.galactic
    l,b=c_gal.l.degree, c_gal.b.degree
    return l,b

ICRStoGal(ra,dec)[0]


As an output to this, I got (58.720664132924085, -32.823605289663924). Or, if anyone has any practice problems with this conversion where I can look at the solutions that would also be amazing. Thank you to anyone who takes a look!

**Tags:** coordinate-systems

> **Comments:**
> **username_1**: First hit on Google: https://ned.ipac.caltech.edu/forms/calculator.html  

---

## 1 answers

### Answer by username_2 on 2024-02-19. Score: 2

Applying spherical trigonometry, it follows that the conversion from equatorial coordinates $\alpha$ and $\delta$ to galactic coordinates $l$ and $b$ is:

$$\left.
\begin{aligned}
\sin b &=\sin \delta\_{NGP} \sin \delta + \cos \delta\_{NGP} \cos \delta \cos ( \alpha - \alpha\_{NGP}) \\
\sin ( l\_{NCP}-l) &=\dfrac{\cos \delta \sin ( \alpha - \alpha\_{NGP})}{\cos b} \\
\cos ( l\_{NCP}-l) &=\dfrac{\cos \delta\_{NGP}\sin \delta - \sin \delta\_{NGP} \cos \delta \cos ( \alpha - \alpha\_{NGP})}{\cos b}
\end{aligned}
\right \}$$

The equatorial coordinates (**J2000**) of the North Galactic Pole are:

$\alpha\_{NGP}=12^h 51^m 26.282^s=192.8595º=3.36603 \ rad$

$\delta\_{NGP}=+27º 07’ 42.01’’=27.1283º=0.473479 \ rad$

And the galactic longitude of the North Celestial Pole is:

$l\_{NCP}=122.932º=2.14557 \ rad$

You can check if your code gives the same results as these equations.

Best regards.

**PD.** For your example:

$\alpha = 21^h \ 33^m \ 56.568^s$

$\delta = +04^{\circ} \ 29' \ 07.84''$

The equations give as a result:

$l = 58.720766^{\circ}$

$b = -32.823544^{\circ}$

> **Comments:**
> **username_0**: Thanks, that is a much simpler way to show the work than what I've been finding online  

---

