首页 > 解决方案 > SkyCoord 错误:“列表”(或“系列”)对象没有属性“SkyCoord” - 在 for 循环中查询星星时

问题描述

所以,我正在尝试编写一个代码,在其中我采集我的恒星样本(通常是 M 矮星),并且只获取具有确认的系外行星围绕它运行的恒星。但是恒星样本很大(大约 178 颗恒星),我必须对其进行自动化处理,并将带有系外行星的恒星放入 pandas 数据框中,有 3 列:恒星名称、系外行星数量、系外行星 ID。

为了让它工作,我使用了 Simbad 库astroquery.simbad。这个想法是在恒星周围查询“0d0m0.02s”的比率并获取行星(也许可以通过恒星的ID来做到这一点,但我不知道这是否可能,但那是不是问题)。

我做了一些测试,只查询一颗有行星的恒星,另一颗没有行星,直到那里的想法和代码有点工作。就像这样:

from astroquery.simbad import Simbad
from astroquery import open_exoplanet_catalogue as oec
from astroquery.open_exoplanet_catalogue import findvalue
import astropy.units as u
import astropy.coordinates as coord
from astropy.coordinates import SkyCoord
import numpy as np

test = C[1] #Coordinates of a star with plantes

#The coordinates were like that:
# <SkyCoord (ICRS): (ra, dec) in deg
#   (343.31971792, -14.26369528)>

#And the query:

result = Simbad.query_region(coord.SkyCoord(SkyCoord(test, unit=(u.hourangle, u.deg)), unit=(u.deg), frame='icrs'), radius='0d0m0.02s')

result

和输出:查询的输出

但是当我试图让它稍微复杂一点时,通过使用for循环来获取列表中两颗星的坐标,代码不起作用,并出现错误:

AttributeError: 'list' object has no attribute 'SkyCoord' 

我正在谈论的稍微复杂的代码:

from astroquery.simbad import Simbad
from astroquery import open_exoplanet_catalogue as oec
from astroquery.open_exoplanet_catalogue import findvalue
import astropy.units as u
import astropy.coordinates as coord
from astropy.coordinates import SkyCoord
import numpy as np


ie = [ID[0],ID[1]] #This should be the stars ID, for the idenfication sake in the dataframe i want to make
coord = [C[0],C[1]] 

#This above are the coordinates of the 2 stars i want to query for tests, them being:

# [<SkyCoord (ICRS): (ra, dec) in deg
#   (348.569285, -19.64428167)>, <SkyCoord (ICRS): (ra, dec) in deg
#   (343.31971792, -14.26369528)>]

#For loop which seems to be the reason of the problem
for i, j in zip(ie,coord):


    #As you know the j variable would be equivalent as de C[0] or C[1]  coordinate
    query = Simbad.query_region(coord.SkyCoord(SkyCoord(j, unit=(u.hourangle, u.deg)), unit=(u.deg), frame='icrs'), radius='0d0m0.02s')
    
    #And the rest of the code below, that don't seem important to be here

此代码块给出了错误:

AttributeError: 'list' object has no attribute 'SkyCoord' 

这是没有意义的,因为类型C[0]是:

<class 'astropy.coordinates.sky_coordinate.SkyCoord'>

在我运行有问题的块代码之后,当我重新运行它们时,它使预览块代码,就像那里更简单的那样,不再显示相同的错误。当我重新启动内核时,如果我不运行有问题的块代码,它们会再次工作。

那么为什么只有当我将它放在for 循环中时才会出现错误?为什么它使其他简单的代码不再工作?有人知道如何解决这个问题或对该错误有任何解释吗?很高兴几个月前我遇到了同样的问题,但它显示的是“系列”而不是“列表”,然后它突然消失了。

抱歉,如果问题太长,这是我在 StackOverflow 中的第一次,我在 astropy 和 astroquery(以及所有与天文学相关的 python)方面确实是新手。

标签: pythonpandasastropyastroquery

解决方案


好吧,与往常一样,如果没有朋友的帮助,我永远不会看到错误。

问题是我将坐标命名为:

coord = [C[0],C[1]]

它正在窃听 Skycoord 的导入部分并覆盖它:

import astropy.coordinates as coord

所以,这就是解决方案。大问题,小错误。


推荐阅读