<p>I'm working on a small mount controller software in Python. From the ASCOM standard, right ascension is reported in unit of hours.
How do I convert from hours to hours:min:sec?
Here is my attempt in Python, using astropy. Don't know if it is correct.</p>
<pre><code># make a coordinate object
 coords = SkyCoord(driver.RightAscension * u.hour, driver.Declination*u.degree, frame = 'icrs')
       
# format to RA and DEC
 RA_hms = coords.ra.to_string(unit=u.hourangle, sep=':',pad=True, precision=1) # format hms
 DEC_dms = coords.dec.to_string(unit=u.degree, sep=':',pad=True, alwayssign= True,precision=1) # format dms
</code></pre>

CC BY-SA 4.0
2023-02-23T18:22:52.130Z
Your code is not wrong but it depends what you what the RA in h:m:s for... For display purposes, your code is fine. If you want direct access to the RA value in hourangle for some reason you can do `coords.ra.hourangle`. One other Q: is the value coming back from ASCOM really in ICRS ? If you look at page 4 this presentation on [telescope pointing](http://www.tpointsw.uk/spie08ppt.pdf) objects move down from ICRS to mount angles and mount angles come back up to ICRS passing through various transformations. Astropy can do these transforms, but you need to tell it what frame the coords are in
astrosnapper
CC BY-SA 4.0
2023-02-23T18:28:58.650Z
Thank you, I fetch the RA and DEC values from the telescope, as reported by the ASCOM telescope driver. Then I display the values in a textbox. With regard to the coordinate frame, I don't know for sure if it's ICRS. I'll have to check
Adrian
CC BY-SA 4.0
2023-02-23T21:30:21.873Z
A direct implementation in JavaScript is here: https://www.celestialprogramming.com/decimal_degrees_to_components.html
Greg Miller
CC BY-SA 4.0
2023-02-24T00:18:40.260Z
@Adrian if you do get it working, you can always post an answer to your own question and perhaps after a few days accept it too.
uhoh
<astropy><right-ascension>
Convert RA from hours to h:m:s
Adrian
# Convert RA from hours to h:m:s

(Asked by: username_0 on 2023-02-23)

I'm working on a small mount controller software in Python. From the ASCOM standard, right ascension is reported in unit of hours.
How do I convert from hours to hours:min:sec?
Here is my attempt in Python, using astropy. Don't know if it is correct.

```
# make a coordinate object
 coords = SkyCoord(driver.RightAscension * u.hour, driver.Declination*u.degree, frame = 'icrs')
       
# format to RA and DEC
 RA_hms = coords.ra.to_string(unit=u.hourangle, sep=':',pad=True, precision=1) # format hms
 DEC_dms = coords.dec.to_string(unit=u.degree, sep=':',pad=True, alwayssign= True,precision=1) # format dms

```

**Tags:** astropy, right-ascension

> **Comments:**
> **username_1**: Your code is not wrong but it depends what you what the RA in h:m:s for... For display purposes, your code is fine. If you want direct access to the RA value in hourangle for some reason you can do `coords.ra.hourangle`. One other Q: is the value coming back from ASCOM really in ICRS ? If you look at page 4 this presentation on [telescope pointing](http://www.tpointsw.uk/spie08ppt.pdf) objects move down from ICRS to mount angles and mount angles come back up to ICRS passing through various transformations. Astropy can do these transforms, but you need to tell it what frame the coords are in  
> **username_0**: Thank you, I fetch the RA and DEC values from the telescope, as reported by the ASCOM telescope driver. Then I display the values in a textbox. With regard to the coordinate frame, I don't know for sure if it's ICRS. I'll have to check  
> **username_2**: A direct implementation in JavaScript is here: https://www.celestialprogramming.com/decimal_degrees_to_components.html  
> **username_3**: @username_0 if you do get it working, you can always post an answer to your own question and perhaps after a few days accept it too.  

---

## 0 answers

