astral icon indicating copy to clipboard operation
astral copied to clipboard

Can't get dawn at this location on this day

Open nhoover opened this issue 11 months ago • 2 comments

from astral import LocationInfo
from zoneinfo import ZoneInfo
from datetime import datetime

# Here is a problematic location in Mongolia
z = ZoneInfo('Asia/Ulaanbaatar')
p = LocationInfo('x', 'x', 'Asia/Ulaanbaatar', 46.79, 101.95)

year = 2025
month = 2

for day in [4, 5, 6]:
    print(f'{year}-{month}-{day}: Sunrise {sunrise(p.observer, datetime(year,month,day).astimezone(z), tzinfo=z)}')
    try:
        print(f'{year}-{month}-{day}: Dawn    {dawn(p.observer, datetime(year,month,day).astimezone(z), tzinfo=z)}')
    except ValueError:
        print(f'Could not get dawn for {year}-{month}{day}')```

Produces this with Astral 3.2 and Python 3.13.1:

2025-2-4: Sunrise 2025-02-04 08:33:09.401354+08:00
2025-2-4: Dawn    2025-02-04 08:00:23.477507+08:00
2025-2-5: Sunrise 2025-02-05 08:31:48.131147+08:00
Could not get dawn for 2025-25
2025-2-6: Sunrise 2025-02-06 08:30:25.162764+08:00
2025-2-6: Dawn    2025-02-06 07:57:50.427476+08:00

There's nothing special I can see about this position or these days. 

Also check out Feb 25. But all the rest of the days of the year look fine.

nhoover avatar Feb 07 '25 02:02 nhoover

Here's another one:

# Here's a problematic place in Norway, just above the Arctic circle
z = ZoneInfo('Europe/Oslo')
p = LocationInfo('x', 'x', 'Europe/Oslo', 67.88, 12.98)
print(f'\n{p}')

year = 2025
month = 5
for day in [21, 22, 23, 24, 25, 26]:
    try:
        print(f'{year}-{month:02}-{day:02}: Sunrise {sunrise(p.observer, datetime(year,month,day).astimezone(z), tzinfo=z)}')
    except ValueError:
        print(f'Could not get Sunrise for {year}-{month:02}-{day:02}')

LocationInfo(name='x', region='x', timezone='Europe/Oslo', latitude=67.88, longitude=12.98)
2025-05-21: Sunrise 2025-05-21 02:21:42.785710+02:00
2025-05-22: Sunrise 2025-05-22 02:14:41.780903+02:00
2025-05-23: Sunrise 2025-05-23 02:07:08.157144+02:00
Could not get Sunrise for 2025-05-24
2025-05-25: Sunrise 2025-05-25 01:49:10.855431+02:00
2025-05-26: Sunrise 2025-05-26 01:37:18.380089+02:00

The value for sunrise for 05-24 should be something between the values for the surrounding days.

nhoover avatar Feb 08 '25 22:02 nhoover

2025-03-13 14:45:44.021549+00:00 Lat 30.2873, Lon -82.1901

Is there some repository of non-working times and places? I could probably write 10 failing unit tests from finding sunrise and solar noon for a handful of locations every 15 minutes for about a year.

magnus-bakke avatar Mar 13 '25 14:03 magnus-bakke