|
| 1 | +# (C) British Crown Copyright 2018, Met Office |
| 2 | +# |
| 3 | +# This file is part of Iris. |
| 4 | +# |
| 5 | +# Iris is free software: you can redistribute it and/or modify it under |
| 6 | +# the terms of the GNU Lesser General Public License as published by the |
| 7 | +# Free Software Foundation, either version 3 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# Iris is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU Lesser General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU Lesser General Public License |
| 16 | +# along with Iris. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +"""Unit tests for the :class:`iris.coord_systems.Mercator` class.""" |
| 18 | + |
| 19 | +from __future__ import (absolute_import, division, print_function) |
| 20 | +from six.moves import (filter, input, map, range, zip) # noqa |
| 21 | + |
| 22 | +# Import iris.tests first so that some things can be initialised before |
| 23 | +# importing anything else. |
| 24 | +import iris.tests as tests |
| 25 | + |
| 26 | +import cartopy.crs as ccrs |
| 27 | +from iris.coord_systems import GeogCS, Mercator |
| 28 | + |
| 29 | + |
| 30 | +class Test_Mercator__basics(tests.IrisTest): |
| 31 | + def setUp(self): |
| 32 | + self.tm = Mercator(longitude_of_projection_origin=90.0, |
| 33 | + ellipsoid=GeogCS(6377563.396, 6356256.909)) |
| 34 | + |
| 35 | + def test_construction(self): |
| 36 | + self.assertXMLElement(self.tm, ("coord_systems", "Mercator.xml")) |
| 37 | + |
| 38 | + def test_repr(self): |
| 39 | + expected = ("Mercator(longitude_of_projection_origin=90.0, " |
| 40 | + "ellipsoid=GeogCS(semi_major_axis=6377563.396, " |
| 41 | + "semi_minor_axis=6356256.909), " |
| 42 | + "standard_parallel=0.0)") |
| 43 | + self.assertEqual(expected, repr(self.tm)) |
| 44 | + |
| 45 | + |
| 46 | +class Test_Mercator__as_cartopy_crs(tests.IrisTest): |
| 47 | + def test_simple(self): |
| 48 | + # Check that a projection set up with all the defaults is correctly |
| 49 | + # converted to a cartopy CRS. |
| 50 | + merc_cs = Mercator() |
| 51 | + res = merc_cs.as_cartopy_crs() |
| 52 | + expected = ccrs.Mercator(globe=ccrs.Globe()) |
| 53 | + self.assertEqual(res, expected) |
| 54 | + |
| 55 | + def test_extra_kwargs(self): |
| 56 | + # Check that a projection with non-default values is correctly |
| 57 | + # converted to a cartopy CRS. |
| 58 | + longitude_of_projection_origin = 90.0 |
| 59 | + true_scale_lat = 14.0 |
| 60 | + ellipsoid = GeogCS(semi_major_axis=6377563.396, |
| 61 | + semi_minor_axis=6356256.909) |
| 62 | + |
| 63 | + merc_cs = Mercator( |
| 64 | + longitude_of_projection_origin, |
| 65 | + ellipsoid=ellipsoid, |
| 66 | + standard_parallel=true_scale_lat) |
| 67 | + |
| 68 | + expected = ccrs.Mercator( |
| 69 | + central_longitude=longitude_of_projection_origin, |
| 70 | + globe=ccrs.Globe(semimajor_axis=6377563.396, |
| 71 | + semiminor_axis=6356256.909, ellipse=None), |
| 72 | + latitude_true_scale=true_scale_lat) |
| 73 | + |
| 74 | + res = merc_cs.as_cartopy_crs() |
| 75 | + self.assertEqual(res, expected) |
| 76 | + |
| 77 | + |
| 78 | +class Test_as_cartopy_projection(tests.IrisTest): |
| 79 | + def test_simple(self): |
| 80 | + # Check that a projection set up with all the defaults is correctly |
| 81 | + # converted to a cartopy projection. |
| 82 | + merc_cs = Mercator() |
| 83 | + res = merc_cs.as_cartopy_projection() |
| 84 | + expected = ccrs.Mercator(globe=ccrs.Globe()) |
| 85 | + self.assertEqual(res, expected) |
| 86 | + |
| 87 | + def test_extra_kwargs(self): |
| 88 | + longitude_of_projection_origin = 90.0 |
| 89 | + true_scale_lat = 14.0 |
| 90 | + ellipsoid = GeogCS(semi_major_axis=6377563.396, |
| 91 | + semi_minor_axis=6356256.909) |
| 92 | + |
| 93 | + merc_cs = Mercator( |
| 94 | + longitude_of_projection_origin, |
| 95 | + ellipsoid=ellipsoid, |
| 96 | + standard_parallel=true_scale_lat) |
| 97 | + |
| 98 | + expected = ccrs.Mercator( |
| 99 | + central_longitude=longitude_of_projection_origin, |
| 100 | + globe=ccrs.Globe(semimajor_axis=6377563.396, |
| 101 | + semiminor_axis=6356256.909, ellipse=None), |
| 102 | + latitude_true_scale=true_scale_lat) |
| 103 | + |
| 104 | + res = merc_cs.as_cartopy_projection() |
| 105 | + self.assertEqual(res, expected) |
| 106 | + |
| 107 | + |
| 108 | +if __name__ == "__main__": |
| 109 | + tests.main() |
0 commit comments