【发布时间】:2019-12-14 21:36:54
【问题描述】:
我需要将一个大型 ICRS 数据库(大约 10 亿个数据)转换为星系中心坐标。首先,我尝试使用将我的数据转换为 coord.ICRS,然后在迭代循环中将这些转换为 coord.Galactocentric。但这非常耗时。环顾四周,我 found 在 coord.Skycoord 中您可以使用数据数组进行转换。所以我在我的代码上实现了解决方案:
data = pd.read_csv('/content/data (1).csv')
data_ra = data['ra']
data_dec = data['dec']
data_dist = data['r_est']
data_ra = data_ra * u.degree
data_dec = data_dec * u.degree
data_dist = data_dist * u.pc
c = coord.ICRS(data_ra, data_dec, data_dist)
c = c.transform_to(coord.Galactocentric)
x = c.x.value
y = c.y.value
z = c.z.value
返回错误码:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-26-e02bbc9ec5dd> in <module>()
6 data_dec = data_dec * u.degree
7 data_dist = data_dist * u.pc
----> 8 c = coord.ICRS(data_ra, data_dec, data_dist)
9 c = c.transform_to(coord.Galactocentric)
10 x = c.x.value
5 frames
/usr/local/lib/python3.6/dist-packages/astropy/units/quantity.py in __new__(cls, value, unit, dtype, copy, order, subok, ndmin)
340 # Convert all quantities to the same unit.
341 if unit is None:
--> 342 unit = value[0].unit
343 value = [q.to_value(unit) for q in value]
344 value_unit = unit # signal below that conversion has been done
AttributeError: 'numpy.float64' object has no attribute 'unit'
我似乎无法解决问题,coord.ICRS 与数组不兼容吗?如果是这样,我怎样才能加快转型过程。
【问题讨论】: