Python, Bing Chat & Astronomy

I’ve done a degree in Mathematics, as an aside degree and I’m not particularly strong in it but still have an interest. One thing that I’d always wanted to do is to calculate the orbit of a planet with Keplers Orbit equations. It has been of intellectual interest and no practical use really.

I’ve been tinkering with chatGPT and with all the hue and cry about it have dabbled with it. On general text stuff and general questions, eg how to be happy? it gives general replies. When I use it with trying to do code snippets for me, it does very well, it may take a few rephrases of the question but it usually gets there or nearly there with the code I want.

Python Skyfield library

I see it as a practical tool and it can extend knowledge for you, especially in areas where you have little expertise. So I thought I’d use it to do equations and examples for showing examples of formulas to get actual results for demonstrating Keplar’s orbit equations. I have a Obsidian note on my queries to BING Chat on the topic and will follow up on it in a while. Whilst doing this I asked about python Libraries and astronomy for locating astral bodies, it came up with the python Skyfield package to begin with.

I sort of got sidetracked into playing with the package to identify locations of planets at a specific time, and used Stellarium to locate current positions of planets. So I could use the Python script to locate a planet position at a specific time (Now()) and check its position with Stellarium.

With the package you can locate your specific location on the Earth and then find the Azimuth and Altitude of planets.

I was not getting particularly good results when comparing to Stellarium. Although Stellarium seemed to be getting local time wrong and I was having to adjust it manually.

Julian Calendar

I was a little confused with the JULIAN CALENDAR with a NASA converter to convert from Julian time to Timestamp. I still haven’t got my head around this yet but if I explore these scripts further and get more interested in Astronomy then I’ll likely have to take a deeper dive into it. It seems that Julian Year is 365.25 days instead of 365 and leap year every 4th year, so easier to calculate when using formulas. And in the python script it converts it to seconds, a bit like epoch time, but start of julian calendar is 4712 years ago (so 2689 BC by our calendar) and it starts at midday instead of midnight. Sort of makes sense when you think about it.

Julian Day Number:0
Calendar Date/Time:-4712-01-01 12:00:00
(month-abbr. form):-4712-Jan-01 12:00:00
(day-of-year form):-4712–1 12:00:00

Point of View – AltAz or RA & Dec

This did my head in too. Trying to figure out reference planes/spheres for astronomical objects.

The Altitude & Azimuth work with where you are standing, wherever on the World as the Horizon is 0 Altitude, so anything directly overhead is 90 degrees , and anything directly below is -90 degrees. In the Azimuth direction N,S,E W are all used. So you can locate astronomical objects from your physical position. So the Stellarium website is great for this.

The Right Ascension and Declination is a bit ore complicated, I started to do some research into this (ie I watched some YouTube videos) and am still trying to get my head around this. The Vernal Equinox will move over time so you can’t anchor it to a specific longitude and match the 2 reference systems.

Python Astropy library

I had a lot more success with getting planet location to match the Stellarium location of the planet I was trying to identify.

I used Bing chat to find python code that will do this but ran into some trouble with the SkyCoord.from_name(‘Jupiter’) and using planet names as the SkyCoord.from_name() method only does astronomical objects outside of the solar system, and looks up a library SIMBAD Astronomical Database – CDS (Strasbourg) ( for this, to get data on the astronomical objects, so lots of errors when trying to use planets. Bing chat kept on using SkyCoord.from_name() and it took a few questions to get it to offer up other code alternatives.

Current code : I’ve generalised the AstObj at the top so can test a few of them separately against Stellarium and some seem to work out.

from astropy.coordinates import EarthLocation, AltAz, get_body
from astropy.time import Time
import astropy.units as u
import datetime

# AstObject='sun'  #
# AstObject='moon'
# AstObject='mars'
# AstObject='mercury'
# AstObject='venus'
# AstObject='jupiter'
# AstObject='neptune'
# AstObject='uranus'

# Set up location and time  Wellington (-41.2963 * N, 174.7964 * W)
location = EarthLocation(lat=-41.2963*u.deg, lon=174.7964*u.deg, height=10*u.m)
time =     #+0.54166992

# Get coordinates of Jupiter
AstOb = get_body(AstObject, time)

# Calculate altitude and azimuth
altaz = AstOb.transform_to(AltAz(obstime=time, location=location))
altitude =
azimuth =


print(f"{AstObject} Altitude: {altitude:.2f} degrees")
print(f"{AstObject} Azimuth: {azimuth:.2f} degrees")

End comment

I messed around with Skyfield time for a while, hoping to get it to be a bit more accurate, but in the end I found the Astropy library worked pretty much straight off the bat, so I was happy with that.

This has whet my appetite for doing some more astronomy calculations with python.