/usr/lib/python2.7/dist-packages/cartopy/tests/test_util.py is in python-cartopy 0.14.2+dfsg1-2build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | # (C) British Crown Copyright 2014 - 2016, Met Office
#
# This file is part of cartopy.
#
# cartopy 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.
#
# cartopy 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 cartopy. If not, see <https://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
from nose.tools import raises
import numpy as np
import numpy.ma as ma
from numpy.testing import assert_array_equal
from cartopy.util import add_cyclic_point
class Test_add_cyclic_point(object):
@classmethod
def setup_class(cls):
cls.lons = np.arange(0, 360, 60)
cls.data2d = np.ones([3, 6]) * np.arange(6)
cls.data4d = np.ones([4, 6, 2, 3]) * \
np.arange(6)[..., np.newaxis, np.newaxis]
def test_data_only(self):
c_data = add_cyclic_point(self.data2d)
r_data = np.concatenate((self.data2d, self.data2d[:, :1]), axis=1)
assert_array_equal(c_data, r_data)
def test_data_and_coord(self):
c_data, c_lons = add_cyclic_point(self.data2d, coord=self.lons)
r_data = np.concatenate((self.data2d, self.data2d[:, :1]), axis=1)
r_lons = np.concatenate((self.lons, np.array([360.])))
assert_array_equal(c_data, r_data)
assert_array_equal(c_lons, r_lons)
def test_data_only_with_axis(self):
c_data = add_cyclic_point(self.data4d, axis=1)
r_data = np.concatenate((self.data4d, self.data4d[:, :1]), axis=1)
assert_array_equal(c_data, r_data)
def test_data_and_coord_with_axis(self):
c_data, c_lons = add_cyclic_point(self.data4d, coord=self.lons, axis=1)
r_data = np.concatenate((self.data4d, self.data4d[:, :1]), axis=1)
r_lons = np.concatenate((self.lons, np.array([360.])))
assert_array_equal(c_data, r_data)
assert_array_equal(c_lons, r_lons)
def test_masked_data(self):
new_data = ma.masked_less(self.data2d, 3)
c_data = add_cyclic_point(new_data)
r_data = ma.concatenate((self.data2d, self.data2d[:, :1]), axis=1)
assert_array_equal(c_data, r_data)
@raises(ValueError)
def test_invalid_coord_dimensionality(self):
lons2d = np.repeat(self.lons[np.newaxis], 3, axis=0)
c_data, c_lons = add_cyclic_point(self.data2d, coord=lons2d)
@raises(ValueError)
def test_invalid_coord_size(self):
c_data, c_lons = add_cyclic_point(self.data2d, coord=self.lons[:-1])
@raises(ValueError)
def test_invalid_axis(self):
c_data = add_cyclic_point(self.data2d, axis=-3)
|