brandon-rhodes / pyephem

Scientific-grade astronomy routines for Python
Other
783 stars 121 forks source link

Endless loop in sunrise computation #258

Open fpinnahub opened 1 year ago

fpinnahub commented 1 year ago

With version 4.1.4 I think there is an endless loop happening in sunrise calculation for some particular latitude, longitude and elevation. I share below an example:

# venv/Lib/site-packages/ephem/__init__.py --> line 490, endless loop
#
# overtake by setting: default_newton_precision = minute

import ephem
from datetime import datetime
from timezonefinder import TimezoneFinder
from pytz import timezone

ephem_obj = ephem.Sun()

latitude = 69.043
longitude = 20.851
elevation = 1009

# Create an observer object
observer = ephem.Observer()

# Set the observer's location
observer.lat = str(latitude)
observer.lon = str(longitude)
observer.elev = elevation

tf = TimezoneFinder()
tz_str = tf.timezone_at(lat=latitude, lng=longitude)
tz = timezone(tz_str)

# Set the observer's date and time in local
observer.date = datetime(2023, 5, 21, 0, 0, 0, 0, tz)

sr = observer.next_rising(ephem_obj)    # Here, endless loop! *****************
sunrise = datetime(*map(int, sr.tuple()), 0, timezone('UTC'))
ss = observer.next_setting(ephem_obj)
sunset = datetime(*map(int, ss.tuple()), 0, timezone('UTC'))

Thanks in advance for your support and work.