-2

This script is supposed to get the transit time, get the angle of the transit time, and then get the time when the angle is reached. The two print statements I gave should give equivalent outputs.

import ephem
obs = ephem.Observer()
obs.lat = '30'
obs.long = '30'
sun = ephem.Sun(obs)
obs.date = sun.transit_time

sun.compute(obs)
altitude = sun.alt
obs.horizon = altitude
print(obs.next_setting(ephem.Sun(), use_center = True))

Instead, this is giving me a NeverUpError. That doesn't make any sense. I tried with coordinates of 20,20. It didn't give an error but the times were mismatched.

Traceback (most recent call last): File "test.py", line 11, in print(obs.next_setting(ephem.Sun(), use_center = True)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ephem/init.py", line 498, in next_setting return self._riset_helper(body, start, use_center, False, False) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ephem/init.py", line 466, in _riset_helper d0 = visit_transit() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ephem/init.py", line 410, in visit_transit % (body.name, d)) ephem.NeverUpError: 'Sun' transits below the horizon at 2017/7/12 10:05:39

JobHunter69
  • 1,706
  • 5
  • 25
  • 49
  • please share the actual code you are using. The error message references line 15. You print the variable `transTime`, but never initialize it. This is not the same code that generated the error. – Daren Thomas Jul 11 '17 at 12:37
  • @DarenThomas You can take a look at my past edits. I shortened it a little to make it more readable but it is the same in essence. – JobHunter69 Jul 11 '17 at 12:42
  • 1
    Your shortening to make it "more readable" has made your code not work and the error message you show is not applicable to this code, i.e. likely to put people off trying to help you. Fail. – DisappointedByUnaccountableMod Jul 11 '17 at 12:43

1 Answers1

0

First: following what appears to be an earlier discussion, you do seem to have edited the question into good shape by this point. I can paste it into a file and run it and get the same error.

Second: the problem may be that you are searching for a circumstance called an “osculation” using a solver that is designed instead to find a straight intersection. A routines like next_setting() is expecting to find that at one time of day the sun is above the horizon, then some time later is below the horizon, and then it narrows in on the exact moment when that transition occurs. But you are setting for it the problem of finding the next setting given a horizon that is as high as the sun’s maximum altitude, if I'm reading your code correctly — and given that setup, there will never be a moment when the sun is “up” because it will never be higher (more or less) than its height above the horizon at the moment of transit. When you set the horizon that far up into the sky, in other words, you create what to PyEphem looks like a day without a sunrise, so it sensibly reports to you that it cannot find a sunset.

You say that your goal is to “get the time when the angle is reached” — but isn't that the transit_time itself? I am not sure I understand why the transit_time isn't already exactly the time you are looking for.

Brandon Rhodes
  • 83,755
  • 16
  • 106
  • 147
  • Thanks for the response. I had a function that calculated the time based off angle input. The main body of the script took in an angle to calculate the time where the sun reached that angle. If the angle was out of bounds of the sun, it used the time of the maximum altitude (calculated from transit_time) as input, which is why I needed to go from time -> angle -> time – JobHunter69 Jul 11 '17 at 13:39