From abae36fe633a72132df3720307278e36a4acbded Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Fri, 31 Jul 2020 14:31:34 +0200 Subject: [PATCH 1/2] Fix inappropriate runtime warning --- pyorbital/orbital.py | 28 ++++++++++++++-------------- pyorbital/tests/test_geoloc.py | 6 +++--- pyorbital/tests/test_orbital.py | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/pyorbital/orbital.py b/pyorbital/orbital.py index eccc464..05af655 100644 --- a/pyorbital/orbital.py +++ b/pyorbital/orbital.py @@ -22,8 +22,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -"""Module for computing the orbital parameters of satellites. -""" +"""Module for computing the orbital parameters of satellites.""" import warnings from datetime import datetime, timedelta @@ -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) diff --git a/pyorbital/tests/test_geoloc.py b/pyorbital/tests/test_geoloc.py index 34ce123..bf8b99d 100644 --- a/pyorbital/tests/test_geoloc.py +++ b/pyorbital/tests/test_geoloc.py @@ -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): diff --git a/pyorbital/tests/test_orbital.py b/pyorbital/tests/test_orbital.py index 80db2ba..03add2a 100644 --- a/pyorbital/tests/test_orbital.py +++ b/pyorbital/tests/test_orbital.py @@ -283,6 +283,22 @@ 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 """ @@ -290,5 +306,6 @@ def suite(): mysuite = unittest.TestSuite() mysuite.addTest(loader.loadTestsFromTestCase(Test)) mysuite.addTest(loader.loadTestsFromTestCase(TestGetObserverLook)) + mysuite.addTest(loader.loadTestsFromTestCase(TestRegressions)) return mysuite From a5a7ad6a66a406e40e975d297e4ec6ee6ba67b58 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 31 Jul 2020 12:34:50 +0000 Subject: [PATCH 2/2] Fixing style errors. --- pyorbital/orbital.py | 2 +- pyorbital/tests/test_orbital.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyorbital/orbital.py b/pyorbital/orbital.py index 05af655..c2a9e19 100644 --- a/pyorbital/orbital.py +++ b/pyorbital/orbital.py @@ -394,7 +394,7 @@ def get_max_parab(fun, start, end, tol=0.01): 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))) + ((b - a) * (f_b - f_c) - (b - c) * (f_b - f_a))) except FloatingPointError: return b if abs(b - x) <= tol: diff --git a/pyorbital/tests/test_orbital.py b/pyorbital/tests/test_orbital.py index 03add2a..9f4135b 100644 --- a/pyorbital/tests/test_orbital.py +++ b/pyorbital/tests/test_orbital.py @@ -293,8 +293,8 @@ def test_63(self): 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") + 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')