Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions lib/iris/tests/unit/util/test__is_circular.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
"""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()
2 changes: 1 addition & 1 deletion lib/iris/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down