Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Sun never reaches an elevation of ... degrees at this location. #95

Open
danielfaust opened this issue Jun 10, 2024 · 1 comment

Comments

@danielfaust
Copy link

danielfaust commented Jun 10, 2024

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.

Related LOC:

f"Sun never reaches an elevation of {elevation} degrees "

@lulunac27a
Copy link

lulunac27a commented Sep 30, 2024

Python floating point numbers have double-precision type, so it can have floating-point rounding error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants