def test_two_plots_with_independent_axes(self): c1 = Contour(self.cube, self.axes) levels = 5 other = _add_levels(self.cube, levels)[:, 0] c2 = Contour(other, self.axes) browser = Browser([c1, c2]) tcoord = self._tidy(self.cube.coord('time')) zcoord = self._tidy(other.coord('model_level_number')) # Check axis_by_name. taxis = _AxisDefn(dim=0, name='time', size=7, coord=tcoord) zaxis = _AxisDefn(dim=0, name='model_level_number', size=levels, coord=zcoord) axis_by_name = browser._axis_by_name expected = dict(time=taxis, model_level_number=zaxis) self.assertEqual(axis_by_name, expected) # Check plots_by_name. c1_id, c2_id = id(c1), id(c2) plots_by_name = browser._plots_by_name self.assertEqual(set(plots_by_name.keys()), set(['time', 'model_level_number'])) self.assertEqual([id(v) for v in plots_by_name['time']], [c1_id]) self.assertEqual([id(v) for v in plots_by_name['model_level_number']], [c2_id]) # Check names_by_plot_id. names_by_plot_id = browser._names_by_plot_id self.assertEqual(set(names_by_plot_id.keys()), set([c1_id, c2_id])) self.assertEqual(names_by_plot_id[c1_id], ['time']) self.assertEqual(names_by_plot_id[c2_id], ['model_level_number'])
def test_lookup(self): dim, name, size, coord = 0, 1, 2, 4 a = _AxisDefn(dim=dim, name=name, size=size, coord=coord) self.assertEqual(a.dim, dim) self.assertEqual(a.name, name) self.assertEqual(a.size, size) self.assertEqual(a.coord, coord)
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)
def test_single_plot_with_axis(self): plot = Contour(self.cube, self.axes) browser = Browser(plot) name = 'time' coord = self._tidy(self.cube.coord(name)) # Check axis_by_name. axis = _AxisDefn(dim=0, name=name, size=7, coord=coord) expected = dict(time=axis) self.assertEqual(browser._axis_by_name, expected) # Check plots_by_name. plot_id = id(plot) self.assertEqual(browser._plots_by_name.keys(), [name]) self.assertEqual([id(v) for v in browser._plots_by_name[name]], [plot_id]) # Check names_by_plot_id. self.assertEqual(browser._names_by_plot_id.keys(), [plot_id]) self.assertEqual(browser._names_by_plot_id[plot_id], [name])
def test_two_plots_with_shared_axis(self): coords = ('time', 'grid_latitude') c1 = Contour(self.cube, self.axes, coords=coords) c2 = Contour(self.cube, self.axes, coords=coords) browser = Browser([c1, c2]) name = 'grid_longitude' coord = self._tidy(self.cube.coord(name)) # Check axis_by_name. axis = _AxisDefn(dim=2, name=name, size=11, coord=coord) expected = dict(grid_longitude=axis) self.assertEqual(browser._axis_by_name, expected) # Check plots_by_name. c1_id, c2_id = id(c1), id(c2) plots_by_name = browser._plots_by_name self.assertEqual(plots_by_name.keys(), [name]) self.assertEqual(set([id(v) for v in plots_by_name[name]]), set([c1_id, c2_id])) # Check names_by_plot_id. names_by_plot_id = browser._names_by_plot_id self.assertEqual(set(names_by_plot_id.keys()), set([c1_id, c2_id])) self.assertEqual(names_by_plot_id[c1_id], [name]) self.assertEqual(names_by_plot_id[c2_id], [name])
def test_alias_with_defn(self): a1 = _AxisAlias(dim=0, name=1, size=2) a2 = _AxisDefn(dim=0, name=1, size=2, coord=3) self.assertNotEqual(a1, a2)
def test_defn_with_different_coord(self): a1 = _AxisDefn(dim=0, name=1, size=2, coord=3) a2 = _AxisDefn(dim=0, name=1, size=2, coord=30) self.assertNotEqual(a1, a2)
def test_defn_same(self): a1 = _AxisDefn(dim=0, name=1, size=2, coord=3) a2 = _AxisDefn(dim=0, name=1, size=2, coord=3) self.assertEqual(a1, a2)