我对python比较陌生,所以我会尽力解释我想要做的事情.我试图遍历两个星形列表(两个都包含记录数组),试图通过它们的坐标匹配恒星与公差(在这种情况下Ra和Dec,它们都是记录数组中的索引).但是,一个列表中似乎有多个星星与另一个星星中的相同星星相匹配.*这是因为atol中的两个星都匹配.有办法防止这种情况吗?这是我到目前为止所拥有的:
from __future__ import print_function
import numpy as np
###importing data###
Astars = list()
for s in ApStars:###this is imported but not shown
Astars.append(s)
wStars = list()
data1 = np.genfromtxt('6819.txt', dtype=None, delimiter=',', names=True)
for star in data1:
wStars.append(star)
###beginning matching stars between the Astars and wStars###
list1 = list()
list2 = list()
for star,s in [(star,s) for star in wStars for s in Astars]:
if np.logical_and(np.isclose(s["RA"],star["RA"], atol=0.000277778)==True ,
np.isclose(s["DEC"],star["DEC"],atol=0.000277778)==True):
if star not in list1:
list1.append(star) #matched wStars
if s not in list2:
list2.append(s) #matched Astars
Run Code Online (Sandbox Code Playgroud)
我不能减少atol,因为它超出了仪器误差.会发生什么:有多个Wstars匹配一个Astar.如果有可能的话,我只想要一颗星星.
有什么建议?
我感谢您提供的一切!我也做了一些询问,找到了一个聪明的方法来实现我正在寻找的东西。这是我们的想法:
sharedStarsW = list()
sharedStarsA = list()
for s in Astars:
distance = [((s["RA"] - star["RA"])**2 + (s["DEC"] - star["DEC"])**2)**0.5 for star in wStars]
if np.amin(distance) < 0.00009259266:
sharedStarsW.append(wStars[(np.argmin(distance))])
sharedStarsA.append(s)
Run Code Online (Sandbox Code Playgroud)
使用列表理解,计算从 Astar 到所有 wStar 的距离,并获取所有落在 1/3 角秒内的距离。如果一个 Astar 星有多个 wStar 匹配,它会附加给出最短距离的 Wstar 索引及其 Astar。
| 归档时间: |
|
| 查看次数: |
85 次 |
| 最近记录: |