简体   繁体   English

SkyCoord 距离抛出 KeyError: 0

[英]SkyCoord distance throws KeyError: 0

# print(df['parallax'].min())
# 724097.8971232784
# print(df['parallax'].max())
# 767397.7874147035

# Convert the RA, Dec, and parallax to 3D Cartesian coordinates
c = SkyCoord(ra=df['ra']*u.deg, dec=df['dec']*u.deg, distance=df['parallax']*u.pc, frame='icrs')

I'm trying to convert my retrieved data to cartesian coordinates using SkyCord but the execution throws a KeyError: 0我正在尝试使用 SkyCord 将检索到的数据转换为笛卡尔坐标,但执行会抛出 KeyError: 0

I've been able to narrow down the source of the error to the distance parameter.我已经能够将错误来源缩小到距离参数。 The distance values in my data set are in the range of 724097.8971232784 to 767397.7874147035 and I've made sure that there aren't any NaN entries.我的数据集中的距离值在 724097.8971232784 到 767397.7874147035 的范围内,并且我确保没有任何 NaN 条目。 But it looks to me as though SkyCoord has an issue with my distance values anyway.但在我看来,无论如何 SkyCoord 对我的距离值都有问题。

Any ideas as to how to fix this problem are much appreciated.非常感谢有关如何解决此问题的任何想法。

I'm using astropy 5.1我正在使用 astropy 5.1

It looks like I've been able to get rid of this error by doing the conversion to Quantity object beforehand and defining dtype as float64 as follows:看起来我已经能够通过预先转换为 Quantity object 并将 dtype 定义为 float64 来消除此错误,如下所示:

parallax = u.Quantity(df['parallax'], unit='pc', dtype='float64')
# Convert the RA, Dec, and parallax to 3D Cartesian coordinates
c = SkyCoord(ra=df['ra']*u.deg, dec=df['dec']*u.deg, distance=parallax*u.pc, frame='icrs')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM