satellogic / orbit-predictor

Python library to propagate satellite orbits.
MIT License
140 stars 43 forks source link

ValueError exception in eclipses_since function #96

Closed eguaio closed 4 years ago

eguaio commented 4 years ago

The following code raises an exception.

from datetime import datetime
from orbit_predictor.predictors.numerical import J2Predictor

start = datetime(2020, 9, 1)
end = datetime(2020, 10, 1)
alt_km = 470.0
pred = J2Predictor.sun_synchronous(
        alt_km=470.0,
        ecc=0.001,
        ltan_h=19,
        ta_deg=0,
        date=start,
      )
list(pred.eclipses_since(when_utc=start, limit_date=end))
astrojuanlu commented 4 years ago

I confirm I can reproduce with the latest released version:

>>> from datetime import datetime
>>> from orbit_predictor.predictors.numerical import J2Predictor
>>> start = datetime(2020, 9, 1)
>>> end = datetime(2020, 10, 1)
>>> alt_km = 470.0
>>> pred = J2Predictor.sun_synchronous(
...         alt_km=470.0,
...         ecc=0.001,
...         ltan_h=19,
...         ta_deg=0,
...         date=start,
...       )
>>> list(pred.eclipses_since(when_utc=start, limit_date=end))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/juanlu/.pyenv/versions/mbp38/lib/python3.8/site-packages/orbit_predictor/predictors/base.py", line 341, in eclipses_since
    eclipse_start_delta_s = brentq(
  File "/home/juanlu/.pyenv/versions/mbp38/lib/python3.8/site-packages/scipy/optimize/zeros.py", line 780, in brentq
    r = _zeros._brentq(f, a, b, xtol, rtol, maxiter, args, full_output, disp)
ValueError: f(a) and f(b) must have different signs

However, with master I get a different (trivial) error:

>>> from datetime import datetime
>>> from orbit_predictor.predictors.numerical import J2Predictor
>>> start = datetime(2020, 9, 1)
>>> end = datetime(2020, 10, 1)
>>> alt_km = 470.0
>>> pred = J2Predictor.sun_synchronous(
...         alt_km=470.0,
...         ecc=0.001,
...         ltan_h=19,
...         ta_deg=0,
...         date=start,
...       )
>>> list(pred.eclipses_since(when_utc=start, limit_date=end))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/juanlu/Development/delivery-platform/mission/orbit-predictor/orbit_predictor/predictors/base.py", line 322, in eclipses_since
    minimum_illumination = minimize_scalar(
NameError: name 'minimize_scalar' is not defined
astrojuanlu commented 4 years ago

It's the same version, but one environment lacked SciPy. It looks like ImportWarning is silenced by default in the interpreter: https://docs.python.org/3.7/library/warnings.html?highlight=importwarning#warning-categories

astrojuanlu commented 4 years ago

I confirm that there is an eclipse, and the problem is in our bracketing:

fig