code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def test_handedness(orientation, expected_handedness):
"""Check that handedness is calculated properly."""
camera = Camera()
camera.orientation = orientation
assert camera.handedness == expected_handedness | Check that handedness is calculated properly. | test_handedness | python | napari/napari | src/napari/components/_tests/test_camera.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_camera.py | BSD-3-Clause |
def test_ndim():
"""
Test number of dimensions including after adding and removing dimensions.
"""
dims = Dims()
assert dims.ndim == 2
dims = Dims(ndim=4)
assert dims.ndim == 4
dims = Dims(ndim=2)
assert dims.ndim == 2
dims.ndim = 10
assert dims.ndim == 10
dims.ndim =... |
Test number of dimensions including after adding and removing dimensions.
| test_ndim | python | napari/napari | src/napari/components/_tests/test_dims.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_dims.py | BSD-3-Clause |
def test_order_when_changing_ndim():
"""
Test order of the dims when changing the number of dimensions.
"""
dims = Dims(ndim=4)
dims.set_range(0, (0, 4, 1))
dims.set_point(0, 2)
dims.ndim = 5
# Test that new dims get appended to the beginning of lists
assert dims.point == (0, 2, 0, ... |
Test order of the dims when changing the number of dimensions.
| test_order_when_changing_ndim | python | napari/napari | src/napari/components/_tests/test_dims.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_dims.py | BSD-3-Clause |
def test_roll_skip_dummy_axis_1():
"""Test basic roll skips axis with length 1."""
dims = Dims(ndim=4)
dims.set_range(0, (0, 0, 1))
dims.set_range(1, (0, 10, 1))
dims.set_range(2, (0, 10, 1))
dims.set_range(3, (0, 10, 1))
assert dims.order == (0, 1, 2, 3)
dims.roll()
assert dims.orde... | Test basic roll skips axis with length 1. | test_roll_skip_dummy_axis_1 | python | napari/napari | src/napari/components/_tests/test_dims.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_dims.py | BSD-3-Clause |
def test_roll_skip_dummy_axis_2():
"""Test basic roll skips axis with length 1 when not first."""
dims = Dims(ndim=4)
dims.set_range(0, (0, 10, 1))
dims.set_range(1, (0, 0, 1))
dims.set_range(2, (0, 10, 1))
dims.set_range(3, (0, 10, 1))
assert dims.order == (0, 1, 2, 3)
dims.roll()
a... | Test basic roll skips axis with length 1 when not first. | test_roll_skip_dummy_axis_2 | python | napari/napari | src/napari/components/_tests/test_dims.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_dims.py | BSD-3-Clause |
def test_roll_skip_dummy_axis_3():
"""Test basic roll skips all axes with length 1."""
dims = Dims(ndim=4)
dims.set_range(0, (0, 10, 1))
dims.set_range(1, (0, 0, 1))
dims.set_range(2, (0, 10, 1))
dims.set_range(3, (0, 0, 1))
assert dims.order == (0, 1, 2, 3)
dims.roll()
assert dims.o... | Test basic roll skips all axes with length 1. | test_roll_skip_dummy_axis_3 | python | napari/napari | src/napari/components/_tests/test_dims.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_dims.py | BSD-3-Clause |
def test_changing_focus():
"""Test changing focus updates the last_used prop."""
# too-few dims, should have no sliders to update
dims = Dims(ndim=2)
assert dims.last_used == 0
dims._focus_down()
dims._focus_up()
assert dims.last_used == 0
dims.ndim = 5
# Note that with no view atta... | Test changing focus updates the last_used prop. | test_changing_focus | python | napari/napari | src/napari/components/_tests/test_dims.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_dims.py | BSD-3-Clause |
def test_actual_shape_grid_disabled():
"""Test actual shape with grid disabled"""
grid = GridCanvas()
assert not grid.enabled
assert grid.actual_shape(9) == (1, 1)
assert grid.position(3, 9) == (0, 0) | Test actual shape with grid disabled | test_actual_shape_grid_disabled | python | napari/napari | src/napari/components/_tests/test_grid.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_grid.py | BSD-3-Clause |
def test_empty_layers_list():
"""
Test instantiating an empty LayerList object
"""
layers = LayerList()
assert len(layers) == 0 |
Test instantiating an empty LayerList object
| test_empty_layers_list | python | napari/napari | src/napari/components/_tests/test_layers_list.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layers_list.py | BSD-3-Clause |
def test_reordering():
"""
Test indexing into a LayerList by name
"""
layers = LayerList()
layer_a = Image(np.random.random((10, 10)), name='image_a')
layer_b = Image(np.random.random((15, 15)), name='image_b')
layer_c = Image(np.random.random((15, 15)), name='image_c')
layers.append(lay... |
Test indexing into a LayerList by name
| test_reordering | python | napari/napari | src/napari/components/_tests/test_layers_list.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layers_list.py | BSD-3-Clause |
def test_remove_linked_layer():
"""Test removing a layer that is linked to other layers"""
layers = LayerList()
layer_a = Image(np.random.random((10, 10)))
layer_b = Image(np.random.random((15, 15)))
layer_c = Image(np.random.random((15, 15)))
layers.extend([layer_a, layer_b, layer_c])
# li... | Test removing a layer that is linked to other layers | test_remove_linked_layer | python | napari/napari | src/napari/components/_tests/test_layers_list.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layers_list.py | BSD-3-Clause |
def test_layers_save_svg(tmpdir, layers, napari_svg_name):
"""Test saving all layer data to an svg."""
pm = npe2.PluginManager.instance()
pm.register(npe2.PluginManifest.from_distribution('napari-svg'))
path = os.path.join(tmpdir, 'layers_file.svg')
# Check file does not exist
assert not os.pa... | Test saving all layer data to an svg. | test_layers_save_svg | python | napari/napari | src/napari/components/_tests/test_layers_list.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layers_list.py | BSD-3-Clause |
def test_world_extent():
"""Test world extent after adding layers."""
layers = LayerList()
# Empty data is taken to be 512 x 512
np.testing.assert_allclose(layers.extent.world[0], (0, 0))
np.testing.assert_allclose(layers.extent.world[1], (511, 511))
np.testing.assert_allclose(layers.extent.ste... | Test world extent after adding layers. | test_world_extent | python | napari/napari | src/napari/components/_tests/test_layers_list.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layers_list.py | BSD-3-Clause |
def test_world_extent_mixed_ndim():
"""Test world extent after adding layers of different dimensionality."""
layers = LayerList()
# Add 3D layer
layer_a = Image(np.random.random((15, 15, 15)), scale=(4, 12, 2))
layers.append(layer_a)
np.testing.assert_allclose(layers.extent.world[0], (0, 0, 0))... | Test world extent after adding layers of different dimensionality. | test_world_extent_mixed_ndim | python | napari/napari | src/napari/components/_tests/test_layers_list.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layers_list.py | BSD-3-Clause |
def test_world_extent_mixed_flipped():
"""Test world extent after adding data with a flip."""
# Flipped data results in a negative scale value which should be
# made positive when taking into consideration for the step size
# calculation
layers = LayerList()
layer = Image(
np.random.ran... | Test world extent after adding data with a flip. | test_world_extent_mixed_flipped | python | napari/napari | src/napari/components/_tests/test_layers_list.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layers_list.py | BSD-3-Clause |
def test_submit_mixed_allows_sync_to_run(layer_slicer):
"""ensure that a blocked async slice doesn't block sync slicing"""
dims = Dims()
layer1 = FakeAsyncLayer()
layer2 = FakeSyncLayer()
with layer1.lock:
blocked = layer_slicer.submit(layers=[layer1], dims=dims)
layer_slicer.submit(... | ensure that a blocked async slice doesn't block sync slicing | test_submit_mixed_allows_sync_to_run | python | napari/napari | src/napari/components/_tests/test_layer_slicer.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layer_slicer.py | BSD-3-Clause |
def test_submit_with_multiple_async_layer_with_all_locked(
layer_slicer,
):
"""ensure that if only all layers are locked, none continue"""
dims = Dims()
layer1 = FakeAsyncLayer()
layer2 = FakeAsyncLayer()
with layer1.lock, layer2.lock:
blocked = layer_slicer.submit(layers=[layer1, layer... | ensure that if only all layers are locked, none continue | test_submit_with_multiple_async_layer_with_all_locked | python | napari/napari | src/napari/components/_tests/test_layer_slicer.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layer_slicer.py | BSD-3-Clause |
def test_submit_task_to_layers_lock(layer_slicer):
"""ensure that if only one layer has a lock, the non-locked layer
can continue"""
dims = Dims()
layer = FakeAsyncLayer()
with layer.lock:
task = layer_slicer.submit(layers=[layer], dims=dims)
assert task in layer_slicer._layers_to_t... | ensure that if only one layer has a lock, the non-locked layer
can continue | test_submit_task_to_layers_lock | python | napari/napari | src/napari/components/_tests/test_layer_slicer.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layer_slicer.py | BSD-3-Clause |
def test_submit_exception_main_thread(layer_slicer):
"""Exception is raised on the main thread from an error on the main
thread immediately when the task is created."""
class FakeAsyncLayerError(FakeAsyncLayer):
def _make_slice_request(self, dims) -> FakeSliceRequest:
raise RuntimeError... | Exception is raised on the main thread from an error on the main
thread immediately when the task is created. | test_submit_exception_main_thread | python | napari/napari | src/napari/components/_tests/test_layer_slicer.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layer_slicer.py | BSD-3-Clause |
def test_submit_exception_subthread_on_result(layer_slicer):
"""Exception is raised on the main thread from an error on a subthread
only after result is called, not upon submission of the task."""
@dataclass(frozen=True)
class FakeSliceRequestError(FakeSliceRequest):
def __call__(self) -> FakeS... | Exception is raised on the main thread from an error on a subthread
only after result is called, not upon submission of the task. | test_submit_exception_subthread_on_result | python | napari/napari | src/napari/components/_tests/test_layer_slicer.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layer_slicer.py | BSD-3-Clause |
def test_submit_with_one_3d_points(layer_slicer):
"""ensure that async slicing of points does not block"""
np.random.seed(0)
num_points = 100
data = np.rint(2.0 * np.random.rand(num_points, 3))
layer = Points(data=data)
# Note: We are directly accessing and locking the _data of layer. This
... | ensure that async slicing of points does not block | test_submit_with_one_3d_points | python | napari/napari | src/napari/components/_tests/test_layer_slicer.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layer_slicer.py | BSD-3-Clause |
def _wait_until_running(future: Future):
"""Waits until the given future is running using a default finite timeout."""
sleep_secs = 0.01
total_sleep_secs = 0
while not future.running():
time.sleep(sleep_secs)
total_sleep_secs += sleep_secs
if total_sleep_secs > DEFAULT_TIMEOUT_SE... | Waits until the given future is running using a default finite timeout. | _wait_until_running | python | napari/napari | src/napari/components/_tests/test_layer_slicer.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layer_slicer.py | BSD-3-Clause |
def _wait_for_response(
task: 'Future[dict[weakref.ReferenceType[Any], Any]]',
) -> dict:
"""Waits until the given slice task is finished and returns its result."""
weak_result = _wait_for_result(task)
result = {}
for weak_layer, response in weak_result.items():
if layer := weak_layer():
... | Waits until the given slice task is finished and returns its result. | _wait_for_response | python | napari/napari | src/napari/components/_tests/test_layer_slicer.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_layer_slicer.py | BSD-3-Clause |
def test_forgot_multichannel_error_hint():
"""Test that a helpful error is raised when channel_axis is not used."""
viewer = ViewerModel()
np.random.seed(0)
data = da.random.random((15, 10, 5))
with pytest.raises(TypeError) as e:
viewer.add_image(data, name=['a', 'b', 'c'])
assert "did y... | Test that a helpful error is raised when channel_axis is not used. | test_forgot_multichannel_error_hint | python | napari/napari | src/napari/components/_tests/test_multichannel.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_multichannel.py | BSD-3-Clause |
def test_multichannel_index_error_hint():
"""Test multichannel error when arg length != n_channels."""
viewer = ViewerModel()
np.random.seed(0)
data = da.random.random((5, 10, 5))
with pytest.raises(IndexError) as e:
viewer.add_image(data, channel_axis=0, name=['a', 'b'])
assert (
... | Test multichannel error when arg length != n_channels. | test_multichannel_index_error_hint | python | napari/napari | src/napari/components/_tests/test_multichannel.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_multichannel.py | BSD-3-Clause |
def test_scale_bar_fixed_length():
"""Test creating scale bar object with fixed length"""
scale_bar = ScaleBarOverlay(length=50)
assert scale_bar.length == 50 | Test creating scale bar object with fixed length | test_scale_bar_fixed_length | python | napari/napari | src/napari/components/_tests/test_scale_bar.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_scale_bar.py | BSD-3-Clause |
def test_rotate_layers(layer_class, data, ndim):
"""Test rotate layers works with all layer types/data"""
viewer = ViewerModel()
layer = add_layer_by_type(viewer, layer_class, data, visible=True)
np.testing.assert_array_equal(
layer.affine.rotate, np.eye(ndim, dtype=float)
)
rotate_layer... | Test rotate layers works with all layer types/data | test_rotate_layers | python | napari/napari | src/napari/components/_tests/test_viewer_keybindings.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_keybindings.py | BSD-3-Clause |
def test_rotate_layers_in_3D():
"""Test that rotate layers is disabled in 3D viewer mode"""
viewer = ViewerModel()
layer = add_layer_by_type(
viewer, Points, np.array([[1, 2, 3]]), visible=True
)
initial_rotation_matrix = layer.affine.rotate[-2:, -2:]
viewer.dims.ndisplay = 3
assert ... | Test that rotate layers is disabled in 3D viewer mode | test_rotate_layers_in_3D | python | napari/napari | src/napari/components/_tests/test_viewer_keybindings.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_keybindings.py | BSD-3-Clause |
def make_viewer_with_three_layers():
"""Helper function to create a viewer with three layers"""
viewer = ViewerModel()
layer1 = Points()
layer2 = Points()
layer3 = Points()
viewer.layers.append(layer1)
viewer.layers.append(layer2)
viewer.layers.append(layer3)
return viewer | Helper function to create a viewer with three layers | make_viewer_with_three_layers | python | napari/napari | src/napari/components/_tests/test_viewer_keybindings.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_keybindings.py | BSD-3-Clause |
def test_add_image_colormap_variants():
"""Test adding image with all valid colormap argument types."""
viewer = ViewerModel()
np.random.seed(0)
data = np.random.random((10, 15))
# as string
assert viewer.add_image(data, colormap='green')
# as string that is valid, but not a default colorma... | Test adding image with all valid colormap argument types. | test_add_image_colormap_variants | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_add_image_accepts_all_arguments_as_sequence():
"""See https://github.com/napari/napari/pull/7089."""
viewer = ViewerModel(ndisplay=3)
img = viewer.add_image(np.random.rand(2, 2))
viewer.add_image(**img._get_state()) | See https://github.com/napari/napari/pull/7089. | test_add_image_accepts_all_arguments_as_sequence | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_add_multiscale_image_with_negative_floats():
"""See https://github.com/napari/napari/issues/5257"""
viewer = ViewerModel()
shapes = [(20, 10), (10, 5)]
data = [np.zeros(s, dtype=np.float64) for s in shapes]
data[0][-4:, -2:] = -1
data[1][-2:, -1:] = -1
viewer.add_image(data, multis... | See https://github.com/napari/napari/issues/5257 | test_add_multiscale_image_with_negative_floats | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_single_point_dims():
"""Test dims of a Points layer with a single 3D point."""
viewer = ViewerModel()
shape = (1, 3)
data = np.zeros(shape)
viewer.add_points(data)
assert all(r == (0.0, 0.0, 1.0) for r in viewer.dims.range) | Test dims of a Points layer with a single 3D point. | test_single_point_dims | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_mix_dims():
"""Test adding images of mixed dimensionality."""
viewer = ViewerModel()
np.random.seed(0)
data = np.random.random((10, 15))
viewer.add_image(data)
assert len(viewer.layers) == 1
assert np.array_equal(viewer.layers[0].data, data)
assert viewer.dims.ndim == 2
dat... | Test adding images of mixed dimensionality. | test_mix_dims | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_new_labels_empty():
"""Test adding new labels layer to empty viewer."""
viewer = ViewerModel()
viewer._new_labels()
assert len(viewer.layers) == 1
assert np.max(viewer.layers[0].data) == 0
assert viewer.dims.ndim == 2
# Default shape when no data is present is 512x512
np.testing... | Test adding new labels layer to empty viewer. | test_new_labels_empty | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_new_labels_image():
"""Test adding new labels layer with image present."""
viewer = ViewerModel()
np.random.seed(0)
data = np.random.random((10, 15))
viewer.add_image(data)
viewer._new_labels()
assert len(viewer.layers) == 2
assert np.max(viewer.layers[1].data) == 0
assert v... | Test adding new labels layer with image present. | test_new_labels_image | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_new_labels_scaled_image():
"""Test adding new labels layer with scaled image present."""
viewer = ViewerModel()
np.random.seed(0)
data = np.random.random((10, 15))
viewer.add_image(data, scale=(3, 3))
viewer._new_labels()
assert len(viewer.layers) == 2
assert np.max(viewer.layer... | Test adding new labels layer with scaled image present. | test_new_labels_scaled_image | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_new_labels_scaled_translated_image():
"""Test adding new labels layer with transformed image present."""
viewer = ViewerModel()
np.random.seed(0)
data = np.random.random((10, 15))
viewer.add_image(data, scale=(3, 3), translate=(20, -5))
viewer._new_labels()
assert len(viewer.layers)... | Test adding new labels layer with transformed image present. | test_new_labels_scaled_translated_image | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_view_centering_with_points_add():
"""Test if the viewer is only centered when the first
points were added
Regression test for issue #3803
"""
image = np.zeros((5, 10, 10))
viewer = ViewerModel()
viewer.add_image(image)
assert tuple(viewer.dims.point) == (2, 4, 4)
viewer.d... | Test if the viewer is only centered when the first
points were added
Regression test for issue #3803
| test_view_centering_with_points_add | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_swappable_dims():
"""Test swapping dims after adding layers."""
viewer = ViewerModel()
np.random.seed(0)
image_data = np.random.random((7, 12, 10, 15))
image_name = viewer.add_image(image_data).name
assert np.array_equal(
viewer.layers[image_name]._data_view, image_data[3, 5, :,... | Test swapping dims after adding layers. | test_swappable_dims | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_add_remove_layer_dims_change():
"""Test dims change appropriately when adding and removing layers."""
np.random.seed(0)
viewer = ViewerModel()
# Check ndim starts at 2
assert viewer.dims.ndim == 2
# Check ndim increase to 3 when 3D data added
data = np.random.random((10, 15, 20))
... | Test dims change appropriately when adding and removing layers. | test_add_remove_layer_dims_change | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_selection():
"""Test only last added is selected."""
viewer = ViewerModel()
viewer.add_image(np.random.random((10, 10)))
assert viewer.layers[0] in viewer.layers.selection
viewer.add_image(np.random.random((10, 10)))
assert viewer.layers.selection == {viewer.layers[-1]}
viewer.add... | Test only last added is selected. | test_selection | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_add_delete_layers():
"""Test adding and deleting layers with different dims."""
viewer = ViewerModel()
np.random.seed(0)
viewer.add_image(np.random.random((5, 5, 10, 15)))
assert len(viewer.layers) == 1
assert viewer.dims.ndim == 4
viewer.add_image(np.random.random((5, 6, 5, 10, 15)... | Test adding and deleting layers with different dims. | test_add_delete_layers | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_active_layer():
"""Test active layer is correct as layer selections change."""
viewer = ViewerModel()
np.random.seed(0)
# Check no active layer present
assert viewer.layers.selection.active is None
# Check added layer is active
viewer.add_image(np.random.random((5, 5, 10, 15)))
... | Test active layer is correct as layer selections change. | test_active_layer | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_active_layer_status_update():
"""Test status updates from active layer on cursor move."""
viewer = ViewerModel()
np.random.seed(0)
viewer.add_image(np.random.random((5, 5, 10, 15)))
viewer.add_image(np.random.random((5, 6, 5, 10, 15)))
assert len(viewer.layers) == 2
assert viewer.la... | Test status updates from active layer on cursor move. | test_active_layer_status_update | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_active_layer_cursor_size():
"""Test cursor size update on active layer."""
viewer = ViewerModel()
np.random.seed(0)
viewer.add_image(np.random.random((10, 10)))
# Base layer has a default cursor size of 1
assert viewer.cursor.size == 1
viewer.add_labels(np.random.randint(0, 10, siz... | Test cursor size update on active layer. | test_active_layer_cursor_size | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_cursor_ndim_matches_layer():
"""Test cursor position ndim matches viewer ndim after update."""
viewer = ViewerModel()
np.random.seed(0)
im = viewer.add_image(np.random.random((10, 10)))
assert viewer.dims.ndim == 2
assert len(viewer.cursor.position) == 2
im.data = np.random.random(... | Test cursor position ndim matches viewer ndim after update. | test_cursor_ndim_matches_layer | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_sliced_world_extent():
"""Test world extent after adding layers and slicing."""
np.random.seed(0)
viewer = ViewerModel()
# Empty data is taken to be 512 x 512
np.testing.assert_allclose(
viewer._sliced_extent_world_augmented[0], (-0.5, -0.5)
)
np.testing.assert_allclose(
... | Test world extent after adding layers and slicing. | test_sliced_world_extent | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_not_mutable_fields(field):
"""Test appropriate fields are not mutable."""
viewer = ViewerModel()
# Check attribute lives on the viewer
assert hasattr(viewer, field)
# Check attribute does not have an event emitter
assert not hasattr(viewer.events, field)
# Check attribute is not s... | Test appropriate fields are not mutable. | test_not_mutable_fields | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_open_or_get_error_multiple_readers(tmp_plugin: DynamicPlugin):
"""Assert error is returned when multiple plugins are available to read."""
viewer = ViewerModel()
tmp2 = tmp_plugin.spawn(register=True)
@tmp_plugin.contribute.reader(filename_patterns=['*.fake'])
def _(path): ...
@tmp2.c... | Assert error is returned when multiple plugins are available to read. | test_open_or_get_error_multiple_readers | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_open_or_get_error_no_plugin():
"""Assert error is raised when no plugin is available."""
viewer = ViewerModel()
with pytest.raises(
NoAvailableReaderError, match='No plugin found capable of reading'
):
viewer._open_or_raise_error(['my_file.fake']) | Assert error is raised when no plugin is available. | test_open_or_get_error_no_plugin | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_open_or_get_error_builtins(builtins: DynamicPlugin, tmp_path):
"""Test builtins is available to read npy files."""
viewer = ViewerModel()
f_pth = tmp_path / 'my-file.npy'
data = np.random.random((10, 10))
np.save(f_pth, data)
added = viewer._open_or_raise_error([str(f_pth)])
asser... | Test builtins is available to read npy files. | test_open_or_get_error_builtins | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_open_or_get_error_cant_find_plugin(tmp_path, builtins: DynamicPlugin):
"""Test user is warned and only plugin used if preferred plugin missing."""
viewer = ViewerModel()
pth = tmp_path / 'my-file.npy'
np.save(pth, np.random.random((10, 10)))
get_settings().plugins.extension2reader = {'*.np... | Test user is warned and only plugin used if preferred plugin missing. | test_open_or_get_error_cant_find_plugin | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_open_or_get_error_no_prefered_plugin_many_available(
tmp_plugin: DynamicPlugin,
):
"""Test MultipleReaderError raised if preferred plugin missing."""
viewer = ViewerModel()
tmp2 = tmp_plugin.spawn(register=True)
@tmp_plugin.contribute.reader(filename_patterns=['*.fake'])
def _(path): .... | Test MultipleReaderError raised if preferred plugin missing. | test_open_or_get_error_no_prefered_plugin_many_available | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_open_sample_invalid_layer_data_tuple(tmp_plugin):
"""Test that sample returning malformed layer data tuple raises error."""
viewer = ViewerModel()
@tmp_plugin.contribute.sample_data
def return_invalid_ldt():
return [('image', np.zeros((10, 10)))]
with pytest.raises(
TypeEr... | Test that sample returning malformed layer data tuple raises error. | test_open_sample_invalid_layer_data_tuple | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_open_sample_null_layer_sentinel(tmp_plugin):
"""Test that sample returning null layer sentinel raises error."""
viewer = ViewerModel()
@tmp_plugin.contribute.sample_data
def return_null_layer():
return [(None,)]
with pytest.raises(
ValueError,
match='Sample "return... | Test that sample returning null layer sentinel raises error. | test_open_sample_null_layer_sentinel | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_make_layer_visible_after_slicing():
"""See https://github.com/napari/napari/issues/6760"""
viewer = ViewerModel(ndisplay=2)
data = np.array([np.ones((2, 2)) * i for i in range(3)])
layer: Image = viewer.add_image(data)
layer.visible = False
assert viewer.dims.current_step[0] != 0
as... | See https://github.com/napari/napari/issues/6760 | test_make_layer_visible_after_slicing | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_reset_view():
"""Test camera angle behavior after a viewer reset."""
viewer = ViewerModel(ndisplay=3)
viewer.add_image(np.random.random((10, 10, 10)))
viewer.camera.angles = (45, 30, 60)
viewer.reset_view()
assert viewer.camera.angles == (0, 0, 90)
viewer.camera.angles = (45, 30, 6... | Test camera angle behavior after a viewer reset. | test_reset_view | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_fit_to_view_center_calculation(ndisplay, expected_center):
"""Test correct center calculation for different dimensions after fit_to_view."""
viewer = ViewerModel(ndisplay=ndisplay)
data = np.random.random((5, 10, 30, 20))
viewer.add_image(data)
# Pan to origin then reset
viewer.camera.... | Test correct center calculation for different dimensions after fit_to_view. | test_fit_to_view_center_calculation | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_fit_to_view_grid():
"""Test grid view adjusts zoom appropriately."""
viewer = ViewerModel()
for _ in range(4):
viewer.add_image(np.random.random((10, 10)))
viewer.fit_to_view()
default_zoom = viewer.camera.zoom
# enable grid and reset view
viewer.grid.enabled = True
vi... | Test grid view adjusts zoom appropriately. | test_fit_to_view_grid | python | napari/napari | src/napari/components/_tests/test_viewer_model.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_model.py | BSD-3-Clause |
def test_paint(modifiers, native, expected_dim):
"""Test painting labels with circle/square brush."""
viewer = ViewerModel()
data = np.random.random((10, 10, 10))
viewer.add_image(data)
viewer.dims.last_used = 0
viewer.dims.set_point(axis=0, value=5)
viewer.dims.set_point(axis=1, value=5)
... | Test painting labels with circle/square brush. | test_paint | python | napari/napari | src/napari/components/_tests/test_viewer_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_viewer_mouse_bindings.py | BSD-3-Clause |
def test_both_scaled_and_translated_images():
"""Test both scaled and translated images."""
viewer = ViewerModel()
np.random.seed(0)
data = np.random.random((10, 10, 10))
viewer.add_image(data, scale=[2, 1, 1])
viewer.add_image(data, scale=[2, 1, 1], translate=[20, 0, 0])
assert viewer.dims.... | Test both scaled and translated images. | test_both_scaled_and_translated_images | python | napari/napari | src/napari/components/_tests/test_world_coordinates.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_world_coordinates.py | BSD-3-Clause |
def test_no_warning_non_affine_slicing():
"""Test no warning if not slicing into an affine."""
viewer = ViewerModel()
np.random.seed(0)
data = np.random.random((10, 10, 10))
viewer.add_image(data, scale=[2, 1, 1], translate=[10, 15, 20])
with warnings.catch_warnings(record=True) as recorded_warn... | Test no warning if not slicing into an affine. | test_no_warning_non_affine_slicing | python | napari/napari | src/napari/components/_tests/test_world_coordinates.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_world_coordinates.py | BSD-3-Clause |
def test_warning_affine_slicing():
"""Test warning if slicing into an affine."""
viewer = ViewerModel()
np.random.seed(0)
data = np.random.random((10, 10, 10))
with pytest.warns(UserWarning) as wrn:
viewer.add_image(
data,
scale=[2, 1, 1],
translate=[10, 1... | Test warning if slicing into an affine. | test_warning_affine_slicing | python | napari/napari | src/napari/components/_tests/test_world_coordinates.py | https://github.com/napari/napari/blob/master/src/napari/components/_tests/test_world_coordinates.py | BSD-3-Clause |
def _raise_protocol_error(obj: Any, protocol: type) -> None:
"""Raise a more helpful error when required protocol members are missing."""
annotations = getattr(protocol, '__annotations__', {})
needed = set(dir(protocol)).union(annotations) - _OBJ_NAMES
missing = needed - set(dir(obj))
message = tran... | Raise a more helpful error when required protocol members are missing. | _raise_protocol_error | python | napari/napari | src/napari/layers/_data_protocols.py | https://github.com/napari/napari/blob/master/src/napari/layers/_data_protocols.py | BSD-3-Clause |
def layer_source(**source_kwargs: Any) -> Generator[None, None, None]:
"""Creates context in which all layers will be given `source_kwargs`.
The module-level variable `_LAYER_SOURCE` holds a set of key-value pairs
that can be used to create a new `Source` object. Any routine in napari
that may result ... | Creates context in which all layers will be given `source_kwargs`.
The module-level variable `_LAYER_SOURCE` holds a set of key-value pairs
that can be used to create a new `Source` object. Any routine in napari
that may result in the creation of a new layer (such as opening a file,
using a particular... | layer_source | python | napari/napari | src/napari/layers/_source.py | https://github.com/napari/napari/blob/master/src/napari/layers/_source.py | BSD-3-Clause |
def unique_id(self) -> Hashable:
"""Unique ID of the layer.
This is guaranteed to be unique to this specific layer instance
over the lifetime of the program.
"""
if self._unique_id is None:
self._unique_id = uuid.uuid4()
return self._unique_id | Unique ID of the layer.
This is guaranteed to be unique to this specific layer instance
over the lifetime of the program.
| unique_id | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _set_loaded(self, loaded: bool) -> None:
"""Set the loaded state and notify a change with the loaded event."""
if self._loaded != loaded:
self._loaded = loaded
self.events.loaded() | Set the loaded state and notify a change with the loaded event. | _set_loaded | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _on_visible_changed(self) -> None:
"""Execute side-effects on this layer related to changes of the visible state."""
if self.visible and self._visible_mode:
self.mode = self._visible_mode
else:
self._visible_mode = self.mode
self.mode = self._modeclass.PAN... | Execute side-effects on this layer related to changes of the visible state. | _on_visible_changed | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _update_dims(self) -> None:
"""Update the dimensionality of transforms and slices when data changes."""
ndim = self._get_ndim()
old_ndim = self._ndim
if old_ndim > ndim:
keep_axes = range(old_ndim - ndim, old_ndim)
self._transforms = self._transforms.set_slic... | Update the dimensionality of transforms and slices when data changes. | _update_dims | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _extent_world(self) -> np.ndarray:
"""Range of layer in world coordinates.
Returns
-------
extent_world : array, shape (2, D)
"""
# Get full nD bounding box
return get_extent_world(self._extent_data, self._data_to_world) | Range of layer in world coordinates.
Returns
-------
extent_world : array, shape (2, D)
| _extent_world | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _extent_world_augmented(self) -> np.ndarray:
"""Range of layer in world coordinates.
Differently from Layer._extent_world, this also includes the "size" of
data points; for example, Point sizes and Image pixel width are included.
Returns
-------
extent_world : array... | Range of layer in world coordinates.
Differently from Layer._extent_world, this also includes the "size" of
data points; for example, Point sizes and Image pixel width are included.
Returns
-------
extent_world : array, shape (2, D)
| _extent_world_augmented | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def extent(self) -> Extent:
"""Extent of layer in data and world coordinates.
For image-like layers, these coordinates are the locations of the
pixels in `Layer.data` which are treated like sample points that are
centered in the rendered version of those pixels.
For other layers... | Extent of layer in data and world coordinates.
For image-like layers, these coordinates are the locations of the
pixels in `Layer.data` which are treated like sample points that are
centered in the rendered version of those pixels.
For other layers, these coordinates are the points or v... | extent | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _extent_augmented(self) -> Extent:
"""Augmented extent of layer in data and world coordinates.
Differently from Layer.extent, this also includes the "size" of data
points; for example, Point sizes and Image pixel width are included.
For image-like layers, these coordinates are the ... | Augmented extent of layer in data and world coordinates.
Differently from Layer.extent, this also includes the "size" of data
points; for example, Point sizes and Image pixel width are included.
For image-like layers, these coordinates are the locations of the
pixels in `Layer.data` wh... | _extent_augmented | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _get_base_state(self) -> dict[str, Any]:
"""Get dictionary of attributes on base layer.
This is useful for serialization and deserialization of the layer.
And similarly for plugins to pass state without direct dependencies on napari types.
Returns
-------
dict of st... | Get dictionary of attributes on base layer.
This is useful for serialization and deserialization of the layer.
And similarly for plugins to pass state without direct dependencies on napari types.
Returns
-------
dict of str to Any
Dictionary of attributes on base la... | _get_base_state | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _slice_dims(
self,
dims: Dims,
force: bool = False,
) -> None:
"""Slice data with values from a global dims model.
Note this will likely be moved off the base layer soon.
Parameters
----------
dims : Dims
The dims model to use to slic... | Slice data with values from a global dims model.
Note this will likely be moved off the base layer soon.
Parameters
----------
dims : Dims
The dims model to use to slice this layer.
force : bool
True if slicing should be forced to occur, even when some c... | _slice_dims | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def get_value(
self,
position: npt.ArrayLike,
*,
view_direction: npt.ArrayLike | None = None,
dims_displayed: list[int] | None = None,
world: bool = False,
) -> tuple | None:
"""Value of the data at a position.
If the layer is not visible, return None... | Value of the data at a position.
If the layer is not visible, return None.
Parameters
----------
position : tuple of float
Position in either data or world coordinates.
view_direction : Optional[np.ndarray]
A unit vector giving the direction of the ray i... | get_value | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _get_value_3d(
self,
start_point: np.ndarray | None,
end_point: np.ndarray | None,
dims_displayed: list[int],
) -> float | int | None | tuple[float | int | None, int | None]:
"""Get the layer data value along a ray
Parameters
----------
start_poin... | Get the layer data value along a ray
Parameters
----------
start_point : np.ndarray
The start position of the ray used to interrogate the data.
end_point : np.ndarray
The end position of the ray used to interrogate the data.
dims_displayed : List[int]
... | _get_value_3d | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def projected_distance_from_mouse_drag(
self,
start_position: npt.ArrayLike,
end_position: npt.ArrayLike,
view_direction: npt.ArrayLike,
vector: np.ndarray,
dims_displayed: list[int],
) -> npt.NDArray:
"""Calculate the length of the projection of a line betwee... | Calculate the length of the projection of a line between two mouse
clicks onto a vector (or array of vectors) in data coordinates.
Parameters
----------
start_position : np.ndarray
Starting point of the drag vector in data coordinates
end_position : np.ndarray
... | projected_distance_from_mouse_drag | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _set_highlight(self, force: bool = False) -> None:
"""Render layer highlights when appropriate.
Parameters
----------
force : bool
Bool that forces a redraw to occur when `True`.
""" | Render layer highlights when appropriate.
Parameters
----------
force : bool
Bool that forces a redraw to occur when `True`.
| _set_highlight | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _block_refresh(self):
"""Prevent refresh calls from updating view."""
previous = self._refresh_blocked
self._refresh_blocked = True
try:
yield
finally:
self._refresh_blocked = previous | Prevent refresh calls from updating view. | _block_refresh | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def refresh(
self,
event: Event | None = None,
*,
thumbnail: bool = True,
data_displayed: bool = True,
highlight: bool = True,
extent: bool = True,
force: bool = False,
) -> None:
"""Refresh all layer data based on current view slice."""
... | Refresh all layer data based on current view slice. | refresh | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def world_to_data(self, position: npt.ArrayLike) -> npt.NDArray:
"""Convert from world coordinates to data coordinates.
Parameters
----------
position : tuple, list, 1D array
Position in world coordinates. If longer then the
number of dimensions of the layer, the... | Convert from world coordinates to data coordinates.
Parameters
----------
position : tuple, list, 1D array
Position in world coordinates. If longer then the
number of dimensions of the layer, the later
dimensions will be used.
Returns
-------... | world_to_data | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def data_to_world(self, position):
"""Convert from data coordinates to world coordinates.
Parameters
----------
position : tuple, list, 1D array
Position in data coordinates. If longer then the
number of dimensions of the layer, the later
dimensions w... | Convert from data coordinates to world coordinates.
Parameters
----------
position : tuple, list, 1D array
Position in data coordinates. If longer then the
number of dimensions of the layer, the later
dimensions will be used.
Returns
-------
... | data_to_world | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _world_to_displayed_data(
self, position: np.ndarray, dims_displayed: list[int]
) -> npt.NDArray:
"""Convert world to data coordinates for displayed dimensions only.
Parameters
----------
position : tuple, list, 1D array
Position in world coordinates. If long... | Convert world to data coordinates for displayed dimensions only.
Parameters
----------
position : tuple, list, 1D array
Position in world coordinates. If longer then the
number of dimensions of the layer, the later
dimensions will be used.
dims_displa... | _world_to_displayed_data | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _world_to_data_ray(self, vector: npt.ArrayLike) -> npt.NDArray:
"""Convert a vector defining an orientation from world coordinates to data coordinates.
For example, this would be used to convert the view ray.
Parameters
----------
vector : tuple, list, 1D array
A... | Convert a vector defining an orientation from world coordinates to data coordinates.
For example, this would be used to convert the view ray.
Parameters
----------
vector : tuple, list, 1D array
A vector in world coordinates.
Returns
-------
tuple
... | _world_to_data_ray | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _world_to_displayed_data_ray(
self, vector_world: npt.ArrayLike, dims_displayed: list[int]
) -> np.ndarray:
"""Convert an orientation from world to displayed data coordinates.
For example, this would be used to convert the view ray.
Parameters
----------
vector_... | Convert an orientation from world to displayed data coordinates.
For example, this would be used to convert the view ray.
Parameters
----------
vector_world : 1D array
A vector in world coordinates.
Returns
-------
tuple
Vector in data c... | _world_to_displayed_data_ray | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _world_to_layer_dims(
self, *, world_dims: npt.NDArray, ndim_world: int
) -> np.ndarray:
"""Map world dimensions to layer dimensions while maintaining order.
This is used to map dimensions from the full world space defined by ``Dims``
to the subspace that a layer inhabits, so th... | Map world dimensions to layer dimensions while maintaining order.
This is used to map dimensions from the full world space defined by ``Dims``
to the subspace that a layer inhabits, so that those can be used to index the
layer's data and associated coordinates.
For example a world ``Di... | _world_to_layer_dims | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _display_bounding_box_augmented(
self, dims_displayed: list[int]
) -> npt.NDArray:
"""An augmented, axis-aligned (ndisplay, 2) bounding box.
This bounding box includes the size of the layer in best resolution, including required padding
"""
return self._extent_data_augme... | An augmented, axis-aligned (ndisplay, 2) bounding box.
This bounding box includes the size of the layer in best resolution, including required padding
| _display_bounding_box_augmented | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _display_bounding_box_augmented_data_level(
self, dims_displayed: list[int]
) -> npt.NDArray:
"""An augmented, axis-aligned (ndisplay, 2) bounding box.
If the layer is multiscale layer, then returns the
bounding box of the data at the current level
"""
return sel... | An augmented, axis-aligned (ndisplay, 2) bounding box.
If the layer is multiscale layer, then returns the
bounding box of the data at the current level
| _display_bounding_box_augmented_data_level | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def click_plane_from_click_data(
self,
click_position: npt.ArrayLike,
view_direction: npt.ArrayLike,
dims_displayed: list[int],
) -> tuple[np.ndarray, np.ndarray]:
"""Calculate a (point, normal) plane parallel to the canvas in data
coordinates, centered on the centre ... | Calculate a (point, normal) plane parallel to the canvas in data
coordinates, centered on the centre of rotation of the camera.
Parameters
----------
click_position : np.ndarray
click position in world coordinates from mouse event.
view_direction : np.ndarray
... | click_plane_from_click_data | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def get_ray_intersections(
self,
position: npt.ArrayLike,
view_direction: npt.ArrayLike,
dims_displayed: list[int],
world: bool = True,
) -> tuple[np.ndarray | None, np.ndarray | None]:
"""Get the start and end point for the ray extending
from a point through ... | Get the start and end point for the ray extending
from a point through the data bounding box.
Parameters
----------
position
the position of the point in nD coordinates. World vs. data
is set by the world keyword argument.
view_direction : np.ndarray
... | get_ray_intersections | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _get_ray_intersections(
self,
position: npt.NDArray,
view_direction: np.ndarray,
dims_displayed: list[int],
bounding_box: npt.NDArray,
world: bool = True,
) -> tuple[np.ndarray | None, np.ndarray | None]:
"""Get the start and end point for the ray extendin... | Get the start and end point for the ray extending
from a point through the data bounding box.
Parameters
----------
position
the position of the point in nD coordinates. World vs. data
is set by the world keyword argument.
view_direction : np.ndarray
... | _get_ray_intersections | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _update_draw(
self, scale_factor, corner_pixels_displayed, shape_threshold
):
"""Update canvas scale and corner values on draw.
For layer multiscale determining if a new resolution level or tile is
required.
Parameters
----------
scale_factor : float
... | Update canvas scale and corner values on draw.
For layer multiscale determining if a new resolution level or tile is
required.
Parameters
----------
scale_factor : float
Scale factor going from canvas to world coordinates.
corner_pixels_displayed : array, sh... | _update_draw | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def get_status(
self,
position: npt.ArrayLike | None = None,
*,
view_direction: npt.ArrayLike | None = None,
dims_displayed: list[int] | None = None,
world: bool = False,
value: Any | None = None,
) -> dict[str, str]:
"""
Status message informa... |
Status message information of the data at a coordinate position.
Parameters
----------
position : tuple of float
Position in either data or world coordinates.
view_direction : Optional[np.ndarray]
A unit vector giving the direction of the ray in nD world... | get_status | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def _get_tooltip_text(
self,
position: npt.NDArray,
*,
view_direction: np.ndarray | None = None,
dims_displayed: list[int] | None = None,
world: bool = False,
) -> str:
"""
tooltip message of the data at a coordinate position.
Parameters
... |
tooltip message of the data at a coordinate position.
Parameters
----------
position : ndarray
Position in either data or world coordinates.
view_direction : Optional[ndarray]
A unit vector giving the direction of the ray in nD world coordinates.
... | _get_tooltip_text | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def save(self, path: str, plugin: str | None = None) -> list[str]:
"""Save this layer to ``path`` with default (or specified) plugin.
Parameters
----------
path : str
A filepath, directory, or URL to open. Extensions may be used to
specify output format (provide... | Save this layer to ``path`` with default (or specified) plugin.
Parameters
----------
path : str
A filepath, directory, or URL to open. Extensions may be used to
specify output format (provided a plugin is available for the
requested format).
plugin ... | save | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def __copy__(self):
"""Create a copy of this layer.
Returns
-------
layer : napari.layers.Layer
Copy of this layer.
Notes
-----
This method is defined for purpose of asv memory benchmarks.
The copy of data is intentional for properly estimati... | Create a copy of this layer.
Returns
-------
layer : napari.layers.Layer
Copy of this layer.
Notes
-----
This method is defined for purpose of asv memory benchmarks.
The copy of data is intentional for properly estimating memory
usage for lay... | __copy__ | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def create(
cls,
data: Any,
meta: Mapping | None = None,
layer_type: str | None = None,
) -> Layer:
"""Create layer from `data` of type `layer_type`.
Primarily intended for usage by reader plugin hooks and creating a
layer from an unwrapped layer data tuple.
... | Create layer from `data` of type `layer_type`.
Primarily intended for usage by reader plugin hooks and creating a
layer from an unwrapped layer data tuple.
Parameters
----------
data : Any
Data in a format that is valid for the corresponding `layer_type`.
me... | create | python | napari/napari | src/napari/layers/base/base.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/base.py | BSD-3-Clause |
def highlight_box_handles(layer: 'Layer', event: Event) -> None:
"""
Highlight the hovered handle of a TransformBox.
"""
if len(event.dims_displayed) != 2:
return
# we work in data space so we're axis aligned which simplifies calculation
# same as Layer.world_to_data
world_to_data =... |
Highlight the hovered handle of a TransformBox.
| highlight_box_handles | python | napari/napari | src/napari/layers/base/_base_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/_base_mouse_bindings.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.