sffjunkie / astral

Python calculations for the position of the sun and moon.
Apache License 2.0
241 stars 46 forks source link

Astronomical dawn doesn't occur after astronomical dusk #7

Open jh-12345 opened 7 years ago

jh-12345 commented 7 years ago

Hi!

I've come across a case where astronomical dusk is reported but there is no astronomical dawn following that dusk which, I suppose, should always be the case.

I suspect it has to do with the sun barely reaching 18 degrees below the horizon.

The following program illustrates the issue. Specifically, astronomical dusk occurs on 2017-05-03 at time 01:29:52+02:00 (at the specified location) but there is no astronomical dawn on the same day.

import astral
import datetime

location = astral.Location(("Test name", "Test region", 56.1629, 0, "Europe/Berlin", 0))
date = datetime.date(2017, 5, 3)

location.solar_depression = "astronomical"
yesterday = date - datetime.timedelta(1)
print("Astronomical dusk: " + str(location.dusk(yesterday)))
print("Astronomical dawn: " + str(location.dawn(date)))

I used Python 2.7.12 and Astral 1.3.4.

jh-12345 commented 7 years ago

Hi again. I'm sure not if it's helpful or even a problem but I've noticed that the Location.solar_elevation function returns values that are not entirely consistent with the dusk/dawn functions.

For example, the following program prints the solar elevation at each minute of the day, for the same date and location as above:

import astral
import datetime
import pytz

location = astral.Location(("Test name", "Test region", 56.1629, 0, "Europe/Berlin", 0))
tz = pytz.timezone(location.timezone)

beginning_of_day = tz.localize(datetime.datetime(2017, 5, 3))
for i in range(24*60):
    time = beginning_of_day + datetime.timedelta(minutes=i)
    elev = location.solar_elevation(time)

    print(str(time) + ": " + str(elev))

The following is a sample of the output:

[output omitted]
2017-05-03 01:32:00+02:00: -17.969160095
2017-05-03 01:33:00+02:00: -17.9839581501
2017-05-03 01:34:00+02:00: -17.9981449878
2017-05-03 01:35:00+02:00: -18.0117201924
2017-05-03 01:36:00+02:00: -18.0246833656
2017-05-03 01:37:00+02:00: -18.0370341267
[output omitted]
2017-05-03 02:17:00+02:00: -18.0267245776
2017-05-03 02:18:00+02:00: -18.0138599232
2017-05-03 02:19:00+02:00: -18.0003830874
2017-05-03 02:20:00+02:00: -17.9862944615
2017-05-03 02:21:00+02:00: -17.9715944546
2017-05-03 02:22:00+02:00: -17.956283493
[output omitted]

This shows that, according toLocation.solar_elevation, the sun goes below 18 degrees approximately at 1:34 AM while the dusk time reported by Location.dusk is 1:29:52 AM. And according toLocation.solar_elevation the astronomical dawn should be around 2:19 AM.

I hope this is helpful somehow. :)

Swamp-Ig commented 5 years ago

I've come across the same issue as above. The forward and reverse calculations don't quite match up.

I had a look at the maths but I don't know enough about it to figure it out.