Chandra X-Ray Observatory
Skip to the navigation links
Last modified: November 2015

AHELP for CIAO 4.9


Context: contrib


Convert between string and numeric formats for Astronomical positions.


from coords.format import *
(rad, decd) = sex2deg(ras, decs)
rad = ra2deg(ras)
decd = dec2deg(decs)
ras = deg2ra(rad, fmt)
decs = deg2dec(decd, fmt)

rad and decd are in decimal degrees, ras and decs are strings.
fmt is a string and can be one of: " ", "space", ":", "colon", and then
either "hms", "HMS", "hour" or "dms", "degree" for deg2ra() and
deg2dec() respectively

The Python help command - e.g. help(deg2ra) - can be used.


The coords.format module contains 5 routines for converting between string and numeric formats for Astronomical positions.

Loading the routines

The routines can be loaded into a Python session or script by saying:

from coords.format import *

Example 1

chips> from coords.format import *
chips> (ra, dec) = (101.28854, -16.71314)
chips> def doit1(fmt): print("Format={} ra={}".format(fmt,
chips> for fmt in [" ", ":", "hms", "HMS", "hour"]: doit1(fmt)
Format= ra=6 45 9.2496
Format=: ra=6:45:9.2496
Format=hms ra=6h 45m 9.2496s
Format=HMS ra=6H 45M 9.2496S
Format=hour ra=6.75256933333h
chips> def doit2(fmt): print("Format={} dec={}".format(fmt,
chips> for fmt in [" ", ":", "dms", "degree"]: doit2(fmt)
Format= dec=-16 42 47.304
Format=: dec=-16:42:47.304
Format=dms dec=-16d 42' 47.304"
Format=degree dec=-16.71314d

The deg2ra() and deg2dec() routines are used to convert decimal values into strings, showing the various different formatting options.

Example 2

chips> print(ra2deg('6:45:9.2496'))
chips> print(dec2deg('-16d 42\' 47.304"'))

Here we convert a string value into a decimal position.

Changes in the scripts 4.8.1 (December 2015) release

The code has been updated to avoid warning messages from NumPy version 1.9. There is no difference to how the script behaves.

Changes in the scripts 4.5.5 (October 2013) release

The deg2dec routine now correctly handles small negative declinations; that is it now correctly converts the following

chips> print(deg2dec(-0.00138888888889, ':'))

Changes in the scripts 4.5.4 (August 2013) release

Documentation for the coords.format module is new in this release.

About Contributed Software

This module is not an official part of the CIAO release but is made available as "contributed" software via the CIAO scripts page. Please see this page for installation instructions.

See Also

coords_chandra, coords_utils, identify_name

Last modified: November 2015
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email: Smithsonian Institution, Copyright © 1998-2017. All rights reserved.