将字符串解析为天文坐标

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)

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
https://docs.astropy.org/en/latest/units/combining_and_defining.html

>>> '01 24 45.98328' * u.hour

astropy.units不知道球形几何形状或六进制（小时，分钟，秒）：如果要处理天坐标，请参阅astropy.coordinates包装。

TL; DRSkyCoord本身处理解析的坐标格式，您可以将坐标直接指定为SkyCoord

>>> SkyCoord(ra='01 24 45.98328', dec='+22 30 04.3700', unit=(u.hourangle, u.deg))
<SkyCoord (ICRS): (ra, dec) in deg
(21.191597, 22.50121389)>

0条评论