Pyephem not displaying correct rise and set times

  Kiến thức lập trình

I’m trying to use the python ephem library to calculate the times a given planet will set / rise, but the times I’m getting are way off. The code I’m using is shown below.

import ephem

j = ephem.Jupiter()
p = ephem.Observer()
p.lat = '45.5051'
p.lon = '-122.6750'
p.date = '2024/04/15 00:50:22'
j.compute(p)
if(j.alt < 0):
    print("rising: " + str(p.next_rising(j).datetime()))
else:
    print("setting: " + str(p.next_setting(j).datetime()))
print(j.ra, j.dec)
print(ephem.constellation(j))

The time and date is all accurate to my knowledge. The location is for Portland Oregon, and running the script gives the following.

setting: 2024-04-15 05:04:57.798034
3:13:04.46 17:06:42.0
('Ari', 'Aries')

The time that Jupiter should be setting is around 10pm, but for some reason its giving me 5 am. If anyone knows what I’m doing wrong, I would appreciate some guidance.

LEAVE A COMMENT