brandon-rhodes / pyephem

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

Change in behavior -> observer.previous_rising / observer.next_setting in > v4.1.1 #255

Open jminutaglio opened 1 year ago

jminutaglio commented 1 year ago

There has been a change of behavior from PyEphem v4.1.1. to PyEphem 4.1.2+

With this sample code:

import ephem
import concurrent.futures
from concurrent.futures import ThreadPoolExecutor, TimeoutError

def test_code(request):

    test_case_ephem()

    return f'Hello World!' 

####

def test_case_ephem():
    planet_name = 'Moon'
    test_date = '1996/11/07 12:45:00'
    test_lon = '-77.03333333333333'

    for i in range(2):
        try:
            # Create an observer
            observer = ephem.Observer()

            # Set the observer's latitude and longitude
            observer.lat = str('-90.0')
            observer.lon = str(test_lon)

            # Set observer's date to the test date
            observer.date = test_date

            # Get the planet
            planet = getattr(ephem, planet_name.capitalize())()

            # Compute the Ascendant and Descendant times
            # This is the failure condition
            # Create a ThreadPoolExecutor
            with ThreadPoolExecutor(max_workers=2) as executor:
                # Compute the Ascendant and Descendant times
                try:
                    asc_time = executor.submit(observer.previous_rising, planet).result(timeout=60.0)
                    dsc_time = executor.submit(observer.next_setting, planet).result(timeout=60.0)
                except TimeoutError:
                    print(f"ephem version: {ephem.__version__}")
                    print(f"TimeoutError: The calculations for {planet_name} at latitude -90.0 took too long.")
                    executor.shutdown(wait=True)

        except (ephem.NeverUpError, ephem.AlwaysUpError):
            print(f"ephem version: {ephem.__version__}")
            print(f'NeverUpError/AlwaysUpError Exception encountered!')
            pass  # skip this latitude if the planet is never up or always up
        except Exception as e:  # This will catch all other exceptions
            print(f'Exception encountered: {e}')

    return 

in v4.1.1, output is (This is the expected behavior/result) ->

ephem version: 4.1.1
NeverUpError/AlwaysUpError Exception encountered!
ephem version: 4.1.1
NeverUpError/AlwaysUpError Exception encountered!

in v4.1.2+, the output is ->

ephem version: 4.1.2
TimeoutError: The calculations for Moon at latitude -90.0 took too long.

I believe this is a bug/unexpected result.