diff --git a/lib/iris/tests/unit/util/test__is_circular.py b/lib/iris/tests/unit/util/test__is_circular.py new file mode 100644 index 0000000000..171368274b --- /dev/null +++ b/lib/iris/tests/unit/util/test__is_circular.py @@ -0,0 +1,42 @@ +# (C) British Crown Copyright 2016, Met Office +# +# This file is part of Iris. +# +# Iris is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Iris is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Iris. If not, see . +"""Test function :func:`iris.util._is_circular`.""" + +from __future__ import (absolute_import, division, print_function) +from six.moves import (filter, input, map, range, zip) # noqa + +# import iris tests first so that some things can be initialised before +# importing anything else +import iris.tests as tests + +import numpy as np + +from iris.util import _is_circular + + +class Test(tests.IrisTest): + def test_simple(self): + data = np.arange(12) * 30 + self.assertTrue(_is_circular(data, 360)) + + def test_negative_diff(self): + data = np.arange(12) * -30 + self.assertTrue(_is_circular(data, 360)) + + +if __name__ == '__main__': + tests.main() diff --git a/lib/iris/util.py b/lib/iris/util.py index 7809dade10..3bd42424e0 100644 --- a/lib/iris/util.py +++ b/lib/iris/util.py @@ -1398,7 +1398,7 @@ def _is_circular(points, modulus, bounds=None): if len(points) > 1: diffs = list(set(np.diff(points))) diff = np.mean(diffs) - abs_tol = diff * 1.0e-4 + abs_tol = np.abs(diff * 1.0e-4) diff_approx_equal = np.max(np.abs(diffs - diff)) < abs_tol if diff_approx_equal: circular_value = (points[-1] + diff) % modulus