如何在Skyfield中添加JulianDate对象或偏移量 [英] How to add JulianDate objects or offsets in Skyfield

查看:108
本文介绍了如何在Skyfield中添加JulianDate对象或偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Skyfield 中的JulianDate对象是一种方便的方法,可以快速产生并保持一组时间值,然后将其传递给Skyfield的at()方法,以计算各种坐标中的天文位置. (请参见示例脚本)

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)

但是,我似乎找不到addoffset方法,以便可以向JulianDate对象添加时间偏移量或可迭代的偏移量.我似乎总是挣扎日期和时间.

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.

这是一个非常简单的抽象示例.我生成的jd60与任意jd0的偏移量为60天.作为一次简单的检查,我两次计算了地球的位置,并确保其移动大约60度.

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']

以任意t_zero开头:

Start with an arbitrary t_zero:

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

现在,使第二个JulianDate对象偏移60天

Now, make a second JulianDate object offset by 60 days

这有效:

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

jd60 = JulianDate(utc=tuple(tim))

但是,我想要的是这样的东西:

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"

给予

60.6215331601
should be roughly 60 degrees

推荐答案

参考这里

我的解决方法如下:

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"

编程愉快.

这篇关于如何在Skyfield中添加JulianDate对象或偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆