Skip to content

Commit

Permalink
For #940, detect when Sun fails to set in Arctic
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-rhodes committed Feb 7, 2024
1 parent b0abf97 commit 4f397d2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion skyfield/almanac.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def _find(observer, target, start_time, end_time, horizon_degrees, f):
timebump = ha_adjustment / ha_per_day
t = ts.tt_jd(t.whole, t.tt_fraction + timebump)

is_above_horizon = (desired_ha != 0.0)
is_above_horizon = (desired_ha % pi != 0.0)
return t, is_above_horizon

def find_risings(observer, target, start_time, end_time, horizon_degrees=None):
Expand Down
47 changes: 38 additions & 9 deletions skyfield/documentation/almanac.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,18 @@ For example:
alt, az, dist = harra_observer.at(t).observe(sun).apparent().altaz()

for ti, yi, alti in zip(t.utc_iso(' '), y, alt.degrees):
print('{} {:5} {:.4f}'.format(ti, str(yi), alti))
print('{} {:5} {:.4f}°'.format(ti, str(yi), alti))

.. testoutput::

2022-12-18 10:22:54Z True -0.8333
2022-12-19 10:29:21Z True -0.8333
2022-12-20 10:37:06Z False -0.8387
2022-12-21 10:37:36Z False -0.8464
2022-12-22 10:38:06Z False -0.8461
2022-12-23 10:38:36Z False -0.8380
2022-12-24 10:31:28Z True -0.8333
2022-12-25 10:26:08Z True -0.8333
2022-12-18 10:22:54Z True -0.8333°
2022-12-19 10:29:21Z True -0.8333°
2022-12-20 10:37:06Z False -0.8387°
2022-12-21 10:37:36Z False -0.8464°
2022-12-22 10:38:06Z False -0.8461°
2022-12-23 10:38:36Z False -0.8380°
2022-12-24 10:31:28Z True -0.8333°
2022-12-25 10:26:08Z True -0.8333°

This output shows that right around the winter solstice,
there are four days on which the Sun never quite reaches the horizon,
Expand All @@ -209,6 +209,35 @@ that would qualify for the USNO definition of sunrise.
So Skyfield instead returns the moment when the Sun is closest to the horizon,
with the accompanying value ``False``.

The value ``False`` also accompanies a lower transit
when the sun is up for an entire 24-hour day
and never touches the horizon and sets.

.. testcode::

utqiagvik_alaska = wgs84.latlon(71.2906 * N, 156.7886 * W)
utqiagvik_observer = eph['Earth'] + utqiagvik_alaska

t0 = ts.utc(2023, 6, 21)
t1 = ts.utc(2023, 6, 22)
t, y = almanac.find_settings(utqiagvik_observer, sun, t0, t1)

alt, az, dist = utqiagvik_observer.at(t).observe(sun).apparent().altaz()

for ti, yi, alti in zip(t.utc_iso(' '), y, alt.degrees):
print('{} {:5} {:.4f}°'.format(ti, str(yi), alti))

.. testoutput::

2023-06-21 10:28:55Z False 4.7265°

The Sun at this Alaska location doesn’t reach the horizon on June 21,
and so instead of triumphantly returning
the time at which the sun reached -0.8333°,
Skyfield returns the moment of anti-transit
when the Sun was at its lowest and furthest north —
standing a full 4.7° above the horizon.

Moonrise and moonset
--------------------

Expand Down

0 comments on commit 4f397d2

Please sign in to comment.