Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jminutaglio opened this issue Jun 10, 2023 · 0 comments

Comments

@jminutaglio
Copy link

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

  • the observer.previous_rising / observer.next_setting is no longer calculating (endless loop)
  • the observer.previous_rising / observer.next_setting is no longer throwing a NeverUpError/AlwaysUpError Exception
  • this condition is for certain dates, not every date. I was unable to ID the pattern or range of the problematic dates...

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant