Skip to content

Bug: almanac.find_settings returns nan for a valid time range and location #1097

@LucaPizzagalli

Description

@LucaPizzagalli

When using almanac.find_settings the function returns a nan value for one of the timestamps instead of a valid time or raising an error. The accompanying boolean array y_sunset indicates that all values are valid (all True), which is inconsistent with the nan in the timestamp array.

Minimal code example (skyfield version 1.53):

import numpy as np
from skyfield import almanac
from skyfield.api import N, S, E, W, wgs84, load


latitude, longitude = (44.53101, 10.86888)
ts = load.timescale()
eph = load("de421.bsp")
sun = eph["Sun"]
observer = eph["Earth"] + wgs84.latlon(latitude  *  N ,  longitude  *  E )

t0, t1 = ts.utc(2024, 1, 1), ts.utc(2025, 1, 1)
t_sunset, y_sunset = almanac.find_settings(observer, sun, t0, t1)

if not np.all( y_sunset ):
   raise ValueError("One or more times not valid.")

print("-----------------")
print(np.sum(y_sunset))
print(latitude, longitude)
print([t for t in t_sunset[180:190]])

output (notice the nan value):

/.venv/lib/python3.13/site-packages/skyfield/almanac.py:339: RuntimeWarning: invalid value encountered in divide
  return - 2*c / (b + sign * sqrt(discriminant))
-----------------
366
44.53101 10.86888
[<Time tt=2460491.2961994563>, <Time tt=2460492.2961015017>, <Time tt=2460493.2959767403>, <Time tt=2460494.295825144>, <Time tt=2460495.295646698>, <Time tt=2460496.2954414077>, <Time tt=2460497.2952092965>, <Time tt=nan>, <Time tt=2460499.2946648155>, <Time tt=2460500.294352611>]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions