skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.38k stars 208 forks source link

Moon Node: convert Julian Day to datetime not correct #968

Closed u-blusky closed 4 weeks ago

u-blusky commented 1 month ago

Hi, I wanted to calculate the position of the Lunar Node on the date: 2999-12-31 23:59:00. When I run the script I get the following output:

['2999-11-14 08:28:15', '2999-11-27 11:41:12', '2999-12-11 19:10:36', '2999-12-24 15:56:12']
[0 1 0 1]
[2816739.80553796 2816752.93952284 2816767.25160169 2816780.11660008]

If I read the data carefully: julian day = 2816780.11660008 corresponds to the date 2999-12-24 15:56:12.

In JPL Horizon App, if I enter JD2816780.11660008 I get this output:

2999-Dec-24 14:47:54.247 2816780.116600081

There is a difference on the calculation of the date:

Skyfield: 2999-12-24 15:56:12 Horizon: 2999-Dec-24 14:47:54.247

I don't understand where I'm wrong.

Thanks a lot, Blu

Python version: 3.8.10 Skyfield version: 1.48 jplephem version: 2.17 sgp4 version: 2.20 Built-in leap seconds table ends with leap second at: 2016-12-31 23:59:60 UTC Built-in ∆T table from finals2000A.all covers: 1973-01-01 to 2025-01-18

Code:

from skyfield.api import Loader
from skyfield import api, almanac

load = Loader('/home/apps/skyfield-data')
ts = api.load.timescale()
ts = load.timescale()
e = api.load('de441_part-2.bsp') 
t1 = ts.utc(2999, 12, 31, 23, 59, 0)
t0 = t1 - 48.0

t, y = almanac.find_discrete(t0, t1, almanac.moon_nodes(e))
strings = t.utc_strftime('%Y-%m-%d %H:%M:%S')
print(strings)
print(y)
print(t.ut1)
u-blusky commented 4 weeks ago

Oops! Sorry Brandon, I finally realized the mistake. If I use the following code the result is correct.

from skyfield.api import Loader
from skyfield import api, almanac

load = Loader('/home/apps/skyfield-data')
ts = api.load.timescale()
ts = load.timescale()
e = api.load('de441_part-2.bsp') 
t1 = ts.utc(2999, 12, 31, 23, 59, 0)
t0 = t1 - 48.0

t, y = almanac.find_discrete(t0, t1, almanac.moon_nodes(e))
strings = t.utc_strftime('%Y-%m-%d %H:%M:%S')
print(strings)
print(y)
tx = ts.tt_jd(t.ut1)
for s in tx.tt_strftime():
    print(s)

Thanks a lot, Blu

brandon-rhodes commented 4 weeks ago

Thanks for reporting back and closing the issue! I have been traveling and didn't find time to respond, so I'm glad you were able to work out the problem.