You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code computes the noon time and elevation of any given day.
Then it uses the elevation to compute the time of that given day at the previously obtained elevation, yet it claims that the elevation is not reached on that day.
import pytz
import datetime
from astral.sun import sun, elevation, time_at_elevation
from astral import Observer
LAT = 52.522282527
LON = 13.393107616
TIMEZONE = 'Europe/Berlin'
tz = pytz.timezone(TIMEZONE)
OBSERVER = Observer(LAT, LON, 0)
date = datetime.date(2024, 6, 20) # longest day of the year
date = datetime.date(2024, 12, 21) # shortest day of the year
date = datetime.date.today()
solar_noon = sun(OBSERVER, date=date)['noon']
solar_noon_local = solar_noon.astimezone(tz)
solar_noon_elevation = elevation(OBSERVER, solar_noon_local)
print(f"Solar noon at {solar_noon_local.strftime('%Y-%m-%d %H:%M:%S')} with an elevation of {solar_noon_elevation}\n")
# Adjusted elevation calculation
adjusted_elevation = solar_noon_elevation
# adjusted_elevation = solar_noon_elevation * 0.99 # makes it somewhat safe to compute
# Times for adjusted elevation
noon_at_2 = time_at_elevation(OBSERVER, adjusted_elevation, direction=astral.SunDirection.RISING, date=date)
noon_at_2_local = noon_at_2.astimezone(tz)
print(f"Solar noon at {noon_at_2_local.strftime('%Y-%m-%d %H:%M:%S')} with an elevation of {adjusted_elevation} (rising)\n")
noon_at_3 = time_at_elevation(OBSERVER, adjusted_elevation, direction=astral.SunDirection.SETTING, date=date)
noon_at_3_local = noon_at_3.astimezone(tz)
print(f"Solar noon at {noon_at_3_local.strftime('%Y-%m-%d %H:%M:%S')} with an elevation of {adjusted_elevation} (setting)\n")
This throws an error that ValueError: Sun never reaches an elevation of 60.55323994960828 degrees at this location.
The following code computes the
noon
time and elevation of any given day.Then it uses the elevation to compute the time of that given day at the previously obtained elevation, yet it claims that the elevation is not reached on that day.
This throws an error that
ValueError: Sun never reaches an elevation of 60.55323994960828 degrees at this location.
Related LOC:
astral/src/astral/sun.py
Line 380 in ac23ab5
The text was updated successfully, but these errors were encountered: