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

Please handle polar nights and days .. not just fail. #64

Open
AndKe opened this issue Feb 16, 2021 · 5 comments
Open

Please handle polar nights and days .. not just fail. #64

AndKe opened this issue Feb 16, 2021 · 5 comments

Comments

@AndKe
Copy link

AndKe commented Feb 16, 2021

>>> city = LocationInfo("Tromsø", "Norway", "Europe/Tromsø", 69.66, 18.82)
>>> s = sun(city.observer, date=datetime.date(2021, 7, 16))
Traceback (most recent call last):
 File "/home/andre/.local/lib/python3.8/site-packages/astral/sun.py", line 734, in dawn
   return time_of_transit(
 File "/home/andre/.local/lib/python3.8/site-packages/astral/sun.py", line 343, in time_of_transit
   hourangle = hour_angle(
 File "/home/andre/.local/lib/python3.8/site-packages/astral/sun.py", line 243, in hour_angle
   HA = acos(h)
ValueError: math domain error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/home/andre/.local/lib/python3.8/site-packages/astral/sun.py", line 1150, in sun
   "dawn": dawn(observer, date, dawn_dusk_depression, tzinfo),
 File "/home/andre/.local/lib/python3.8/site-packages/astral/sun.py", line 739, in dawn
   raise ValueError(
ValueError: Sun never reaches 6.0 degrees below the horizon, at this location.
>>> 

Instead of error and all, it would be much nicer to return one additional parameter like
s['polar'] "na" or "day" or "night"

@ldo
Copy link

ldo commented Feb 17, 2021

It would make sense to return math.nan in a situation like this.

@AndKe
Copy link
Author

AndKe commented Feb 17, 2021

yes, please, anything that is easy to handle, and preferably indicate whatever it's a polar day or night.

@acrylic-origami
Copy link

+1, related to this, #74 is also looking for a better way to find this out, because the error also isn't always right: sometimes it says polar day when it is actually polar night.

@doctorcolossus
Copy link

+1. I am writing an aurora notification service. I don't want to get notifications during midnight sun, but of course I want them during polar night. Of course it's obvious to me as a human, but I want to write a service that I can let run all the time and forget about. It needs to have different behaviors in these two circumstances, but right now both conditions just throw a ValueError. I guess I could import some second library to figure this out or try to do the math manually, but wouldn't that defeat the purpose of using astral?

@ldo suggested math.nan, but I don't think that's quite right since a datetime isn't a number - how about just None for the missing values, and adding a boolean key to astral.sun.sun like "is_daylight"?

@doctorcolossus
Copy link

I just tried this with ephem and it raises either an AlwaysUpError or a NeverUpError, depending on the case. This seems like a good way to handle the problem.

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

4 participants