Python 将字符串解析为天文坐标

Python 将字符串解析为天文坐标,python,string,astropy,Python,String,Astropy,我正在尝试从csv文件加载一组坐标。该文件包含星系的坐标,这些坐标加载到熊猫数据框中,如以下代码段所示: 我试图从列\u RAJ2000和\u DEJ2000中提取坐标,以便与另一个文件交叉匹配。我的代码: import numpy as np from astropy import units as u from astropy.coordinates import SkyCoord as coord import quasar_functions as qf # c1 = coord('

我正在尝试从csv文件加载一组坐标。该文件包含星系的坐标,这些坐标加载到熊猫数据框中,如以下代码段所示:

我试图从列
\u RAJ2000
\u DEJ2000
中提取坐标,以便与另一个文件交叉匹配。我的代码:

import numpy as np
from astropy import units as u
from astropy.coordinates import SkyCoord as coord
import quasar_functions as qf

# c1 = coord('5h23m34.5s', '-69d45m22s', distance = 70*u.kpc, frame = 'icrs')
# c2 = coord('0h52m44.8s', '-72d49m43s', distance = 80*u.kpc, frame = 'fk5')

# sep = c1.separation(c2)
# sep_3d = c1.separation_3d(c2)

data = ...# here's where I call my loading function
ra1, dec1 = data['_RAJ2000'], data['_DEJ2000']
ooi1_ra, ooi1_dec = ra1[22], ra1[60]
object1_coords = coord(ra1[22]*u.hour, dec1[22]*u.degree)
object2_coords = coord(ra1[60]*u.hour, dec1[60]*u.degree)
但我有一个错误:

ValueError: '01 24 45.98328' did not parse as unit: Syntax error parsing unit '01 24 45.98328' If
this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file
reader or other code, enable it with 'u.add_enabled_units'. For details, see
https://docs.astropy.org/en/latest/units/combining_and_defining.html

我不想将其定义为自定义单元;我宁愿让Astropy本机读取它(如果可能的话),或者修改字符串以便Astropy可以处理坐标。我认为RA以h/m/s表示,DE以度表示。

您所做的相当于:

>>'01 24 45.98328'*u.hour
这意味着尝试将字符串“01 24 45.98328”转换为以小时为时间单位的数量。与第二个相同,但以度为单位。我能理解这背后的逻辑,也许应该支持它。但原始单位不知道如何处理不同的坐标系表示,根据:

astropy.units
不知道球面几何或六边形(小时、分钟、秒):如果要处理天体坐标,请参阅
astropy.coordinates
软件包

TL;DR
SkyCoord
本身负责解析坐标格式,您可以将坐标直接指定给
SkyCoord

天空合作社(ra='01 24 45.98328',dec='+22 30 04.3700',单位=(u.hourangle,u.deg))
您所做的等同于:

>>'01 24 45.98328'*u.hour
这意味着尝试将字符串“01 24 45.98328”转换为以小时为时间单位的数量。与第二个相同,但以度为单位。我能理解这背后的逻辑,也许应该支持它。但原始单位不知道如何处理不同的坐标系表示,根据:

astropy.units
不知道球面几何或六边形(小时、分钟、秒):如果要处理天体坐标,请参阅
astropy.coordinates
软件包

TL;DR
SkyCoord
本身负责解析坐标格式,您可以将坐标直接指定给
SkyCoord

天空合作社(ra='01 24 45.98328',dec='+22 30 04.3700',单位=(u.hourangle,u.deg))