如何在Skyfield中添加JulianDate对象或偏移量

编程入门 行业动态 更新时间:2024-10-20 05:27:15
本文介绍了如何在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)

但是,我似乎找不到add或offset方法,以便可以向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对象或偏移量

本文发布于:2023-11-12 04:08:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580478.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   偏移量   如何在   JulianDate   Skyfield

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!