# Can anyone check my code that converts RA/DEC to galactic coordinates?

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!

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.

$$\alpha = 21^h \ 33^m \ 56.568^s$$
$$\delta = +04^{\circ} \ 29' \ 07.84''$$
$$l = 58.720766^{\circ}$$
$$b = -32.823544^{\circ}$$