Ejemplo n.º 1
0
 def test_coordinate_multi(self):
     coord = AuxCoord(np.ones(self.cube.shape[1:]), long_name='wibble')
     self.cube.add_aux_coord(coord, (1, 2))
     emsg = "x-axis plot coordinate 'wibble' must be a dimension coordinate"
     coords = ('wibble', 'grid_latitude')
     with self.assertRaisesRegexp(ValueError, emsg):
         Plot2D(self.cube, self.axes, coords=coords)
Ejemplo n.º 2
0
 def test_bad_cover_multi(self):
     emsg = "alias 'wibble' cannot cover a 2d coordinate"
     coord = AuxCoord(np.ones(self.cube.shape[1:]), long_name='wibble')
     self.cube.add_aux_coord(coord, (1, 2))
     plot = Plot2D(self.cube, self.axes)
     with self.assertRaisesRegexp(ValueError, emsg):
         plot.alias(wibble=1)
Ejemplo n.º 3
0
 def setUp(self):
     cube = realistic_3d()
     axes = tests.mock.sentinel.axes
     self.draw = tests.mock.sentinel.draw
     self.patcher = self.patch('cube_browser.Plot2D.draw',
                               return_value=self.draw)
     self.plot = Plot2D(cube, axes)
Ejemplo n.º 4
0
 def test(self):
     cube = realistic_3d()
     axes = tests.mock.sentinel.axes
     plot = Plot2D(cube, axes)
     emsg = 'requires a draw method for rendering'
     with self.assertRaisesRegexp(NotImplementedError, emsg):
         plot(time=0)
Ejemplo n.º 5
0
 def test_cover_anonymous_negative(self):
     self.cube.remove_coord('grid_latitude')
     plot = Plot2D(self.cube, self.axes)
     plot.alias(latitude=-2)
     self.assertEqual(len(plot._dim_by_alias), 1)
     self.assertIn('latitude', plot._dim_by_alias)
     self.assertEqual(plot._dim_by_alias['latitude'], 1)
Ejemplo n.º 6
0
 def test_negative_y_dim_greater_than_coord(self):
     coords = ('grid_latitude', -1)
     plot = Plot2D(self.cube, self.axes, coords=coords)
     glat = self.cube.coord('grid_latitude')
     expected = (glat, 1)
     self.assertIsInstance(plot.coords, tuple)
     self.assertEqual(plot.coords, expected)
Ejemplo n.º 7
0
 def test_negative_y_dim_less_than_coord(self):
     coords = ('grid_longitude', -2)
     plot = Plot2D(self.cube, self.axes, coords=coords)
     glon = self.cube.coord('grid_longitude')
     expected = (glon, 0)
     self.assertIsInstance(plot.coords, tuple)
     self.assertEqual(plot.coords, expected)
Ejemplo n.º 8
0
 def test_x_dim_greater_than_coord(self):
     coords = (2, 'grid_latitude')
     plot = Plot2D(self.cube, self.axes, coords=coords)
     glat = self.cube.coord('grid_latitude')
     expected = (1, glat)
     self.assertIsInstance(plot.coords, tuple)
     self.assertEqual(plot.coords, expected)
Ejemplo n.º 9
0
 def test_x_dim_less_than_coord(self):
     coords = (1, 'grid_longitude')
     plot = Plot2D(self.cube, self.axes, coords=coords)
     glon = self.cube.coord('grid_longitude')
     expected = (0, glon)
     self.assertIsInstance(plot.coords, tuple)
     self.assertEqual(plot.coords, expected)
Ejemplo n.º 10
0
 def test_bad_slider_anonymous(self):
     self.cube.remove_coord('time')
     self.cube.remove_coord('forecast_period')
     plot = Plot2D(self.cube, self.axes)
     emsg = ("cube 'air_potential_temperature' has no meta-data "
             'for dimension 0')
     with self.assertRaisesRegexp(ValueError, emsg):
         plot.sliders_axis
Ejemplo n.º 11
0
 def test_coordinates(self):
     coords = ('grid_longitude', 'grid_latitude')
     plot = Plot2D(self.cube, self.axes, coords=coords)
     glat = self.cube.coord('grid_latitude')
     glon = self.cube.coord('grid_longitude')
     expected = (glon, glat)
     self.assertIsInstance(plot.coords, tuple)
     self.assertEqual(plot.coords, expected)
Ejemplo n.º 12
0
 def test_slider_aux_sort(self):
     coords = ('grid_longitude', 'grid_latitude')
     self.cube.remove_coord('time')
     coord = self.cube.coord('forecast_period').copy()
     coord.rename('first')
     self.cube.add_aux_coord(coord, 0)
     plot = Plot2D(self.cube, self.axes, coords=coords)
     expected = dict(first=0)
     self.assertEqual(plot._slider_dim_by_name, expected)
Ejemplo n.º 13
0
 def test_slider_grid_latitude(self):
     coords = ('time', 'grid_longitude')
     plot = Plot2D(self.cube, self.axes, coords=coords)
     original = self.cube.coord('grid_latitude')
     coord = self._tidy(original)
     expected = _AxisDefn(dim=1, name='grid_latitude', size=9, coord=coord)
     actual = plot.sliders_axis
     self.assertEqual(actual, [expected])
     self.assertIsNot(actual[0].coord, original)
Ejemplo n.º 14
0
 def test_remove_all(self):
     self.cube.remove_coord('grid_latitude')
     self.cube.remove_coord('grid_longitude')
     plot = Plot2D(self.cube, self.axes)
     expected = (2, 1)
     args, _ = self.patcher.call_args
     self.assertEqual(len(args), 1)
     self.assertIsInstance(args[0], tuple)
     self.assertEqual(args[0], expected)
Ejemplo n.º 15
0
 def test_aliases(self):
     plot = Plot2D(self.cube, self.axes)
     expected = {}
     aliases = [('wibble', 0), ('wobble', 1), ('bibble', 2)]
     for (name, dim) in aliases:
         expected[name] = dim
         plot.alias(**{name: dim})
     self.assertEqual(plot.aliases, expected)
     self.assertIsNot(plot.aliases, plot._dim_by_alias)
Ejemplo n.º 16
0
 def test_no_slider_from_aux(self):
     coords = ('grid_longitude', 'grid_latitude')
     self.cube.remove_coord('time')
     fp = self.cube.coord('forecast_period')
     self.cube.remove_coord('forecast_period')
     aux = AuxCoord.from_coord(fp)
     self.cube.add_aux_coord(aux, 0)
     plot = Plot2D(self.cube, self.axes, coords=coords)
     self.assertEqual(plot._slider_dim_by_name, {})
Ejemplo n.º 17
0
 def test_default_coords(self):
     plot = Plot2D(self.cube, self.axes)
     glat = self.cube.coord('grid_latitude')
     glon = self.cube.coord('grid_longitude')
     expected = (glon, glat)
     args, _ = self.patcher.call_args
     self.assertEqual(len(args), 1)
     self.assertIsInstance(args[0], tuple)
     self.assertEqual(args[0], expected)
Ejemplo n.º 18
0
 def test_alias_known(self):
     plot = Plot2D(self.cube, self.axes)
     self.assertEqual(len(plot._dim_by_alias), 0)
     plot.alias(wibble=0)
     self.assertEqual(len(plot._dim_by_alias), 1)
     self.assertIn('wibble', plot._dim_by_alias)
     self.assertEqual(plot._dim_by_alias['wibble'], 0)
     plot.remove_alias('wibble')
     self.assertNotIn('wibble', plot._dim_by_alias)
     self.assertEqual(len(plot._dim_by_alias), 0)
Ejemplo n.º 19
0
 def test_slider_slice_warning(self):
     index = 3
     kwargs = dict(grid_longitude=index)
     coords = ('time', 'grid_latitude')
     plot = Plot2D(self.cube, self.axes, coords=coords)
     plot.alias(wibble=2)
     wmsg = ("expected to be called with alias 'wibble' for dimension 2, "
             "rather than with 'grid_longitude'")
     with warnings.catch_warnings():
         # Cause all warnings to raise an exception.
         warnings.simplefilter('error')
         with self.assertRaisesRegexp(UserWarning, wmsg):
             plot(**kwargs)
Ejemplo n.º 20
0
 def test_slider_slice(self):
     index = 5
     kwargs = dict(time=index)
     plot = Plot2D(self.cube, self.axes)
     result = plot(**kwargs)
     self.assertEqual(result, self.draw)
     args, _ = self.patcher.call_args
     expected = plot.cube[index]
     self.assertEqual(args, (expected, ))
     self.assertEqual(plot.subcube, expected)
     cache = plot.cache
     key = tuple(sorted(kwargs.items()))
     self.assertEqual(len(cache.keys()), 1)
     self.assertIn(key, cache)
     self.assertEqual(cache[key], expected)
Ejemplo n.º 21
0
 def test_bad_slider(self):
     plot = Plot2D(self.cube, self.axes)
     emsg = "called with unknown name 'wibble'"
     with self.assertRaisesRegexp(ValueError, emsg):
         plot(wibble=0)
Ejemplo n.º 22
0
 def test_coords_under_specified_dimension(self):
     emsg = 'requires 2 coordinates, one for each plot axis'
     coords = 'time'
     with self.assertRaisesRegexp(ValueError, emsg):
         Plot2D(self.cube, self.axes, coords=coords)
Ejemplo n.º 23
0
 def test_slider_alias(self):
     plot = Plot2D(self.cube, self.axes)
     plot.alias(time=0)
     expected = _AxisAlias(dim=0, name='time', size=7)
     self.assertEqual(plot.sliders_axis, [expected])
Ejemplo n.º 24
0
 def test_invert_mapping(self):
     mapping = dict(one=1, two=2, three=3, four=4)
     expected = {1: 'one', 2: 'two', 3: 'three', 4: 'four'}
     actual = Plot2D._invert_mapping(mapping)
     self.assertEqual(actual, expected)
Ejemplo n.º 25
0
 def test_invert_mapping(self):
     mapping = dict(one=1, two=2, three=3, four=4)
     expected = {1: 'one', 2: 'two', 3: 'three', 4: 'four'}
     actual = Plot2D._invert_mapping(mapping)
     self.assertEqual(actual, expected)
Ejemplo n.º 26
0
 def test_bad_mapping(self):
     mapping = dict(one=1, two=2, three=3, four=1)
     emsg = 'Cannot invert non 1-to-1 mapping'
     with self.assertRaisesRegexp(ValueError, emsg):
         Plot2D._invert_mapping(mapping)
Ejemplo n.º 27
0
 def test_time_and_grid_longitude(self):
     coords = ('time', 'grid_longitude')
     plot = Plot2D(self.cube, self.axes, coords=coords)
     expected = set([0, 2])
     self.assertEqual(plot._plot_dims, expected)
Ejemplo n.º 28
0
 def test_slider_grid_longitude(self):
     coords = ('time', 'grid_latitude')
     plot = Plot2D(self.cube, self.axes, coords=coords)
     expected = dict(grid_longitude=2)
     self.assertEqual(plot._slider_dim_by_name, expected)
Ejemplo n.º 29
0
 def test_coords_over_specified(self):
     emsg = 'requires 2 coordinates, one for each plot axis'
     coords = ('time', 'grid_latitude', 'grid_longitude')
     with self.assertRaisesRegexp(ValueError, emsg):
         Plot2D(self.cube, self.axes, coords=coords)
Ejemplo n.º 30
0
 def test_slider_aux_forecast_period(self):
     coords = ('grid_longitude', 'grid_latitude')
     self.cube.remove_coord('time')
     plot = Plot2D(self.cube, self.axes, coords=coords)
     expected = dict(forecast_period=0)
     self.assertEqual(plot._slider_dim_by_name, expected)
Ejemplo n.º 31
0
 def test_dimension_out_of_range_above(self):
     emsg = 'y-axis plot dimension for 3d cube out of range'
     coords = ('grid_longitude', 3)
     with self.assertRaisesRegexp(IndexError, emsg):
         Plot2D(self.cube, self.axes, coords=coords)
Ejemplo n.º 32
0
 def test_bad_mapping(self):
     mapping = dict(one=1, two=2, three=3, four=1)
     emsg = 'Cannot invert non 1-to-1 mapping'
     with self.assertRaisesRegexp(ValueError, emsg):
         Plot2D._invert_mapping(mapping)