def test_Percept_max(): percept = Percept(np.arange(30).reshape((3, 5, 2))) npt.assert_almost_equal(percept.max(), 29) npt.assert_almost_equal(percept.max(axis="frames"), percept.data[..., 1]) npt.assert_almost_equal(percept.max(), percept.data.ravel()[percept.argmax()]) npt.assert_almost_equal(percept.max(axis='frames'), percept.data[..., percept.argmax(axis='frames')]) with pytest.raises(TypeError): percept.max(axis=(0, 1)) with pytest.raises(ValueError): percept.max(axis='invalid')
def test_Percept_plot(): y_range = (-1, 1) x_range = (-2, 2) grid = Grid2D(x_range, y_range) percept = Percept(np.arange(15).reshape((3, 5, 1)), space=grid) # Basic usage of pcolor: ax = percept.plot(kind='pcolor') npt.assert_equal(isinstance(ax, Subplot), True) npt.assert_almost_equal(ax.axis(), [*x_range, *y_range]) frame = percept.max(axis='frames') npt.assert_almost_equal(ax.collections[0].get_clim(), [frame.min(), frame.max()]) # Basic usage of hex: ax = percept.plot(kind='hex') npt.assert_equal(isinstance(ax, Subplot), True) npt.assert_almost_equal( ax.axis(), [percept.xdva[0], percept.xdva[-1], percept.ydva[0], percept.ydva[-1]]) npt.assert_almost_equal( ax.collections[0].get_clim(), [percept.data[..., 0].min(), percept.data[..., 0].max()]) # Verify color map: npt.assert_equal(ax.collections[0].cmap, plt.cm.gray) # Specify figsize: ax = percept.plot(kind='pcolor', figsize=(6, 4)) npt.assert_almost_equal(ax.figure.get_size_inches(), (6, 4)) # Test vmin and vmax ax.clear() ax = percept.plot(vmin=2, vmax=4) npt.assert_equal(ax.collections[0].get_clim(), (2., 4.)) # Invalid calls: with pytest.raises(ValueError): percept.plot(kind='invalid') with pytest.raises(TypeError): percept.plot(ax='invalid')