How to add JulianDate objects or offsets in Skyfield

让人想犯罪 __ 提交于 2019-12-01 12:30:55

问题


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:


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"

Happy programming.



来源:https://stackoverflow.com/questions/35364458/how-to-add-juliandate-objects-or-offsets-in-skyfield

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