This test has two parts; the second part is the reverse conversion from the first part.
Find the local hour-angle of a star whose right ascension is α=18h 32m 21s, at a point whose longitude is 64° W, on April 22nd 1980 at 14h 36m 51.67s GMT. Answer: 5h 51m 44s.
#!/usr/bin/env python #================================================================ # test24: Convert from right ascension to hour angle and back. # For documentation, see: # http://www.nmt.edu/tcc/help/lang/python/examples/sidereal/ims/ #---------------------------------------------------------------- import sys from math import * import datetime import sidereal
First we convert the value of α to radians.
For the conversion of mixed units to degrees, see Section 10.2, “MixedUnits.mixToSingle(): Convert to
a single value”; radians() is from Python's math
module and converts degrees to radians.
Next we convert 64° to radians. Then we make a datetime.datetime instance for the given time.
# - - - m a i n
def main():
"""Main program.
"""
global dmsUnits
#-- 1 --
# [ dmsUnits := a MixedUnits instance for factor list (60,60) ]
dmsUnits = sidereal.MixedUnits ( (60, 60) )
#-- 2 --
# [ ra := (18h 32m 21s) in radians
# eLong := 64 degrees as radians
# dt := 14h 36m 51.67s GMT as a datetime.datetime ]
raHours = dmsUnits.mixToSingle((18,32,21))
ra = sidereal.hoursToRadians(raHours)
eLong = radians(-64.0)
dt = datetime.datetime ( 1980, 4, 22, 14, 36, 51, 670000 )
print "Right ascension:", radHMS(ra)
print "Longitude:", radDMS(eLong)
print "UTC:", dt
The function Section 9.3, “hourAngleToRA(): Convert an hour
angle to right ascension” returns the hour
angle in radians; we'll format it in degrees, minutes, and
second for display.
#-- 3 --
# [ hRadians := hour angle in radians for right ascension (ra),
# time (dt), and longitude (eLong) ]
hRadians = sidereal.raToHourAngle ( ra, dt, eLong )
#-- 4 --
# [ sys.stdout +:= hRadians displayed as deg/min/sec ]
print "Hour angle:", radHMS(hRadians)
Now, the inverse test.
#-- 5 --
# [ check := right ascension for hour angle (hRadians),
# time (dt), and longitude (eLong) ]
checkRadians = sidereal.hourAngleToRA ( hRadians, dt, eLong )
#-- 6 --
# [ sys.stdout +:= checkRadians displayed as d/m/s ]
raDec = radHMS ( checkRadians )
print "Check RA:", radHMS ( checkRadians )
This subroutine is used to display radians as degrees, minutes, and seconds.
# - - - r a d D M S
def radDMS(rad):
"""Display radians as degrees, minutes, and seconds.
"""
valueList = dmsUnits.format (
dmsUnits.singleToMix(degrees(rad)), lz=True, decimals=3 )
return "%sd %s' %s\"" % tuple(valueList)
This subroutine displays radians as hours, minutes, and seconds.
# - - - r a d H M S
def radHMS(rad):
"""Display radians as hours, minutes, and seconds.
"""
valueList = dmsUnits.format (
dmsUnits.singleToMix ( sidereal.radiansToHours(rad) ),
lz=True, decimals=3 )
return "%sh %sm %ss" % tuple(valueList)
#================================================================
# Epilogue
#----------------------------------------------------------------
if __name__ == "__main__":
main()