skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.41k stars 211 forks source link

Dawn/Dusk #225

Closed Bernmeister closed 4 years ago

Bernmeister commented 5 years ago

In the olden days of PyEphem, to calculate dawn/dusk, I used this for inspiration.

For Skyfield, I have looked at the Topos object (both API and under a debugger) but I don't see a field for horizon (horizon should be set to say -6 degrees for civil twilight).

Is it possible to calculate dawn/dusk in Skyfield (and if so, how)?

brandon-rhodes commented 5 years ago

Twilight calculations would be a nice new feature, so I'll keep this issue open until there's a chance to add them. In the meantime, you could make your own copy of sunrise_sunset:

https://github.com/skyfielders/python-skyfield/blob/e83d751c0b80d2dbb14dcc0038c574ed2b43f69c/skyfield/almanac.py#L178

but instead of the value -0.8333, you would use an even deeper angle — here are the angles used by the Naval Observatory:

https://aa.usno.navy.mil/faq/docs/RST_defs.php#twilight

boonhapus commented 5 years ago

@brandon-rhodes Would you consider it overkill to use your library in place of astral for this sort of thing? This issue is timely, as I found your work here while trying to dig up an old script that used PyEphem. Being able to pinpoint the phases of twilight is very interesting to me.

brandon-rhodes commented 5 years ago

I think that Skyfield times for twilight would more precisely agree with the official numbers from the USNO than would numbers from PyEphem, which might if you measured them be sometimes one minute different because of small differences in its estimation of where the Sun and Earth are. But my guess is that either library would be well within the precision you need, given that dusk and dawn never proceed exactly according to plan anyway because of humidity and air layers and clouds.

What precision does your application need? That's the first question.

ghost commented 5 years ago

Since skyfield uses SPICE kernel files, it should agree to the minute with USNO, assuming it uses an elliptical Earth model (which I'm sure it does). It wouldn't be hard to test against USNO's data.

This isn't exactly helpful, but my https://github.com/barrycarter/bcapps/tree/master/ASTRO/testdata/ contains a bunch of sun/moon rise/set data I collected from USNO ages ago. It does not include twilight data, but confirming sun (and especially moon) rise/set to the nearest minute would probably be useful.

Additionally, if you need more tests cases for twilight, let me know, and I can generate these as well (my https://github.com/barrycarter/bcapps/tree/master/bclib.pl has a get_usno_calendar function that automates getting USNO calendars