I'm trying to write a program to calculate what planets are above the horizon at a given time, and the direction in the sky the planets are, but I'm getting incorrect results. My code is below, does anyone have any idea what the issue might be?
import numpy as np
import skyfield
from skyfield.api import load
planets = load('de441.bsp')
ts = load.timescale()
earth = planets['earth']
other_planets = [planets['mercury barycenter'], planets['venus barycenter'], planets['mars barycenter'], planets['jupiter barycenter'], planets['saturn barycenter']]
other_planet_names = ["Mercury", "Venus", "Mars", "Jupiter", "Saturn"]
directions = ["North", "Northeast", "East", "Southeast", "South", "Southwest", "West", "Northwest"]
def planets_visible(time):
numPlanetsViewed = 0
for i in range (0, 5):
az, dec, distance = earth.at(time).observe(other_planets[i]).radec()
if dec._degrees > 0:
numPlanetsViewed = numPlanetsViewed + 1
string = other_planet_names[i] + " is " + str(int((round(dec._degrees, 0)))) + " degrees above the horizon!"
print(string)
direction = int(np.floor(((az._degrees - 22.5) % 360) / 45))
string2 = " It is visible to the " + directions[direction] + "."
print(string2)
print(" ")
if numPlanetsViewed == 0:
print("Sorry, none of the four major planets are visible at this time!")
now = ts.now()
planets_visible(now)
I keep getting that, say, right now (4/7/2021, ~4:00 PM), the right planets are visible – yay! – but the azimuths are all off, saying Mars is NE when it's SE, for example (and I can't speak for the right ascensions, since I don't know them at the moment, but I think those are off too.) Does anyone know what' s up?