def test_nD_vectors(qtbot): """Test adding nD vectors.""" viewer = Viewer() view = viewer.window.qt_viewer qtbot.addWidget(view) np.random.seed(0) data = 20 * np.random.random((10, 2, 3)) viewer.add_vectors(data) assert np.all(viewer.layers[0].data == data) assert len(viewer.layers) == 1 assert view.layers.vbox_layout.count() == 2 * len(viewer.layers) + 2 assert viewer.dims.ndim == 3 assert view.dims.nsliders == viewer.dims.ndim assert np.sum(view.dims._displayed_sliders) == 1 # Flip dims order displayed viewer.dims.order = [0, 2, 1] assert viewer.dims.order == [0, 2, 1] # Flip dims order including non-displayed viewer.dims.order = [1, 0, 2] assert viewer.dims.order == [1, 0, 2] # Switch to 3D rendering viewer.dims.ndisplay = 3 assert np.sum(view.dims._displayed_sliders) == 0 assert viewer.dims.ndisplay == 3 viewer.dims.ndisplay = 2 assert viewer.dims.ndisplay == 2 # Close the viewer viewer.window.close()
def test_screenshot(qtbot): "Test taking a screenshot" viewer = Viewer() view = viewer.window.qt_viewer qtbot.addWidget(view) np.random.seed(0) # Add image data = np.random.random((10, 15)) viewer.add_image(data) # Add labels data = np.random.randint(20, size=(10, 15)) viewer.add_labels(data) # Add points data = 20 * np.random.random((10, 2)) viewer.add_points(data) # Add vectors data = 20 * np.random.random((10, 2, 2)) viewer.add_vectors(data) # Add shapes data = 20 * np.random.random((10, 4, 2)) viewer.add_shapes(data) # Take screenshot screenshot = viewer.screenshot() assert screenshot.ndim == 3 # Close the viewer viewer.window.close()
def test_add_vectors(qtbot): """Test adding vectors.""" viewer = Viewer() view = viewer.window.qt_viewer qtbot.addWidget(view) np.random.seed(0) data = 20 * np.random.random((10, 2, 2)) viewer.add_vectors(data) assert np.all(viewer.layers[0].data == data) assert len(viewer.layers) == 1 assert view.layers.vbox_layout.count() == 2 * len(viewer.layers) + 2 assert viewer.dims.ndim == 2 assert view.dims.nsliders == viewer.dims.ndim assert np.sum(view.dims._displayed_sliders) == 0 # Switch to 3D rendering mode and back to 2D rendering mode viewer.dims.ndisplay = 3 assert viewer.dims.ndisplay == 3 viewer.dims.ndisplay = 2 assert viewer.dims.ndisplay == 2 # Close the viewer viewer.window.close()
def test_nD_vectors(qtbot): """Test adding nD vectors.""" viewer = Viewer() view = viewer.window.qt_viewer qtbot.addWidget(view) np.random.seed(0) data = 20 * np.random.random((10, 2, 3)) viewer.add_vectors(data) assert np.all(viewer.layers[0].data == data) assert len(viewer.layers) == 1 assert view.layers.vbox_layout.count() == 2 * len(viewer.layers) + 2 assert viewer.dims.ndim == 3 assert view.dims.nsliders == 1 assert np.sum(view.dims._displayed) == 1 # Close the viewer viewer.window.close()
def test_data_change_ndisplay_vectors(qtbot): """Test change data calls for vectors layer with ndisplay change.""" viewer = Viewer() view = viewer.window.qt_viewer qtbot.addWidget(view) np.random.seed(0) data = 20 * np.random.random((10, 2, 3)) layer = viewer.add_vectors(data) visual = view.layer_to_visual[layer] @patch.object(visual, '_on_data_change', wraps=visual._on_data_change) def test_ndisplay_change(mocked_method, ndisplay=3): viewer.dims.ndisplay = ndisplay mocked_method.assert_called_once() # Switch to 3D rendering mode and back to 2D rendering mode test_ndisplay_change(ndisplay=3) test_ndisplay_change(ndisplay=2) # Close the viewer viewer.window.close()