How to add JulianDate objects or offsets to Skyfield

An object JulianDatein Skyfield is a convenient way to quickly create and hold a set of time values ​​in Julian Days, and pass them to the Skyfield method at()to calculate astronomical positions in different coordinates. (see example script )

However, I cannot find a method addor offset, so that I can add a time offset or an iterable bias to the object JulianDate. I always think the struggle with dates and times.

Here is a very simple, abstract example. I generate jd60, which is shifted from arbitrary jd0by 60 days. As a simple check, I calculate the position of the earth twice and make sure that it moves about 60 degrees.

from skyfield.api import load, JulianDate
import numpy as np

data  = load('de421.bsp')
earth = data['earth']

Start with arbitrary t_zero:

jd0 = JulianDate(utc=(2016, 1, 17.4329, 22.8, 4, 39.3))   # (y, m, d, h, m, s)

Now do a second JulianDate object shift of 60 days

It works:

tim = list(jd0.tt_tuple())
tim[2] += 60   # add 60 days (~1/6 of a year)

jd60 = JulianDate(utc=tuple(tim))

But I would like something like:

jd60 = jd0.add(delta_utc=(0, 0, 60, 0, 0, 0)) # ficticious method

Now calculate the positions and find the approximate angle to make sure it worked.

p0  = earth.at(jd0).position.km
p60 = earth.at(jd60).position.km

dot = (p0*p60).sum()

cos_theta = dot / np.sqrt( (p0**2).sum() * (p61**2).sum() )

print (180./np.pi) * np.arccos(cos_theta)
print "should be roughly 60 degrees"

gives

60.6215331601
should be roughly 60 degrees
+1
source share
1 answer

Link here ,

My solution is this:

from skyfield.api import load
import numpy as np

data  = load('de421.bsp')
earth = data['earth']

ts=load.timescale()
t=ts.utc(2016, 1, np.linspace(17.4329,77.4329,61), 22.8, 4, 39.3)

p=earth.at(t)

p0  = p.position.au[:,0]
p60 = p.position.au[:,60]

dot = (p0*p60).sum()

cos_theta = dot / np.sqrt( (p0**2).sum() * (p60**2).sum() )

print (180./np.pi) * np.arccos(cos_theta)
print "should be roughly 60 degrees"

Happy programming.

+1
source

Source: https://habr.com/ru/post/1628456/


All Articles