Calculate planet positions #912
Unanswered
rajatkharbanda
asked this question in
Q&A
Replies: 1 comment
-
In |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to calculate position of planets from a given location on earth, tried running below code. This is given error.
Can someone help what needs to be done to get the desired results.
from skyfield.api import load, Topos
from datetime import datetime
Initialize the Skyfield data source
ts = load.timescale()
eph = load('de421.bsp')
Set the date and time (UTC)
date = datetime(2023, 10, 26, 12, 0, 0)
t = ts.utc(date.year, date.month, date.day, date.hour, date.minute, date.second)
Specify the observer's location on Earth (e.g., New York City)
observer_latitude = 40.7128 # Latitude in degrees
observer_longitude = -74.0060 # Longitude in degrees
observer_elevation = 0 # Elevation in meters
topos = Topos(latitude_degrees=observer_latitude, longitude_degrees=observer_longitude, elevation_m=observer_elevation)
Load planetary ephemerides
planets = eph['planet_barycenter']
Get the positions of the planets from the observer's location
astrometric = (planets + topos).at(t)
Extract the positions of the planets
positions = {
'Sun': astrometric['sun'],
'Mercury': astrometric['mercury'],
'Venus': astrometric['venus'],
'Mars': astrometric['mars barycenter'],
'Jupiter': astrometric['jupiter barycenter'],
'Saturn': astrometric['saturn barycenter'],
'Uranus': astrometric['uranus barycenter'],
'Neptune': astrometric['neptune barycenter'],
'Pluto': astrometric['pluto barycenter'],
}
Print the positions of the planets
for planet, position in positions.items():
ra, dec, distance = position.apparent().radec()
print(f'{planet}: RA={ra.hstr()} Dec={dec.dstr()} Distance={distance.km:.2f} km')
Beta Was this translation helpful? Give feedback.
All reactions