Astropy is now giving the wrong time and coordinates

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.

New contributor

dronino_matto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật