def test_1d_coords(self):
     cube = simple_2d()
     defn = iplt._get_plot_defn_custom_coords_picked(
         cube, ("foo", "bar"), POINT_MODE)
     self.assertEqual([coord.name() for coord in defn.coords],
                      ["bar", "foo"])
     self.assertFalse(defn.transpose)
    def setUp(self):
        # Load a source cube, then generate an interpolator instance, calculate
        # the interpolation weights and set up a target grid.
        self.cube = stock.simple_2d()
        x_points = self.cube.coord('bar').points
        y_points = self.cube.coord('foo').points
        self.interpolator = _RegularGridInterpolator([x_points, y_points],
                                                     self.cube.data,
                                                     method='linear',
                                                     bounds_error=False,
                                                     fill_value=None)
        newx = x_points + 0.7
        newy = y_points + 0.7

        d_0 = self.cube.data[0, 0]
        d_1 = self.cube.data[0, 1]
        d_2 = self.cube.data[1, 0]
        d_3 = self.cube.data[1, 1]
        px_0, px_1 = x_points[0], x_points[1]
        py_0, py_1 = y_points[0], y_points[1]
        px_t = px_0 + 0.7
        py_t = py_0 + 0.7
        dyt_0 = self._interpolate_point(py_t, py_0, py_1, d_0, d_1)
        dyt_1 = self._interpolate_point(py_t, py_0, py_1, d_2, d_3)
        self.test_increment = self._interpolate_point(px_t, px_0, px_1,
                                                      dyt_0, dyt_1)

        xv, yv = np.meshgrid(newy, newx)
        self.tgrid = np.dstack((yv, xv))
        self.weights = self.interpolator.compute_interp_weights(self.tgrid)
 def test_1d_coords_as_integers(self):
     cube = simple_2d()
     defn = iplt._get_plot_defn_custom_coords_picked(
         cube, (1, 0), POINT_MODE
     )
     self.assertEqual([coord for coord in defn.coords], [0, 1])
     self.assertFalse(defn.transpose)
 def test_time_coord_only_in_some_cubes(self):
     list_of_cubes = self.simple_1d_time_cubes()
     cube = stock.simple_2d()
     list_of_cubes.append(cube)
     expected = 'hours since 1970-01-01 00:00:00'
     unify_time_units(list_of_cubes)
     self._common(expected, list_of_cubes)
 def test_1d_coords_swapped(self):
     cube = simple_2d()
     defn = iplt._get_plot_defn_custom_coords_picked(cube, ('bar', 'foo'),
                                                     POINT_MODE)
     self.assertEqual([coord.name() for coord in defn.coords],
                      ['foo', 'bar'])
     self.assertTrue(defn.transpose)
 def test_1d_coords_as_integers_swapped(self):
     cube = simple_2d()
     defn = iplt._get_plot_defn_custom_coords_picked(
         cube, (0, 1), POINT_MODE
     )
     self.assertEqual([coord for coord in defn.coords], [1, 0])
     self.assertTrue(defn.transpose)
 def test_1d_coords_swapped(self):
     cube = simple_2d()
     defn = iplt._get_plot_defn_custom_coords_picked(cube, ('bar', 'foo'),
                                                     POINT_MODE)
     self.assertEqual([coord.name() for coord in defn.coords],
                      ['foo', 'bar'])
     self.assertTrue(defn.transpose)
Exemplo n.º 8
0
    def setUp(self):
        # Load a source cube, then generate an interpolator instance, calculate
        # the interpolation weights and set up a target grid.
        self.cube = stock.simple_2d()
        x_points = self.cube.coord("bar").points
        y_points = self.cube.coord("foo").points
        self.interpolator = _RegularGridInterpolator(
            [x_points, y_points],
            self.cube.data,
            method="linear",
            bounds_error=False,
            fill_value=None,
        )
        newx = x_points + 0.7
        newy = y_points + 0.7

        d_0 = self.cube.data[0, 0]
        d_1 = self.cube.data[0, 1]
        d_2 = self.cube.data[1, 0]
        d_3 = self.cube.data[1, 1]
        px_0, px_1 = x_points[0], x_points[1]
        py_0, py_1 = y_points[0], y_points[1]
        px_t = px_0 + 0.7
        py_t = py_0 + 0.7
        dyt_0 = self._interpolate_point(py_t, py_0, py_1, d_0, d_1)
        dyt_1 = self._interpolate_point(py_t, py_0, py_1, d_2, d_3)
        self.test_increment = self._interpolate_point(
            px_t, px_0, px_1, dyt_0, dyt_1
        )

        xv, yv = np.meshgrid(newy, newx)
        self.tgrid = np.dstack((yv, xv))
        self.weights = self.interpolator.compute_interp_weights(self.tgrid)
Exemplo n.º 9
0
 def test_time_coord_only_in_some_cubes(self):
     list_of_cubes = self.simple_1d_time_cubes()
     cube = stock.simple_2d()
     list_of_cubes.append(cube)
     expected = 'hours since 1970-01-01 00:00:00'
     unify_time_units(list_of_cubes)
     self._common(expected, list_of_cubes)
Exemplo n.º 10
0
 def setUp(self):
     super().setUp()
     self.cube = simple_2d(with_bounds=True)
     self.cube.add_aux_coord(
         AuxCoord(list("abcd"), long_name="str_coord"), 1
     )
     self.lat_lon_cube = lat_lon_cube()
Exemplo n.º 11
0
    def setUp(self):
        self.cube = stock.simple_2d()

        self.scheme = mock.Mock(name='interpolation scheme')
        self.interpolator = mock.Mock(name='interpolator')
        self.interpolator.return_value = mock.sentinel.RESULT
        self.scheme.interpolator.return_value = self.interpolator
        self.collapse_coord = True
Exemplo n.º 12
0
    def setUp(self):
        self.cube = stock.simple_2d()

        self.scheme = mock.Mock(name='interpolation scheme')
        self.interpolator = mock.Mock(name='interpolator')
        self.interpolator.return_value = mock.sentinel.RESULT
        self.scheme.interpolator.return_value = self.interpolator
        self.collapse_coord = True
Exemplo n.º 13
0
 def test_single_cube_with_transform(self):
     transform = lambda cube: {'long_name': 'wibble'}
     target = ConcreteReferenceTarget('foo', transform)
     src = stock.simple_2d()
     target.add_cube(src)
     dest = target.as_cube()
     self.assertEqual(dest.long_name, 'wibble')
     self.assertNotEqual(dest, src)
     dest.long_name = src.long_name
     self.assertEqual(dest, src)
Exemplo n.º 14
0
 def test_single_cube_with_transform(self):
     transform = lambda cube: {'long_name': 'wibble'}
     target = ConcreteReferenceTarget('foo', transform)
     src = stock.simple_2d()
     target.add_cube(src)
     dest = target.as_cube()
     self.assertEqual(dest.long_name, 'wibble')
     self.assertNotEqual(dest, src)
     dest.long_name = src.long_name
     self.assertEqual(dest, src)
Exemplo n.º 15
0
    def test_skip_contour(self):
        # Contours should not be added if data is all below second level.  See #4086.
        cube = simple_2d()

        levels = [5, 15, 20, 200]
        colors = ["b", "r", "y"]

        with mock.patch("matplotlib.pyplot.contour") as mocked_contour:
            iplt.contourf(cube, levels=levels, colors=colors, antialiased=True)

        mocked_contour.assert_not_called()
Exemplo n.º 16
0
 def setUp(self):
     # We have a 2d cube with dimensionality (bar: 3; foo: 4)
     self.cube = simple_2d(with_bounds=False)
     self.foo = self.cube.coord('foo').points
     self.foo_index = np.arange(self.foo.size)
     self.bar = self.cube.coord('bar').points
     self.bar_index = np.arange(self.bar.size)
     self.data = self.cube.data
     self.dataT = self.data.T
     self.mpl_patch = self.patch('matplotlib.pyplot.contour')
     self.draw_func = qplt.contour
Exemplo n.º 17
0
 def setUp(self):
     # We have a 2d cube with dimensionality (bar: 3; foo: 4)
     self.cube = simple_2d(with_bounds=False)
     self.foo = self.cube.coord("foo").points
     self.foo_index = np.arange(self.foo.size)
     self.bar = self.cube.coord("bar").points
     self.bar_index = np.arange(self.bar.size)
     self.data = None
     self.dataT = None
     self.mpl_patch = self.patch("matplotlib.pyplot.scatter")
     self.draw_func = qplt.points
Exemplo n.º 18
0
    def test_single_cube_with_transform(self):
        def transform(cube):
            return {"long_name": "wibble"}

        target = ConcreteReferenceTarget("foo", transform)
        src = stock.simple_2d()
        target.add_cube(src)
        dest = target.as_cube()
        self.assertEqual(dest.long_name, "wibble")
        self.assertNotEqual(dest, src)
        dest.long_name = src.long_name
        self.assertEqual(dest, src)
Exemplo n.º 19
0
    def test_apply_contour_nans(self):
        # Presence of nans should not prevent contours being added.
        cube = simple_2d()
        cube.data = cube.data.astype(np.float_)
        cube.data[0, 0] = np.nan

        levels = [2, 4, 6, 8]
        colors = ["b", "r", "y"]

        with mock.patch("matplotlib.pyplot.contour") as mocked_contour:
            iplt.contourf(cube, levels=levels, colors=colors, antialiased=True)

        mocked_contour.assert_called_once()
Exemplo n.º 20
0
 def setUp(self):
     # We have a 2d cube with dimensionality (bar: 3; foo: 4)
     self.cube = simple_2d(with_bounds=True)
     coord = self.cube.coord('foo')
     self.foo = coord.contiguous_bounds()
     self.foo_index = np.arange(coord.points.size + 1)
     coord = self.cube.coord('bar')
     self.bar = coord.contiguous_bounds()
     self.bar_index = np.arange(coord.points.size + 1)
     self.data = self.cube.data
     self.dataT = self.data.T
     self.mpl_patch = self.patch('matplotlib.pyplot.pcolormesh')
     self.draw_func = qplt.outline
Exemplo n.º 21
0
 def setUp(self):
     # We have a 2d cube with dimensionality (bar: 3; foo: 4)
     self.cube = simple_2d(with_bounds=False)
     self.foo = self.cube.coord('foo').points
     self.foo_index = np.arange(self.foo.size)
     self.bar = self.cube.coord('bar').points
     self.bar_index = np.arange(self.bar.size)
     self.data = self.cube.data
     self.dataT = self.data.T
     mocker = mock.Mock(alpha=0, antialiased=False)
     self.mpl_patch = self.patch('matplotlib.pyplot.contourf',
                                 return_value=mocker)
     self.draw_func = iplt.contourf
Exemplo n.º 22
0
 def setUp(self):
     # We have a 2d cube with dimensionality (bar: 3; foo: 4)
     self.cube = simple_2d(with_bounds=False)
     self.foo = self.cube.coord("foo").points
     self.foo_index = np.arange(self.foo.size)
     self.bar = self.cube.coord("bar").points
     self.bar_index = np.arange(self.bar.size)
     self.data = self.cube.data
     self.dataT = self.data.T
     mocker = mock.Mock(alpha=0, antialiased=False)
     self.mpl_patch = self.patch("matplotlib.pyplot.contourf",
                                 return_value=mocker)
     self.draw_func = iplt.contourf
Exemplo n.º 23
0
 def blockplot_setup(self):
     # We have a 2d cube with dimensionality (bar: 3; foo: 4)
     self.cube = simple_2d(with_bounds=True)
     coord = self.cube.coord('foo')
     self.foo = coord.contiguous_bounds()
     self.foo_index = np.arange(coord.points.size + 1)
     coord = self.cube.coord('bar')
     self.bar = coord.contiguous_bounds()
     self.bar_index = np.arange(coord.points.size + 1)
     self.data = self.cube.data
     self.dataT = self.data.T
     self.draw_func = self.blockplot_func()
     patch_target_name = 'matplotlib.pyplot.' + self.draw_func.__name__
     self.mpl_patch = self.patch(patch_target_name)
Exemplo n.º 24
0
 def blockplot_setup(self):
     # We have a 2d cube with dimensionality (bar: 3; foo: 4)
     self.cube = simple_2d(with_bounds=True)
     coord = self.cube.coord('foo')
     self.foo = coord.contiguous_bounds()
     self.foo_index = np.arange(coord.points.size + 1)
     coord = self.cube.coord('bar')
     self.bar = coord.contiguous_bounds()
     self.bar_index = np.arange(coord.points.size + 1)
     self.data = self.cube.data
     self.dataT = self.data.T
     self.draw_func = self.blockplot_func()
     patch_target_name = 'matplotlib.pyplot.' + self.draw_func.__name__
     self.mpl_patch = self.patch(patch_target_name)
Exemplo n.º 25
0
 def setUp(self):
     # We have a 2d cube with dimensionality (bar: 3; foo: 4)
     self.cube = simple_2d(with_bounds=True)
     coord = self.cube.coord("foo")
     self.foo = coord.contiguous_bounds()
     self.foo_index = np.arange(coord.points.size + 1)
     coord = self.cube.coord("bar")
     self.bar = coord.contiguous_bounds()
     self.bar_index = np.arange(coord.points.size + 1)
     self.data = self.cube.data
     self.dataT = self.data.T
     self.mpl_patch = self.patch("matplotlib.pyplot.pcolor",
                                 return_value=None)
     self.draw_func = qplt.pcolor
Exemplo n.º 26
0
 def setUp(self):
     # We have a 2d cube with dimensionality (bar: 3; foo: 4)
     self.cube = simple_2d(with_bounds=False)
     self.foo = self.cube.coord('foo').points
     self.foo_index = np.arange(self.foo.size)
     self.bar = self.cube.coord('bar').points
     self.bar_index = np.arange(self.bar.size)
     self.data = self.cube.data
     self.dataT = self.data.T
     mocker = mock.Mock(alpha=0, antialiased=False)
     self.mpl_patch = self.patch('matplotlib.pyplot.contourf',
                                 return_value=mocker)
     # Also need to mock the colorbar.
     self.patch('matplotlib.pyplot.colorbar')
     self.draw_func = qplt.contourf
Exemplo n.º 27
0
    def test_apply_contour_nans(self):
        # Presence of nans should not prevent contours being added.
        cube = simple_2d()
        cube.data = cube.data.astype(np.float_)
        cube.data[0, 0] = np.nan

        levels = [2, 4, 6, 8]
        colors = ["b", "r", "y"]

        iplt.contourf(cube, levels=levels, colors=colors, antialiased=True)

        ax = plt.gca()
        # If contour has been called, last collection will be a LineCollection.
        self.assertIsInstance(ax.collections[-1],
                              matplotlib.collections.LineCollection)
Exemplo n.º 28
0
    def test_skip_contour(self):
        # Contours should not be added if data is all below second level.  See #4086.
        cube = simple_2d()

        levels = [5, 15, 20, 200]
        colors = ["b", "r", "y"]

        iplt.contourf(cube, levels=levels, colors=colors, antialiased=True)

        ax = plt.gca()
        # Expect 3 PathCollection objects (one for each colour) and no LineCollection
        # objects.
        for collection in ax.collections:
            self.assertIsInstance(collection,
                                  matplotlib.collections.PathCollection)
        self.assertEqual(len(ax.collections), 3)
Exemplo n.º 29
0
 def test_single(self):
     cubes = [stock.simple_2d()]
     self.assertEqual(concatenate(cubes), cubes)
Exemplo n.º 30
0
 def setUp(self):
     self.cube = stock.simple_2d()
     self.cm = CellMethod('mean', 'foo', '1 hour')
     self.cube.cell_methods = (self.cm, )
Exemplo n.º 31
0
 def test_single_cube_no_transform(self):
     target = ConcreteReferenceTarget("foo")
     src = stock.simple_2d()
     target.add_cube(src)
     self.assertIs(target.as_cube(), src)
Exemplo n.º 32
0
 def setUp(self):
     self.cube = stock.simple_2d()
     self.cm = CellMethod("mean", "foo", "1 hour")
     self.cube.cell_methods = (self.cm, )
Exemplo n.º 33
0
 def setUp(self):
     super(TestGraphicStringCoord, self).setUp()
     self.cube = simple_2d(with_bounds=True)
     self.cube.add_aux_coord(AuxCoord(list("abcd"), long_name="str_coord"), 1)
 def test_1d_coords_as_integers_swapped(self):
     cube = simple_2d()
     defn = iplt._get_plot_defn_custom_coords_picked(cube, (0, 1),
                                                     POINT_MODE)
     self.assertEqual([coord for coord in defn.coords], [1, 0])
     self.assertTrue(defn.transpose)
Exemplo n.º 35
0
 def test_compare_cubes_incompatible(self):
     test_case_a = stock.simple_2d()
     test_case_b = stock.simple_3d()
     test_cubes = [test_case_a, test_case_b]
     self.assertRaises(OSError, ch.compare_cubes, test_cubes)
Exemplo n.º 36
0
 def test_single_cube_no_transform(self):
     target = ConcreteReferenceTarget('foo')
     src = stock.simple_2d()
     target.add_cube(src)
     self.assertIs(target.as_cube(), src)
Exemplo n.º 37
0
 def setUp(self):
     super(TestGraphicStringCoord, self).setUp()
     self.cube = simple_2d(with_bounds=True)
     self.cube.add_aux_coord(AuxCoord(list('abcd'),
                                      long_name='str_coord'), 1)
     self.lat_lon_cube = lat_lon_cube()
Exemplo n.º 38
0
 def setUp(self):
     self.cube = stock.simple_2d()
     self.extrapolation = 'extrapolation_mode'
     self.scheme = mock.Mock(name='linear scheme')
Exemplo n.º 39
0
 def test_multi_equal(self):
     cubes = [stock.simple_2d()] * 2
     self.assertEqual(concatenate(cubes), cubes)
 def test_1d_coords_as_integers(self):
     cube = simple_2d()
     defn = iplt._get_plot_defn_custom_coords_picked(cube, (1, 0),
                                                     POINT_MODE)
     self.assertEqual([coord for coord in defn.coords], [0, 1])
     self.assertFalse(defn.transpose)
Exemplo n.º 41
0
 def setUp(self):
     self.cube = stock.simple_2d()
     self.extrapolation = 'extrapolation_mode'
     self.scheme = mock.Mock(name='linear scheme')
Exemplo n.º 42
0
 def setUp(self):
     self.cube = stock.simple_2d()
     self.cm = CellMethod('mean', 'foo', '1 hour')
     self.cube.cell_methods = (self.cm, )
Exemplo n.º 43
0
 def test_single(self):
     cubes = [stock.simple_2d()]
     self.assertEqual(concatenate(cubes), cubes)
Exemplo n.º 44
0
 def test_axis_order_xy(self):
     cube_xy = simple_2d()
     defn = iplt._get_plot_defn(cube_xy, iris.coords.POINT_MODE)
     self.assertEqual([coord.name() for coord in defn.coords],
                      ['bar', 'foo'])
Exemplo n.º 45
0
 def test_axis_order_yx(self):
     cube_yx = simple_2d()
     cube_yx.transpose()
     defn = iplt._get_plot_defn(cube_yx, iris.coords.POINT_MODE)
     self.assertEqual([coord.name() for coord in defn.coords],
                      ['foo', 'bar'])
Exemplo n.º 46
0
 def test_multi_equal(self):
     cubes = [stock.simple_2d()] * 2
     self.assertEqual(concatenate(cubes), cubes)