def test_x_data(): m = Movie(dt=1.0 / 14, height_ratio=1.5) img = np.arange(100).reshape(4, 5, 5) m.add_image(img, style='dark_img') a = Animation(m) assert np.allclose(a.x_data, np.arange(4) * 1.0 / 14) m = Movie(dt=0.5, height_ratio=1.5) img = np.arange(1000).reshape(40, 5, 5) m.add_image(img, style='dark_img') a = Animation(m) assert np.allclose(a.x_data, np.arange(40) * 0.5) m = Movie(dt=1) img = np.arange(100).reshape(5, 20) m.add_image(img, animation_type='window', window_size=5) m.add_axis('x', 'y') m.add_trace(np.arange(20)) a = Animation(m) assert np.allclose(a.x_data, np.arange(20) - 5 // 2) m = Movie(dt=1) img = np.arange(100).reshape(5, 20) m.add_image(img, animation_type='window', window_size=7, window_step=2) m.add_axis('x', 'y') m.add_trace(np.arange(20)) a = Animation(m) assert np.allclose(a.x_data, np.arange(20) - 7 // 2)
def test_set_ylim_axis_same_fail(): m = Movie(dt=1.0 / 14) img = np.arange(250).reshape(10, 5, 5) m.add_image(img, style='dark_img') with pytest.raises(RuntimeError) as ex: m.add_axis('test', 'test', ylim_type='same', ylim_value=1) m.add_trace(np.arange(10)) a = Animation(m) a._init_draw() assert 'Tried to have same y limits ' in str(ex.value)
def test_set_ylim_axis_set_fail(): m = Movie(dt=1.0 / 14) img = np.arange(250).reshape(10, 5, 5) m.add_image(img, style='dark_img') data = np.arange(10) with pytest.raises(RuntimeError) as ex: m.add_axis('test', 'test', ylim_type='set', ylim_value=10) m.add_trace(data) a = Animation(m) a._init_draw() assert 'ylim type set to set but len of ylim_value is not len 2' in str( ex.value)
def test_trace(): with pytest.raises(RuntimeError) as ex: m = Movie() m.add_trace(data=[1, 2, 3]) assert 'Please create axis ' in str(ex.value) m = Movie() m.add_axis(x_label='x', y_label='y') m.add_trace(data=[1, 2, 3], color='blue') trace = m.traces[0] assert trace['axis'] == 0 assert np.allclose(trace['data'], [1, 2, 3]) assert trace['kwargs']['color'] == 'blue'
def test_set_ylim_axis_both(): m = Movie(dt=1.0 / 14) img = np.arange(250).reshape(10, 5, 5) m.add_image(img, style='dark_img') data = np.arange(10) m.add_axis('test', 'test', ylim_type='p_both', ylim_value=10) m.add_trace(data) a = Animation(m) a._init_draw() ax = a.trace_axes[-1] y_min, y_max = ax.get_ylim() assert np.isclose(y_min, 0.9) assert np.isclose(y_max, 8.1)
def test_time_label_axis(): m = Movie(dt=1.0 / 14, height_ratio=2) m.add_axis(x_label='x', y_label='y') m.add_trace(data=np.arange(10)) m.add_time_label(color='blue') assert m.labels[0]['x'] == 0.01 assert m.labels[0]['y'] == 0.08 assert np.allclose(m.labels[0]['values'], np.arange(10) / 14.0) assert m.labels[0]['axis'] == 0 assert m.labels[0]['s_format'] == '%.2fs' assert m.labels[0]['size'] == 14 kwargs = m.labels[0]['kwargs'] assert kwargs['color'] == 'blue'
def test_set_ylim_axis_same(): m = Movie(dt=1.0 / 14) img = np.arange(250).reshape(10, 5, 5) m.add_image(img, style='dark_img') data = np.arange(10) m.add_axis('test', 'test', ylim_type='set', ylim_value=(2, 10)) m.add_trace(data) m.add_axis('test', 'test', ylim_type='same', ylim_value=0) m.add_trace(data) m.add_trace(data, axis=1) a = Animation(m) a._init_draw() ax = a.trace_axes[-1] y_min, y_max = ax.get_ylim() assert np.isclose(y_min, 2) assert np.isclose(y_max, 10)
def test_axis(): with pytest.raises(ValueError) as ex: m = Movie() m.add_axis(x_label='x', y_label='y', tight_x='1') assert 'tight_x should be a boolean' in str(ex.value) m = Movie() m.add_axis(x_label='x', y_label='y') axis = m.axes[0] assert axis['x_label'] == 'x' assert axis['y_label'] == 'y' assert axis['style'] == 'dark_trace' assert axis['running_line'] == {'color': 'white', 'lw': 2} assert axis['bottom_left_ticks'] assert axis['ylim_type'] == 'p_top' assert axis['ylim_value'] == 0.1 assert axis['tight_x'] assert axis['label_kwargs'] == {'fontsize': 16} assert axis['legend_kwargs'] == {'frameon': False}
def test_n_axis(): with pytest.raises(RuntimeError) as ex: m = Movie(dt=1.0 / 14, height_ratio=1.5) _ = Animation(m) assert 'At least one image is needed' in str(ex.value) m = Movie(dt=1.0 / 14, height_ratio=1.5) img = np.arange(100).reshape(4, 5, 5) m.add_image(img, style='dark_img') a = Animation(m) a._init_draw() assert a.n_axes == 0 assert a.n_images == 1 m = Movie(dt=1.0 / 14, height_ratio=1.5) img = np.arange(100).reshape(4, 5, 5) m.add_image(img, style='dark_img') m.add_image(img, style='dark_img') a = Animation(m) a._init_draw() assert a.n_axes == 0 assert a.n_images == 2 m = Movie(dt=1.0 / 14, height_ratio=1.5) img = np.arange(100).reshape(4, 5, 5) m.add_image(img, style='dark_img') m.add_axis('x', 'y') with pytest.raises(RuntimeError) as ex: a = Animation(m) a._init_draw() assert 'Axis 0 with no traces' in str(ex.value) m = Movie(dt=1.0 / 14, height_ratio=1.5) img = np.arange(100).reshape(4, 5, 5) m.add_image(img, style='dark_img') m.add_axis('x', 'y') m.add_trace(np.arange(4)) a = Animation(m) a._init_draw() assert a.n_axes == 1 assert a.n_images == 1
def test_ratio_1p5(): m = Movie(dt=1.0 / 14, height_ratio=1.5) img = np.arange(100).reshape(4, 5, 5) m.add_image(img, style='dark_img') a = Animation(m) a._init_draw() assert a.gs.get_geometry() == (1, 1) assert a.gs.get_height_ratios() is None m = Movie(dt=1.0 / 14, height_ratio=1.5) img = np.arange(100).reshape(4, 5, 5) m.add_image(img, style='dark_img') m.add_axis('x', 'y') m.add_trace(np.arange(4)) a = Animation(m) a._init_draw() assert a.gs.get_geometry() == (2, 1) assert a.gs.get_height_ratios() == (1.5, 1) m = Movie(dt=1.0 / 14, height_ratio=1.5) img = np.arange(100).reshape(4, 5, 5) m.add_image(img, style='dark_img') m.add_axis('x', 'y') m.add_trace(np.arange(4)) m.add_axis('x', 'y') m.add_trace(np.arange(4), axis=1) a = Animation(m) a._init_draw() assert a.gs.get_geometry() == (3, 1) assert a.gs.get_height_ratios() == (3, 1, 1)