2016-10-06 23 views
0

我有一個文件,其中包含以hh:mm:ss格式表示的ra & dec。 說出文件名是 「coord.txt」,它的內容是:ra&dec從hh:mm:ss轉換爲度

06 40 34.8 10 04 22 06 41 11.6 10 02 24 06 40 50.9 10 01 43

06 40 34.8是ra和10 04 22是dec 如何使用python或任何其他程序將其轉換爲度數。

+0

什麼是 「RA」 與 「DEC」 代表什麼? –

+0

lmgtfy:ra dec to degrees python: http://docs.astropy.org/en/stable/coordinates/ –

+0

@ Scott「ra」代表赤經,「dec」代表赤緯。那些是天文物體的座標。 – Offor

回答

0
s = "06 40 34.8 10 04 22 06 41 11.6 10 02 24 06 40 50.9 10 01 43" 
# or s = f.readline() 
d = [float(i) for i in s.split()] 
# d = [6.0, 40.0, 34.8, 10.0, 4.0, 22.0, 6.0, 41.0, 11.6, 10.0, 2.0, 24.0, 6.0, 40.0, 50.9, 10.0, 1.0, 43.0] 

d2 = [d[i:i+3] for i in range(0, len(d), 3)] 
# d2 = [[6.0, 40.0, 34.8], [10.0, 4.0, 22.0], [6.0, 41.0, 11.6], [10.0, 2.0, 24.0], [6.0, 40.0, 50.9], [10.0, 1.0, 43.0]] 

d3 = [(s/3600 + m/60 + h) * 15 for h,m,s in d2] 

d4 = [d3[i:i+2] for i in range(0, len(d3), 2)] 

print d4 
# [[100.145, 151.09166666666667], [100.29833333333333, 150.6], [100.21208333333334, 150.42916666666667]] 
0

awk

$ awk '{for(i=1;i<NF;i+=3) a[++c]=($i*15+($(i+1)+$(i+2)/60)/4); 
     for(i=1;i<c;i+=2) printf "(%.3f,%.3f) ", a[i],a[i+1]; 
     print ""}' file 

(100.145,151.092) (100.298,150.600) (100.212,150.429) 

實施@ M.Danilchenko的邏輯在那裏

$ cat file 
06 40 34.8 10 04 22 06 41 11.6 10 02 24 06 40 50.9 10 01 43 
相關問題