所以,我试着做一个代码,我取我的恒星样本(M矮星,一般),只有恒星有一个确定的系外行星围绕它运行。但是这个恒星样本很大(大约178颗恒星),我必须将它自动化,并将具有系外行星的恒星放在熊猫的数据中,其中有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'>在我运行buggy代码之后,当我重新运行它们时,它会让预览块代码,就像上面更简单的代码一样,不再显示出同样的错误。当我重新启动内核时,如果我不运行buggy块代码,它们将再次工作。
那么为什么只有当我将错误放在for循环中时才会出现错误呢?为什么它使其他简单的代码不再工作了?有人知道如何解决这个问题,或者对这个错误有什么解释?很好地说,几个月前我遇到了同样的问题,但它显示的是“系列赛”而不是“名单”,它突然间消失了。
很抱歉,如果这个问题太长了,这是我在StackOverflow中的第一个问题,我在astropy和天文查询(以及所有与天文学相关的python)方面都是新手。
发布于 2021-09-24 03:07:41
嗯,和往常一样,这个错误是我永远不会看到的,如果不是朋友的帮助的话。
问题是,我将具有坐标的列表命名为:
coord = [C[0],C[1]]它窃听了Skycoord的进口部分并覆盖了它:
import astropy.coordinates as coord所以,这就是解决办法。大问题,小错误。
https://stackoverflow.com/questions/69308776
复制相似问题