1

The JulianDate object in Skyfield is a handy way to quickly produce and hold a set of time values in Julian Days, and pass them to Skyfield's at() method to calculate astronomical positions in various coordinates. (see an example script)

However, I can't seem to find an add or offset method so that I can add a time offset or an iterable of offsets to a JulianDate object. I always seem to struggle with dates and times.

Here is a very simple, abstracted example. I generate jd60 which is offset from an arbitrary jd0 by 60 days. As a simple check I calculate the position of the earth at the two times and make sure it moves by about 60 degrees.

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

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

Start with an arbitrary t_zero:

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

Now, make a second JulianDate object offset by 60 days

This works:

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

jd60 = JulianDate(utc=tuple(tim))

But, what I would like is something like:

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

Now calculate the positions and find the approximate angle, just to see that 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 Answer 1

1

Reference here,

My solution is as follows:

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")
1
  • Excellent! The question was written back in February before the .timescale() method existed. Nice catch!
    – uhoh
    Jun 13, 2016 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.