I tried writing this code using the Astropy package, installed through pip. The code asks the user for an astronomical object, the time and then for the city, then it uses that data with the Skycoord class and it finds the object’s coordinates in Ra/Dec, then a frame is created to convert the Ra/Dec coordinates to Alt/Az.
import math
from email.policy import default
from astropy.coordinates import SkyCoord, EarthLocation, AltAz
from astropy.time import Time
from geopy.geocoders import Nominatim
while True:
# Initializes geocoder
geolocator = Nominatim(user_agent="city_geocoder")
default_city = "Rome"
print(" ---------------------------------------------------------- ")
print("CELESTIAL OBJECT VISIBILITY ASSESSOR")
dso = input("please type identifier for a deep space object (galaxy, cluster or nebula): ")
# Pulls Ra/Dec coordinates of the DSO
try:
astroposition = SkyCoord.from_name(dso)
except Exception as e:
print(f"The object {dso} wasn't found in the database")
continue
print(" ---------------------------------------------------------- ")
# Finds the city
while True:
city_name = input("type city name: ('d' for default) ")
try:
if city_name == "d":
observer_location = geolocator.geocode(default_city)
observer_location = EarthLocation(lat=observer_location.latitude, lon=observer_location.longitude)
city_name = default_city
break
elif len(city_name) < 3:
print("Your city wasn't found")
continue
else:
observer_location = geolocator.geocode(city_name)
observer_location = EarthLocation(lat=observer_location.latitude, lon=observer_location.longitude)
print(f"You chose the city: {city_name}")
break
except Exception as e:
print("Your city wasn't found")
continue
date = input("type date YYYY-MM-DD HH:MM:SS (or 'now'): ")
if date == "now":
specific_time = Time.now()
print(f"Time chosen: {specific_time}")
else:
specific_time = Time(date) # Correctly initialize Time object
print(f"Time chosen: {specific_time}")
# Creates a frame for Ra/Dec - Alt/Az conversion using the input time and the observer location
altaz_frame = AltAz(obstime=specific_time, location=observer_location)
# Transforms the DSO coordinates to Alt/Az
dso_altaz = astroposition.transform_to(altaz_frame)
print(" ")
print(f"{dso}'s alt-az coordinates are: Altitude {dso_altaz.alt}, Azimuth {dso_altaz.az}, at {city_name}")
print(" ")
print("VISIBILITY: ", end=" ")
altitude = dso_altaz.alt.deg
if altitude > 0:
print("above the horizon,", end=" ")
else:
print("under the horizon")
if 20 < altitude < 70:
print("well visible")
elif 0 < altitude < 20:
print("hardly visible")
elif 70 < altitude < 85:
print("visible but Seestar might struggle (very high in the sky)")
elif altitude > 85:
print("visible but Seestar can't track the object (directly overhead)")
print("FIELD ROTATION CALCULATE: ")
sensor_width = 1096
sensor_height = 1936
exposure = 10 # You can change this value based on the length in seconds of your exposure
sensor_diagonal = math.sqrt(math.pow(sensor_width, 2) + math.pow(sensor_height, 2))
earth_rotation = 360 / 23.9344696
degree_lat = observer_location.lat.deg
rad_lat = math.radians(degree_lat)
rad_azimuth = math.radians(dso_altaz.az.deg)
rad_alt = math.radians(dso_altaz.alt.deg)
image_rotation_rate = earth_rotation * math.cos(rad_lat) * math.cos(rad_azimuth) / math.cos(rad_alt)
print(f"image rotation rate: {round(image_rotation_rate, 2)} Arcseconds/second")
image_rot_rad = math.radians(image_rotation_rate)
sensor_movement = math.sin(image_rot_rad / 3600) * sensor_diagonal * exposure
print(f"max sensor movement: {round(sensor_movement, 2)} pixels")
This code used to work perfectly, but after a few hours I noticed that when I used the Time.now()
function to get current time, it was two hours behind. I noticed this after I started adding error handling to the code, but I don’t really think thats the cause. I tried using older versions of the code, and the time was still wrong.
But also, I noticed the coordinates were starting to get wrong too, even I set the time manually. This also started to happen using older versions of the code.
I tried to reinstall and update Astropy but it didn’t work.
dronino_matto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.