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

Sun calculation not working correctly for NZ? "Sun never transits at a zenith of 96.0 on 2020-02-11" #44

Closed
therefromhere opened this issue Feb 11, 2020 · 2 comments
Labels

Comments

@therefromhere
Copy link

I'm getting this error with astral==2.0.1 (also with the 2.0.2 tag, and with latest master 60aa65f) when trying to calculate sun data from NZ:

"ValueError: Sun never transits at a zenith of 96.0 on 2020-02-11"

Example:

from astral.geocoder import database, lookup
from astral.sun import sun
import pprint

london = lookup("London", database())
pprint.pprint(sun(london.observer))

outputs something reasonable:

{'dawn': datetime.datetime(2020, 2, 11, 6, 47, 1, 656555, tzinfo=<UTC>),
 'dusk': datetime.datetime(2020, 2, 11, 17, 42, 13, 415600, tzinfo=<UTC>),
 'noon': datetime.datetime(2020, 2, 11, 12, 14, 14, tzinfo=<UTC>),
 'sunrise': datetime.datetime(2020, 2, 11, 7, 22, 40, 881412, tzinfo=<UTC>),
 'sunset': datetime.datetime(2020, 2, 11, 17, 6, 30, 837342, tzinfo=<UTC>)}
wellington = lookup("Wellington", database())
pprint.pprint(sun(wellington.observer))

hits this exception

Traceback (most recent call last):
  File "/home/johnc/.PyCharm2019.3/config/scratches/scratch_10.py", line 11, in <module>
    pprint.pprint(sun(wellington.observer))
  File "/home/johnc/.virtualenvs/sureflap_gcloud/lib/python3.7/site-packages/astral/sun.py", line 1123, in sun
    "dawn": dawn(observer, date, dawn_dusk_depression, tzinfo),
  File "/home/johnc/.virtualenvs/sureflap_gcloud/lib/python3.7/site-packages/astral/sun.py", line 738, in dawn
    observer, date, 90.0 + dep, SunDirection.RISING
  File "/home/johnc/.virtualenvs/sureflap_gcloud/lib/python3.7/site-packages/astral/sun.py", line 380, in time_of_transit
    raise ValueError(f"Sun never transits at a zenith of {zenith} on {date}")
ValueError: Sun never transits at a zenith of 96.0 on 2020-02-11
@sffjunkie
Copy link
Owner

I have uploaded version 2.1 which fixes this bug.

The problem was with sun times that in the UTC timezone that would be on the previous day and I was treating that as an error. This only showed up for time zones with a large positive time offset of which Wellington is one.

@therefromhere
Copy link
Author

Thanks, I can confirm this is working for me now with 2.1.

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

No branches or pull requests

2 participants