#!/usr/bin/python # syntax # # %> ./radectodeg.py infile # ########### ########### # # program to convert RA DEC listing to decimal RA and DEC # # e.g., to modify spitzer RA DEC logs # # input file should have the format HH MM SS.ss DD MM SS.ss # (spaces instead of :'s) # # based on standards.py # # det 28 jan 2005 # # modified: add a name column in front # # det 5 may 2009 # ########### import math,os,string,sys ################define functions##################################33 # # # conversion function def degtorad(degrees): radians = (degrees * 3.14)/180.0 return radians # # # conversion function def radtodeg(radians): degrees = (radians * 180.0)/3.14 return degrees # # # conversion function: arguments are strings, return is float def sexitodecideg(dd,mm,ss): decimals = ((float(dd)+((float(mm)+(float(ss)/60.0))/60.0))) return decimals # # # conversion function: arguments are strings, return is float def sexitodecidegneg(dd,mm,ss): decimals = ((float(dd)+((float(mm)+(float(ss)/60.0))/60.0))) return -1.0*decimals # # # conversion function: arguments are strings, return is float def sexitodecira(hh,mm,ss): decimals = ((float(hh)+((float(mm)+(float(ss)/60.0))/60.0))/24.0)*360.0 return decimals # # # conversion function: argument is float, returns are integers def decitosexira(decimals): hours = (decimals/360.0) * 24.0 hh = int(hours) minutes = (hours - hh) * 60.0 mm = int(minutes) seconds = (minutes - mm) * 60.0 ss = int(seconds) return hh,mm,ss # # # argument is an integer, return value is a string: pretties up outputs def addzero(value): if (value < 10): newvalue='0%i' % value else: newvalue='%i' % value return newvalue ############ end of function definitions ############################### # read inputs infile = sys.argv[1] indata = open(infile,'r') # begin loop over all entries in input file while 1: dataline = indata.readline() if not dataline: break # columns are ra (HH MM SS.ss) and dec (DD MM SS.ss) str1,str2,str3,str4,str5,str6,str7 = dataline.split() # RA rhh = str2 rmm = str3 rss = str4 # DEC ddd = str5 dmm = str6 dss = str7 radeg = sexitodecira(rhh,rmm,rss) if (ddd[0]=='-'): decdeg = sexitodecidegneg(ddd[1:],dmm,dss) if (ddd[0]=='+'): decdeg = sexitodecideg(ddd[1:],dmm,dss) if ((ddd[0]!='-') and (ddd[0]!='+')): decdeg = sexitodecideg(ddd,dmm,dss) # print results to the screen print str1,radeg,decdeg