簡體   English   中英

從hh:mm:ss到ra的dec轉換

[英]ra & dec conversion from hh:mm:ss to degrees

我有一個包含hh:mm:ss格式的ra&dec的文件。 假設文件名為“ coord.txt”,其內容為:

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或任何其他程序將其轉換為度。

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]]

awk實現@ M.Danilchenko的邏輯

$ 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)

哪里

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM