Last modified: December 2020

URL: https://cxc.cfa.harvard.edu/ciao/ahelp/coords_format.html
AHELP for CIAO 4.16

coords_format

Context: contrib

Synopsis

Convert between string and numeric formats for Astronomical positions.

Syntax

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

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
ndp gives the number of decimal places, if not None.

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

Description

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 *

Examples

Example 1

>>> from coords.format import *
>>> (ra, dec) = (101.28854, -16.71314)
>>> def doit1(fmt): print(f"Format={fmt:6s} ra={deg2ra(ra,fmt)}")
>>> for fmt in [" ", ":", "hms", "HMS", "hour"]: doit1(fmt)
Format= ra=6 45 9.249599999997713
Format=: ra=6:45:9.249599999997713
Format=hms ra=6h 45m 9.249599999997713s
Format=HMS ra=6H 45M 9.249599999997713S
Format=hour ra=6.752569333333333h
>>> def doit2(fmt): print(f"Format={fmt:6s} dec={deg2dec(dec,fmt)}")
>>> for fmt in [" ", ":", "dms", "degree"]: doit2(fmt)
Format= dec=-16 42 47.30399999999719
Format=: dec=-16:42:47.30399999999719
Format=dms dec=-16d 42' 47.30399999999719"
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

>>> print(deg2ra(ra, 'hms', ndp=3))
6h 45m 9.250s
>>> print(deg2dec(dec, 'dms', ndp=2))
-16d 42' 47.30"

Here we use the oprional ndp argument to deg2ra() and deg2dec() to restrict the number of decimal places in the output.

Example 3

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

Here we convert a string value into a decimal position.


Changes in the scripts 4.13.0 (December 2020) release

The optional argument ndp has been added to the deg2ra and deg2dec routines.

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

>>> print(deg2dec(-0.00138888888889, ':'))
-0:0:5.0

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

contrib
coords_chandra, coords_gratings, coords_utils, identify_name