Convert a direction (vector) to R.A. and Dec in Skyfield

烂漫一生 提交于 2019-12-23 02:38:58

问题


Within Skyfield, if I have a vector (x, y, z) from the center of the earth, how can I back-convert it to a point on the "Celestial Sphere" (i.e. Right Ascension and Declination)?

For example purposes, suppose I have a few points in the orbit of a telescope around the earth, and I want to calculate the exact RA and Dec of the direction normal to the orbit - for whatever reason.

Effects like aberration and gravitation can be neglected here - I'm just looking to transform a direction in ICRF to RA and Dec.

In pseudocode:

from skyfield.api import load
import numpy as np

eph = load('de421.bsp')
ts  = load.timescale()
now = ts.now()

vec     = np.array([3141, 2718, 5820], dtype=float)
nvec = vec / np.sqrt((vec**2).sum())  # normalize for the heck of it

earth = eph['earth']
evec  = earth.at(now).vector(vec)   # pseudocode

print "It's pointing toward: ", evec.radec()   # pseudocode

回答1:


Happily, converting a direction vector in the ICRF to a right ascension and declination is completely independent of the position of the Earth or anything else — it is a question that only involves how some x,y,z coordinates would be expressed as polar coordinates, which is to say that it is a quick problem of geometry.

Using Skyfield:

from skyfield.positionlib import ICRF

vec = ICRF([3141, 2718, 5820])
ra, dec, distance = vec.radec()
print(ra)
print(dec)

Which outputs:

02h 43m 28.94s
+54deg 29' 04.7"

This even avoids having to import NumPy manually, because the ICRF class auto-detects if it has been passed a Python list and automatically converts it into a NumPy array for you.



来源:https://stackoverflow.com/questions/36740731/convert-a-direction-vector-to-r-a-and-dec-in-skyfield

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!