Skip to content

Commit

Permalink
Merge pull request #64 from mraspaud/fix-63
Browse files Browse the repository at this point in the history
Fix inappropriate runtime warning
  • Loading branch information
mraspaud committed Aug 7, 2020
2 parents 048d5a0 + a5a7ad6 commit a8a1900
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
28 changes: 14 additions & 14 deletions pyorbital/orbital.py
Expand Up @@ -22,8 +22,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Module for computing the orbital parameters of satellites.
"""
"""Module for computing the orbital parameters of satellites."""

import warnings
from datetime import datetime, timedelta
Expand Down Expand Up @@ -390,18 +389,19 @@ def get_max_parab(fun, start, end, tol=0.01):
f_c = fun(c)

x = b

while True:
x = x - 0.5 * (((b - a) ** 2 * (f_b - f_c)
- (b - c) ** 2 * (f_b - f_a)) /
((b - a) * (f_b - f_c) - (b - c) * (f_b - f_a)))
if np.isnan(x):
return b
if abs(b - x) <= tol:
return x

a, b, c = (a + x) / 2.0, x, (x + c) / 2.0
f_a, f_b, f_c = fun(a), fun(b), fun(c)
with np.errstate(invalid='raise'):
while True:
try:
x = x - 0.5 * (((b - a) ** 2 * (f_b - f_c)
- (b - c) ** 2 * (f_b - f_a)) /
((b - a) * (f_b - f_c) - (b - c) * (f_b - f_a)))
except FloatingPointError:
return b
if abs(b - x) <= tol:
return x

a, b, c = (a + x) / 2.0, x, (x + c) / 2.0
f_a, f_b, f_c = fun(a), fun(b), fun(c)

# every minute
times = utc_time + np.array([timedelta(minutes=minutes)
Expand Down
6 changes: 3 additions & 3 deletions pyorbital/tests/test_geoloc.py
Expand Up @@ -109,10 +109,10 @@ def test_scan_geometry(self):
start_of_scan = np.datetime64(datetime(2014, 1, 8, 11, 30))
times = instrument.times(start_of_scan)

self.assertEquals(times[0, 1], start_of_scan)
self.assertEquals(times[0, 0], start_of_scan -
self.assertEqual(times[0, 1], start_of_scan)
self.assertEqual(times[0, 0], start_of_scan -
np.timedelta64(100, 'ms'))
self.assertEquals(times[0, 2], start_of_scan +
self.assertEqual(times[0, 2], start_of_scan +
np.timedelta64(100, 'ms'))

def test_geodetic_lat(self):
Expand Down
17 changes: 17 additions & 0 deletions pyorbital/tests/test_orbital.py
Expand Up @@ -283,12 +283,29 @@ def _xarr_conv(input):
np.testing.assert_allclose(elev.data.compute(), self.exp_elev)


class TestRegressions(unittest.TestCase):
"""Test regressions."""

def test_63(self):
"""Check that no runtimewarning is raised, #63."""
import warnings
from pyorbital.orbital import Orbital
from dateutil import parser
warnings.filterwarnings('error')
orb = Orbital("Suomi-NPP",
line1="1 37849U 11061A 19292.84582509 .00000011 00000-0 25668-4 0 9997",
line2="2 37849 98.7092 229.3263 0000715 98.5313 290.6262 14.19554485413345")
orb.get_next_passes(parser.parse("2019-10-21 16:00:00"), 12, 123.29736, -13.93763, 0)
warnings.filterwarnings('default')


def suite():
"""The suite for test_orbital
"""
loader = unittest.TestLoader()
mysuite = unittest.TestSuite()
mysuite.addTest(loader.loadTestsFromTestCase(Test))
mysuite.addTest(loader.loadTestsFromTestCase(TestGetObserverLook))
mysuite.addTest(loader.loadTestsFromTestCase(TestRegressions))

return mysuite

0 comments on commit a8a1900

Please sign in to comment.