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
  • 2
    $\begingroup$ 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 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 $\endgroup$ Feb 23 at 18:22
  • 1
    $\begingroup$ 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 $\endgroup$
    – Adrian
    Feb 23 at 18:28
  • 2
    $\begingroup$ A direct implementation in JavaScript is here: celestialprogramming.com/decimal_degrees_to_components.html $\endgroup$ Feb 23 at 21:30
  • $\begingroup$ @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. $\endgroup$
    – uhoh
    Feb 24 at 0:18


You must log in to answer this question.

Browse other questions tagged .