Conversion between sexagesimal and decimal coordinate representation

The routines below convert between sexagesimal and decimal coordinate representations.

Warning

Until (and including) version 0.11.0, the sign of declinations starting with ‘-00’ was not handled correctly.

Example: Convert between decimal and sexagesimal representation

from __future__ import print_function, division
from PyAstronomy import pyasl

# Coordinates of HD 1 from SIMBAD
hd1 = "00 05 08.83239 +67 50 24.0135"

print("Coordinates of HD 1 (SIMBAD): ", hd1)

# Obtain decimal representation
ra, dec = pyasl.coordsSexaToDeg(hd1)
print("Coordinates of HD 1 [deg]: %010.6f  %+09.6f" % (ra, dec))

# Convert back into sexagesimal representation
sexa = pyasl.coordsDegToSexa(ra, dec)
print("Coordinates of HD 1 [sexa]: ", sexa)

Routines

PyAstronomy.pyasl.coordsSexaToDeg(c, fullOut=False)

Convert sexagesimal coordinate string into degrees.

Parameters
cstring

The coordinate string. Valid formats are, e.g., “00 05 08.83239 +67 50 24.0135” or “00:05:08.83239 -67:50:24.0135”. Spaces or colons are allowed as separators for the individual components of the coordinates.

fullOutboolean, optional

If True, two additional tuples holding the individual components of the right ascension and declination specification will be returned. The default is False.

Returns
ra, decfloat

Right ascension and declination in degrees.

hms, dmstuples of three floats

If fullOut is True, two tuples of three numbers each will be returned, which hold the individual constituents making up the right ascension (hms) and declination (dms) specifiers in sexagesimal representation.

PyAstronomy.pyasl.coordsDegToSexa(ra, dec, asString=True, fmt=('%02d %02d %06.3f  ', '%s%02d %02d %06.3f'))

Convert right ascension and declination from degrees into sexagesimal representation.

Parameters
rafloat

Right ascension in degrees.

decfloat

Declination in degrees.

asStringboolean, optional

If True (default), the result will be a string formatted according to the rules specified by fmt.

fmttuple of strings, optional

The output format used to create the output string (first ra, second dec). Only used if asString is True (default).

Returns
Coordinatesstring or tuple

If asString is True (default), a string holding the coordinates is returned, which is formatted according to the rules specified by the fmt parameter. If False, a tuple of two tuples is returned, of which the first holds three numbers representing the right ascension (hms) and the second three numbers representing the declination (dms, sign).

PyAstronomy.pyasl.hmsToDeg(h, m, s)

Convert hour-minute-second specification into degrees.

Parameters
hfloat

Hours (0-24)

mfloat

Minutes (time, 0-60)

sfloat

Seconds (time, 0-60)

Returns
Anglefloat

The corresponding angle in degrees.

PyAstronomy.pyasl.degToHMS(d)

Convert degrees into time units (hours-minutes-seconds)

Parameters
dfloat

Degrees (0-360)

Returns
h, m, s: float

Hours, minutes, and seconds

PyAstronomy.pyasl.dmsToDeg(d, m, s, esign=0)

Convert degree-arcminute-arcsecond specification into degrees.

Parameters
dfloat

Degrees.

mfloat

Arcminutes (0-60)

sfloat

Arcseconds (0-60)

esignint, optional, {-1,0,1}

Explicit sign with -1 representing negative sign, +1 representing positive sign, and 0 indicating no explicit sign specification. The explicit sign is necessary if negative southern coordinates are specified but d is 0 and, thus, cannot carry the sign.

Returns
Anglefloat

The corresponding angle in degrees.

PyAstronomy.pyasl.degToDMS(g)

Convert degrees into arc units (degrees, (arc)minutes, (arc)seconds)

Parameters
gfloat

Value in degrees.

Returns
d, m, s, signfloat, int

Degrees, (arc)minutes, and (arc)seconds. Note that only the degree number is signed. The sign (+1/-1) is also returned to yield a complete result if the value of degree (d) is zero.