-
I have the barycentric coordinates of a thing in the solar system, and I'd like to know where in the sky it is when observed from a specific location on Earth at a specific time. Below is an example script of how I'm trying to do this, but calling What is the recommended way of doing something like this? I am probably misunderstanding or missing something. from skyfield.api import load, wgs84
from skyfield.positionlib import Barycentric
planets = load('de421.bsp')
earth = planets['earth']
location = earth + wgs84.latlon(0, 0)
ts = load.timescale()
point_in_time = ts.utc(2022, 8, 1)
point_in_space = Barycentric([1.2345, 1.2345, 1.2345])
location.at(point_in_time).observe(point_in_space) EDIT: After some more digging through the docs and source code, I'm starting to believe I need to inherit from |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
If I understood things right, I got it working by inheriting from from skyfield.api import load, wgs84
from skyfield.vectorlib import VectorFunction
class ThingInSpace(VectorFunction):
def __init__(self):
# Value 0 corresponds to the solar system barycenter according to this: https://rhodesmill.org/skyfield/api-vectors.html#skyfield.vectorlib.VectorFunction.center
self.center = 0
@property
def target(self):
# This is a property to avoid circular references as described here: https://github.com/skyfielders/python-skyfield/blob/master/skyfield/planetarylib.py#L222
return self
def _at(self, t):
# Position vector
p = [1.2345, 1.2345, 1.2345]
# Velocity vector
v = [0.0, 0.0, 0.0]
return p, v, self.center, "Thing in space"
planets = load('de421.bsp')
earth = planets['earth']
location = earth + wgs84.latlon(0, 0)
ts = load.timescale()
point_in_time = ts.utc(2022, 8, 1)
point_in_space = ThingInSpace()
astrometric = location.at(point_in_time).observe(point_in_space)
print(astrometric.radec()) It'd be great if someone could confirm whether this is the way to go. |
Beta Was this translation helpful? Give feedback.
If I understood things right, I got it working by inheriting from
VectorFunction
like this: