<p>This can be pretty easily accomplished in astropy using the following code:</p>
<pre><code>import astropy.units as u
import astropy.time
import astropy.coordinates

coord = astropy.coordinates.TETE(
    ra=25 * u.deg,
    dec=45 * u.deg,
    obstime=astropy.time.Time(&quot;2023-04-12&quot;)
)

coord = coord.transform_to(astropy.coordinates.Galactic())

print(coord.l.deg, coord.b.deg)
</code></pre>
<p>which outputs</p>
<pre><code>131.65579483995242 -17.18683219126681
</code></pre>
<p>It works by specifying the right ascension and declination in the True Equator True Equinox coordinate system (known as <code>astropy.coordinates.TETE</code>) and then using the <code>transform_to()</code> method to convert the coordinates into galactic coordinates.</p>

CC BY-SA 4.0
2023-04-12T22:44:49.073Z
2023-04-12T22:44:49.073Z
Roy Smart
<p>I actually made a converter for myself, with help from some old website that may not be around anymore. I think this may be what you're looking for: <a href="https://docs.google.com/spreadsheets/d/1wneDrG5xUMr1jMfPPOVLxPzkT72EMKj6dh52dzEHVAk/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1wneDrG5xUMr1jMfPPOVLxPzkT72EMKj6dh52dzEHVAk/edit?usp=sharing</a></p>
<p>The J2K (Right Ascension and Declination) part is all the way at the bottom, I'm afraid; I might give everything its own sheet in the future.
For that part, I used the following, gleaned from said old website:</p>
<p>For <strong>RIGHT ASCENSION</strong></p>
<ul>
<li><p>Multiply hours by 15</p>
</li>
<li><p>Divide minutes by 4</p>
</li>
<li><p>Divide seconds by 239.999808000153</p>
</li>
<li><p>Add it all together!</p>
</li>
</ul>
<p>For <strong>DECLINATION</strong></p>
<ul>
<li><p>If the first part (degrees) is negative, make it positive. Otherwise, leave it as it is.</p>
</li>
<li><p>Divide minutes by 59.9999880000023</p>
</li>
<li><p>Divide seconds by 3599.97120023039</p>
</li>
<li><p>Add it all together. If the value of the 'degrees' part had been negative, make this summed value negative.</p>
</li>
</ul>

CC BY-SA 4.0
2023-04-13T02:21:35.243Z
Can I get actual analytic formula for conversion?
Kyle
CC BY-SA 4.0
2023-04-15T16:28:10.120Z
@Kyle You can, sorry. I'm new to this place. I'll edit it into the original answer.
Kazon
CC BY-SA 4.0
2023-04-15T16:28:35.077Z
@uhoh Sorry. I will do that ASAP!
Kazon
CC BY-SA 4.0
2023-04-15T19:29:43.940Z
Okay looks great, thanks!
uhoh
CC BY-SA 4.0
2024-11-27T04:06:58.073Z
One detail, which will probably be obvious to many (but not all), is that if the declination coordinate is **negative**, make it **positive** before doing the calculations for it, and then make it negative again when finished. Otherwise positive values get added to a negative value, and the resulting coordinate will be inaccurate.
Mentalist
CC BY-SA 4.0
2024-11-28T06:28:27.033Z
I just went ahead and added the steps for handling negative degree values. I think it's easier for readers to understand in one pass than by trying to apply what I described in my previous comment as a second layer of logic. I hope you don't mind.
Mentalist
CC BY-SA 4.0
2024-11-28T06:39:43.453Z
Also, re-reading the original question, OP wanted to convert to *galactic* coordinates. But what your program and steps describe is a conversion from *sexagesimal* RA/Dec to *decimal* RA/Dec. (Someone please correct me if I'm mistaken about any of this.)
Mentalist
CC BY-SA 4.0
2023-04-12T20:23:51.400Z
2024-12-03T15:22:01.070Z
2024-12-03T15:22:01.070Z
Kazon
<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>Reference:</p>
<p><a href="https://www.scientificlib.com/en/Astronomy/Galaxies/GalacticCoordinateSystem.html" rel="nofollow noreferrer"><strong>Galactic coordinate system. (Scientific Library)</strong></a></p>
<p>Additional bibliography:</p>
<p><a href="https://www.aanda.org/articles/aa/full_html/2011/02/aa14961-10/aa14961-10.html" rel="nofollow noreferrer"><strong>Reconsidering the Galactic coordinate system</strong></a></p>
<p><a href="https://arxiv.org/abs/1306.2945" rel="nofollow noreferrer"><strong>Transformation of the equatorial proper motion to the Galactic system</strong></a></p>
<p>Best regards.</p>

CC BY-SA 4.0
2023-04-13T08:12:25.757Z
2023-04-14T07:10:23.023Z
2023-04-14T07:10:23.023Z
Albert
<p>I am an astro-particle physics PhD student trying to look for a simulation.</p>
<p>I was looking for a conversion formula for sky (or celestial or Equatorial) coordinate system using Right Ascension and Declination to l and b (galactic longitude and latitude).</p>
<p>Of course, since sky coordinate cannot contain Earth rotation or evolution effect, I also have UTC time for specific time.</p>
<p>Can anyone tell me the formula of RA, Dec and UTC to l and b?</p>
<p>Thanks in advance.</p>

CC BY-SA 4.0
2023-04-12T21:10:30.023Z
The conversion from RA and Dec to l and b does not depend on time (other than the equinox).
ProfRob
<observational-astronomy><positional-astronomy><galaxy-center><coordinate-systems><spherical-astronomy>
How can I convert my sky coordinate system (RA, Dec) into galactic coordinate system (l, b)?
Kyle
# How can I convert my sky coordinate system (RA, Dec) into galactic coordinate system (l, b)?

(Asked by: username_0 on 2023-04-12)

I am an astro-particle physics PhD student trying to look for a simulation.

I was looking for a conversion formula for sky (or celestial or Equatorial) coordinate system using Right Ascension and Declination to l and b (galactic longitude and latitude).

Of course, since sky coordinate cannot contain Earth rotation or evolution effect, I also have UTC time for specific time.

Can anyone tell me the formula of RA, Dec and UTC to l and b?

Thanks in advance.

**Tags:** observational-astronomy, positional-astronomy, galaxy-center, coordinate-systems, spherical-astronomy
> **Comments:**
> **username_1**: The conversion from RA and Dec to l and b does not depend on time (other than the equinox).  

---

## 3 answers

### Answer by username_6 on 2023-04-13. Score: 8 | Accepted answer

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$

Reference:

[**Galactic coordinate system. (Scientific Library)**](https://www.scientificlib.com/en/Astronomy/Galaxies/GalacticCoordinateSystem.html)

Additional bibliography:

[**Reconsidering the Galactic coordinate system**](https://www.aanda.org/articles/aa/full_html/2011/02/aa14961-10/aa14961-10.html)

[**Transformation of the equatorial proper motion to the Galactic system**](https://arxiv.org/abs/1306.2945)

Best regards.


---

### Answer by username_2 on 2023-04-12. Score: 3

This can be pretty easily accomplished in astropy using the following code:
import astropy.units as u
import astropy.time
import astropy.coordinates

coord = astropy.coordinates.TETE(
    ra=25 * u.deg,
    dec=45 * u.deg,
    obstime=astropy.time.Time("2023-04-12")
)

coord = coord.transform_to(astropy.coordinates.Galactic())

print(coord.l.deg, coord.b.deg)

which outputs
131.65579483995242 -17.18683219126681

It works by specifying the right ascension and declination in the True Equator True Equinox coordinate system (known as astropy.coordinates.TETE) and then using the transform_to() method to convert the coordinates into galactic coordinates.


---

### Answer by username_3 on 2023-04-12. Score: 1

I actually made a converter for myself, with help from some old website that may not be around anymore. I think this may be what you're looking for: <https://docs.google.com/spreadsheets/d/1wneDrG5xUMr1jMfPPOVLxPzkT72EMKj6dh52dzEHVAk/edit?usp=sharing>

The J2K (Right Ascension and Declination) part is all the way at the bottom, I'm afraid; I might give everything its own sheet in the future.
For that part, I used the following, gleaned from said old website:

For **RIGHT ASCENSION**

* Multiply hours by 15
* Divide minutes by 4
* Divide seconds by 239.999808000153
* Add it all together!

For **DECLINATION**

* If the first part (degrees) is negative, make it positive. Otherwise, leave it as it is.
* Divide minutes by 59.9999880000023
* Divide seconds by 3599.97120023039
* Add it all together. If the value of the 'degrees' part had been negative, make this summed value negative.

> **Comments:**
> **username_0**: Can I get actual analytic formula for conversion?  
> **username_3**: @Kyle You can, sorry. I'm new to this place. I'll edit it into the original answer.  
> **username_3**: @uhoh Sorry. I will do that ASAP!  
> **username_4**: Okay looks great, thanks!  
> **username_5**: One detail, which will probably be obvious to many (but not all), is that if the declination coordinate is **negative**, make it **positive** before doing the calculations for it, and then make it negative again when finished. Otherwise positive values get added to a negative value, and the resulting coordinate will be inaccurate.  
> **username_5**: I just went ahead and added the steps for handling negative degree values. I think it's easier for readers to understand in one pass than by trying to apply what I described in my previous comment as a second layer of logic. I hope you don't mind.  
> **username_5**: Also, re-reading the original question, OP wanted to convert to *galactic* coordinates. But what your program and steps describe is a conversion from *sexagesimal* RA/Dec to *decimal* RA/Dec. (Someone please correct me if I'm mistaken about any of this.)  

---

