Python Code to Plot position of planets on RA-DEC Grid
Below is Python Output & Code to "Plot position of planets on RA-DEC Grid".
Change the Setting parameters - Longitude, Latitude and Time.
The comments "#" gives short description of the code. You may need to install the required libraries.
***************************************************************************
from astropy.coordinates import EarthLocation, AltAz, get_sun, get_moon, solar_system_ephemeris, get_body
from astropy.time import Time
import astropy.units as u
import matplotlib.pyplot as plt
def plot_planet_positions(date_time, latitude, longitude):
# Define observer's location
observer_location = EarthLocation(lat=latitude*u.deg, lon=longitude*u.deg, height=0*u.m)
# Define the time of observation
observing_time = Time(date_time)
# List of planets
planets = ['mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune']
# Lists to store RA and DEC values for each planet
ra_values = []
dec_values = []
# Calculate RA and DEC for each planet
with solar_system_ephemeris.set('builtin'):
for planet_name in planets:
planet = get_body(planet_name, observing_time, observer_location)
ra_values.append(planet.ra.deg)
dec_values.append(planet.dec.deg)
# Plotting
plt.figure(figsize=(10, 5))
plt.scatter(ra_values, dec_values, color='blue')
for i, planet_name in enumerate(planets):
plt.text(ra_values[i], dec_values[i], planet_name.capitalize(), fontsize=9, ha='right')
plt.xlabel('Right Ascension (degrees)')
plt.ylabel('Declination (degrees)')
plt.title('Positions of Planets on RA-DEC Grid')
plt.grid(True)
plt.gca().invert_xaxis() # Invert RA axis to match astronomical convention
plt.show()
# Example usage:
date_time = '2024-07-17 20:00:00' # UTC time
latitude = 37.7749 # San Francisco, CA latitude
longitude = -122.4194 # San Francisco, CA longitude
plot_planet_positions(date_time, latitude, longitude)
***************************************************************************
Credits- ChatGPT
Comments
Post a Comment