|
1 | 1 | """Import test for the :mod:`mpl_toolkits.basemap.Basemap` class."""
|
2 | 2 |
|
| 3 | +import datetime as dt |
3 | 4 | try:
|
4 | 5 | import unittest2 as unittest
|
5 | 6 | except ImportError:
|
|
9 | 10 | import matplotlib as mpl
|
10 | 11 | import matplotlib.pyplot as plt
|
11 | 12 | from matplotlib.collections import LineCollection
|
| 13 | +from matplotlib.contour import QuadContourSet |
12 | 14 | from matplotlib.image import AxesImage
|
13 | 15 | from matplotlib.patches import Polygon
|
14 | 16 | from mpl_toolkits.basemap import Basemap
|
@@ -204,6 +206,48 @@ def test_shadedrelief_with_custom_axes(self):
|
204 | 206 | _, axs = plt.subplots()
|
205 | 207 | self.test_shadedrelief(axs=axs, axslen0=10)
|
206 | 208 |
|
| 209 | + def _test_generic_contour_function(self, function): |
| 210 | + """Generic test for the `contour` and `contourf` methods.""" |
| 211 | + |
| 212 | + bmap = Basemap(projection="ortho", lat_0=45, lon_0=-100, resolution=None) |
| 213 | + |
| 214 | + # Create a regular lat/lon grid. |
| 215 | + nlats = 73 |
| 216 | + nlons = 145 |
| 217 | + delta = 2 * np.pi / (nlons - 1) |
| 218 | + indx = np.indices((nlats, nlons)) |
| 219 | + lats = (0.5 * np.pi - delta * indx[0, :, :]) |
| 220 | + lons = (delta * indx[1, :, :]) |
| 221 | + |
| 222 | + # Create some data the regular lat/lon grid. |
| 223 | + mean = 0.50 * np.cos(2 * lats) * ((np.sin(2 * lats))**2 + 2) |
| 224 | + wave = 0.75 * np.cos(4 * lons) * np.sin(2 * lats)**8 |
| 225 | + data = mean + wave |
| 226 | + |
| 227 | + # Compute native map projection coordinates of lat/lon grid. |
| 228 | + x, y = bmap(np.degrees(lons), np.degrees(lats)) |
| 229 | + |
| 230 | + # Contour data over the map and check output. |
| 231 | + cset = getattr(bmap, function)(x, y, data, 15) |
| 232 | + self.assertIsInstance(cset, QuadContourSet) |
| 233 | + |
| 234 | + def test_contour(self): |
| 235 | + """Test drawing contours on a map.""" |
| 236 | + |
| 237 | + self._test_generic_contour_function("contour") |
| 238 | + |
| 239 | + def test_contourf(self): |
| 240 | + """Test drawing filled contours on a map.""" |
| 241 | + |
| 242 | + self._test_generic_contour_function("contourf") |
| 243 | + |
| 244 | + def test_nightshade(self): |
| 245 | + """Test drawing the day/night terminator and night shade on a map.""" |
| 246 | + |
| 247 | + bmap = Basemap(projection="mill", lon_0=180) |
| 248 | + cset = bmap.nightshade(date=dt.datetime(1970, 1, 1)) |
| 249 | + self.assertIsInstance(cset, QuadContourSet) |
| 250 | + |
207 | 251 |
|
208 | 252 | class TestMplToolkitsBasemapBasemapCall(unittest.TestCase):
|
209 | 253 | """Unittest class for :meth:`mpl_toolkits.basemap.Basemap.__call__`."""
|
|
0 commit comments