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_refresh_text():
"""Test refreshing the text after setting new properties"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
properties = {'point_type': ['A'] * shape[0]}
layer = Points(data, properties=copy(properties), text='point_type')
new_properties = {'po... | Test refreshing the text after setting new properties | test_refresh_text | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_border_width_types_negative(border_width):
"""Test negative values in all border_width dtypes"""
shape = (5, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
with pytest.raises(ValueError, match='must be > 0'):
Points(data, border_width=border_width, border_width_is_relative... | Test negative values in all border_width dtypes | test_border_width_types_negative | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_out_of_slice_display():
"""Test setting out_of_slice_display flag for 2D and 4D data."""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data)
assert layer.out_of_slice_display is False
layer.out_of_slice_display = True
assert layer.out_of_s... | Test setting out_of_slice_display flag for 2D and 4D data. | test_out_of_slice_display | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_colormap_without_properties(attribute):
"""Setting the colormode to colormap should raise an exception"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data)
with pytest.raises(ValueError, match='must be a valid Points.properties'):
setatt... | Setting the colormode to colormap should raise an exception | test_colormap_without_properties | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_add_colormap(attribute):
"""Test directly adding a vispy Colormap object"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
annotations = {'point_type': _make_cycled_properties([0, 1.5], shape[0])}
color_kwarg = f'{attribute}_color'
colormap_kwarg = f'{attribu... | Test directly adding a vispy Colormap object | test_add_colormap | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_add_points_direct(
attribute: str, coords, expected_indices, expected_colors
):
"""Test adding points to layer directly"""
layer = Points()
old_data = layer.data
assert len(getattr(layer, f'{attribute}_color')) == 0
layer.events.data = Mock()
setattr(layer, f'current_{attribute}_co... | Test adding points to layer directly | test_add_points_direct | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_color_cycle(attribute, color_cycle):
"""Test setting border/face color with a color cycle list"""
# create Points using list color cycle
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
properties = {'point_type': _make_cycled_properties(['A', 'B'], shape[0])}
p... | Test setting border/face color with a color cycle list | test_color_cycle | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_color_cycle_dict(attribute):
"""Test setting border/face color with a color cycle dict"""
data = np.array([[0, 0], [100, 0], [0, 100]])
properties = {'my_colors': [2, 6, 3]}
points_kwargs = {
'properties': properties,
f'{attribute}_color': 'my_colors',
f'{attribute}_colo... | Test setting border/face color with a color cycle dict | test_color_cycle_dict | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_add_color_cycle_to_empty_layer(attribute):
"""Test adding a point to an empty layer when border/face color is a color cycle
See: https://github.com/napari/napari/pull/1069
"""
default_properties = {'point_type': np.array(['A'])}
color_cycle = ['red', 'blue']
points_kwargs = {
'... | Test adding a point to an empty layer when border/face color is a color cycle
See: https://github.com/napari/napari/pull/1069
| test_add_color_cycle_to_empty_layer | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_adding_value_color_cycle(attribute):
"""Test that adding values to properties used to set a color cycle
and then calling Points.refresh_colors() performs the update and adds the
new value to the face/border_color_cycle_map.
See: https://github.com/napari/napari/issues/988
"""
shape = (... | Test that adding values to properties used to set a color cycle
and then calling Points.refresh_colors() performs the update and adds the
new value to the face/border_color_cycle_map.
See: https://github.com/napari/napari/issues/988
| test_adding_value_color_cycle | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_color_colormap(attribute):
"""Test setting border/face color with a colormap"""
# create Points using with a colormap
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
properties = {'point_type': _make_cycled_properties([0, 1.5], shape[0])}
points_kwargs = {
... | Test setting border/face color with a colormap | test_color_colormap | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_copy_and_paste():
"""Test copying and pasting selected points."""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data)
# Clipboard starts empty
assert layer._clipboard == {}
# Pasting empty clipboard doesn't change data
layer._paste_dat... | Test copying and pasting selected points. | test_copy_and_paste | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_value_3d(
position, view_direction, dims_displayed, world, scale, expected
):
"""Test get_value in 3D with and without scale"""
data = np.array([[0, 10, 15, 15], [0, 10, 5, 5], [0, 5, 15, 15]])
layer = Points(data, size=5, scale=scale)
layer._slice_dims(Dims(ndim=4, ndisplay=3))
value =... | Test get_value in 3D with and without scale | test_value_3d | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_thumbnail_non_square_data():
"""Test the image thumbnail for non-square data.
See: https://github.com/napari/napari/issues/1450
"""
# The points coordinates are in a short and wide range.
data_range = [1, 32]
np.random.seed(0)
data = np.random.random((10, 2)) * data_range
# Mak... | Test the image thumbnail for non-square data.
See: https://github.com/napari/napari/issues/1450
| test_thumbnail_non_square_data | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_thumbnail_with_n_points_greater_than_max():
"""Test thumbnail generation with n_points > _max_points_thumbnail
see: https://github.com/napari/napari/pull/934
"""
# 2D
max_points = Points._max_points_thumbnail * 2
bigger_data = np.random.randint(10, 100, (max_points, 2))
big_layer =... | Test thumbnail generation with n_points > _max_points_thumbnail
see: https://github.com/napari/napari/pull/934
| test_thumbnail_with_n_points_greater_than_max | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_view_size():
"""Test out of slice point rendering and slicing with no points."""
coords = np.array([[0, 1, 1], [0, 2, 2], [1, 3, 3], [4, 3, 3]])
sizes = np.array([5, 5, 3, 3])
layer = Points(coords, size=sizes, out_of_slice_display=False)
layer._slice_dims(Dims(ndim=3, point=(0, 0, 0)))
... | Test out of slice point rendering and slicing with no points. | test_view_size | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_interaction_box():
"""Test the boxes calculated for selected points"""
data = [[3, 3]]
size = 2
layer = Points(data, size=size)
# get a box with no points selected
index = []
box = layer.interaction_box(index)
assert box is None
# get a box with a point selected
index ... | Test the boxes calculated for selected points | test_interaction_box | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_text_param_and_setter_are_consistent():
"""See https://github.com/napari/napari/issues/1833"""
data = np.random.rand(5, 3) * 100
properties = {
'accepted': np.random.choice([True, False], (5,)),
}
text = {'string': 'accepted', 'color': 'black'}
points_init = Points(data, proper... | See https://github.com/napari/napari/issues/1833 | test_text_param_and_setter_are_consistent | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_empty_data_from_tuple():
"""Test that empty data raises an error."""
layer = Points(name='points')
layer2 = Points.create(*layer.as_layer_data_tuple())
assert layer2.data.size == 0 | Test that empty data raises an error. | test_empty_data_from_tuple | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_new_point_size_editable(attribute, new_value):
"""tests the newly placed points may be edited without re-selecting"""
layer = Points()
layer.mode = Mode.ADD
layer.add((0, 0))
setattr(layer, f'current_{attribute}', new_value)
np.testing.assert_allclose(getattr(layer, attribute)[0], new_... | tests the newly placed points may be edited without re-selecting | test_new_point_size_editable | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_antialiasing_setting_and_event_emission():
"""Antialiasing changing should cause event emission."""
data = [[0, 0, 0], [1, 1, 1]]
layer = Points(data)
layer.events.antialiasing = Mock()
layer.antialiasing = 5
assert layer.antialiasing == 5
layer.events.antialiasing.assert_called_onc... | Antialiasing changing should cause event emission. | test_antialiasing_setting_and_event_emission | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_antialiasing_value_clipping():
"""Antialiasing can only be set to positive values."""
data = [[0, 0, 0], [1, 1, 1]]
layer = Points(data)
with pytest.warns(RuntimeWarning):
layer.antialiasing = -1
assert layer.antialiasing == 0 | Antialiasing can only be set to positive values. | test_antialiasing_value_clipping | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_set_drag_start():
"""Drag start should only change when currently None."""
data = [[0, 0], [1, 1]]
layer = Points(data)
assert layer._drag_start is None
position = (0, 1)
layer._set_drag_start({0}, position=position)
np.testing.assert_array_equal(layer._drag_start, position)
lay... | Drag start should only change when currently None. | test_set_drag_start | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_point_slice_request_response(dims_indices, target_indices):
"""Test points slicing with request and response."""
data = [
(10, 2, 4),
(10 + 2 * 1e-7, 4, 6),
(8, 1, 7),
(10.1, 7, 2),
(10 - 2 * 1e-7, 1, 6),
]
layer = Points(data)
data_slice = _ThickND... | Test points slicing with request and response. | test_point_slice_request_response | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_editable_and_visible_are_independent():
"""See https://github.com/napari/napari/issues/1346"""
data = np.empty((0, 2))
layer = Points(data)
assert layer.editable
assert layer.visible
layer.editable = False
layer.visible = False
assert not layer.editable
assert not layer.vis... | See https://github.com/napari/napari/issues/1346 | test_editable_and_visible_are_independent | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_point_selection_remains_evented_after_update():
"""Existing evented selection model should be updated rather than replaced."""
data = np.empty((3, 2))
layer = Points(data)
assert isinstance(layer.selected_data, Selection)
layer.selected_data = {0, 1}
assert isinstance(layer.selected_dat... | Existing evented selection model should be updated rather than replaced. | test_point_selection_remains_evented_after_update | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def test_changing_symbol():
"""Changing the symbol should update the UI"""
layer = Points(np.random.rand(2, 2))
assert layer.symbol[1].value == 'disc'
assert layer.current_symbol.value == 'disc'
# select a point and change its symbol
layer.selected_data = {1}
layer.current_symbol = 'square... | Changing the symbol should update the UI | test_changing_symbol | python | napari/napari | src/napari/layers/points/_tests/test_points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points.py | BSD-3-Clause |
def create_known_points_layer_2d():
"""Create points layer with known coordinates
Returns
-------
layer : napari.layers.Points
Points layer.
n_points : int
Number of points in the points layer
known_non_point : list
Data coordinates that are known to contain no points. U... | Create points layer with known coordinates
Returns
-------
layer : napari.layers.Points
Points layer.
n_points : int
Number of points in the points layer
known_non_point : list
Data coordinates that are known to contain no points. Useful during
testing when needing t... | create_known_points_layer_2d | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def create_known_points_layer_3d():
"""Create 3D points layer with known coordinates displayed in 3D.
Returns
-------
layer : napari.layers.Points
Points layer.
n_points : int
Number of points in the points layer
known_non_point : list
Data coordinates that are known to ... | Create 3D points layer with known coordinates displayed in 3D.
Returns
-------
layer : napari.layers.Points
Points layer.
n_points : int
Number of points in the points layer
known_non_point : list
Data coordinates that are known to contain no points. Useful during
te... | create_known_points_layer_3d | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_not_adding_or_selecting_point(create_known_points_layer_2d):
"""Don't add or select a point by clicking on one in pan_zoom mode."""
layer, n_points, _ = create_known_points_layer_2d
layer.mode = 'pan_zoom'
# Simulate click
event = read_only_event(type='mouse_press')
mouse_press_callbac... | Don't add or select a point by clicking on one in pan_zoom mode. | test_not_adding_or_selecting_point | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_add_point(create_known_points_layer_2d):
"""Add point by clicking in add mode."""
layer, n_points, known_non_point = create_known_points_layer_2d
# Add point at location where non exists
layer.mode = 'add'
# Simulate click
event = read_only_event(type='mouse_press', position=known_non... | Add point by clicking in add mode. | test_add_point | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_add_point_3d(create_known_points_layer_3d):
"""Add a point by clicking in 3D mode."""
layer, n_points, known_not_point = create_known_points_layer_3d
layer.mode = 'add'
# Simulate click
event = read_only_event(
type='mouse_press',
position=known_not_point,
view_dir... | Add a point by clicking in 3D mode. | test_add_point_3d | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_drag_in_add_mode(create_known_points_layer_2d):
"""Drag in add mode and make sure no point is added."""
layer, n_points, known_non_point = create_known_points_layer_2d
# Add point at location where non exists
layer.mode = 'add'
# Simulate click
event = read_only_event(
type='m... | Drag in add mode and make sure no point is added. | test_drag_in_add_mode | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_select_point(create_known_points_layer_2d):
"""Select a point by clicking on one in select mode."""
layer, n_points, _ = create_known_points_layer_2d
layer.mode = 'select'
position = tuple(layer.data[0])
# Simulate click
event = read_only_event(type='mouse_press', position=position)
... | Select a point by clicking on one in select mode. | test_select_point | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_select_point_3d(create_known_points_layer_3d):
"""Select a point by clicking on one in select mode in 3D mode."""
layer, n_points, _ = create_known_points_layer_3d
layer.mode = 'select'
position = tuple(layer.data[1])
# Simulate click
event = read_only_event(
type='mouse_press... | Select a point by clicking on one in select mode in 3D mode. | test_select_point_3d | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_unselect_by_click_point_3d(create_known_points_layer_3d):
"""Select unselecting point by shift clicking on it again in 3D mode."""
layer, n_points, _ = create_known_points_layer_3d
layer.mode = 'select'
position = tuple(layer.data[1])
layer.selected_data = {0, 1}
# Simulate shift+cli... | Select unselecting point by shift clicking on it again in 3D mode. | test_unselect_by_click_point_3d | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_select_by_shift_click_3d(create_known_points_layer_3d):
"""Select selecting point by shift clicking on an additional point in 3D"""
layer, n_points, _ = create_known_points_layer_3d
layer.mode = 'select'
position = tuple(layer.data[1])
layer.selected_data = {0}
# Simulate shift+click... | Select selecting point by shift clicking on an additional point in 3D | test_select_by_shift_click_3d | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_unselect_by_click_empty_3d(create_known_points_layer_3d):
"""Select unselecting point by clicking in empty space"""
layer, n_points, known_not_point = create_known_points_layer_3d
layer.mode = 'select'
layer.selected_data = {0, 1}
# Simulate click on point
event = read_only_event(
... | Select unselecting point by clicking in empty space | test_unselect_by_click_empty_3d | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_add_select_point(create_known_points_layer_2d):
"""Add to a selection of points point by shift-clicking on one."""
layer, n_points, _ = create_known_points_layer_2d
layer.mode = 'select'
position = tuple(layer.data[0])
layer.selected_data = {2, 3}
# Simulate click
event = read_onl... | Add to a selection of points point by shift-clicking on one. | test_add_select_point | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_remove_select_point(create_known_points_layer_2d):
"""Remove from a selection of points point by shift-clicking on one."""
layer, n_points, _ = create_known_points_layer_2d
layer.mode = 'select'
position = tuple(layer.data[0])
layer.selected_data = {0, 2, 3}
# Simulate click
event... | Remove from a selection of points point by shift-clicking on one. | test_remove_select_point | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_not_selecting_point(create_known_points_layer_2d):
"""Don't select a point by not clicking on one in select mode."""
layer, n_points, known_non_point = create_known_points_layer_2d
layer.mode = 'select'
# Simulate click
event = read_only_event(type='mouse_press', position=known_non_point)... | Don't select a point by not clicking on one in select mode. | test_not_selecting_point | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_unselecting_points(create_known_points_layer_2d):
"""Unselect points by not clicking on one in select mode."""
layer, n_points, known_non_point = create_known_points_layer_2d
layer.mode = 'select'
layer.selected_data = {2, 3}
assert len(layer.selected_data) == 2
# Simulate click
e... | Unselect points by not clicking on one in select mode. | test_unselecting_points | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_selecting_all_points_with_drag_2d(create_known_points_layer_2d):
"""Select all points when drag box includes all of them."""
layer, n_points, known_non_point = create_known_points_layer_2d
layer.mode = 'select'
# drag a box that includes all the points
box_drag_begin = (20, 20)
box_dr... | Select all points when drag box includes all of them. | test_selecting_all_points_with_drag_2d | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_selecting_no_points_with_drag_2d(create_known_points_layer_2d):
"""Select no points when drag box outside of all of them."""
layer, n_points, known_non_point = create_known_points_layer_2d
layer.mode = 'select'
# Simulate click
event = read_only_event(type='mouse_press', position=known_no... | Select no points when drag box outside of all of them. | test_selecting_no_points_with_drag_2d | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def test_drag_start_selection(
create_known_points_layer_2d, pre_selection, on_point, modifier
):
"""Check layer drag start and drag box behave as expected."""
layer, n_points, known_non_point = create_known_points_layer_2d
layer.mode = 'select'
layer.selected_data = pre_selection
initial_posit... | Check layer drag start and drag box behave as expected. | test_drag_start_selection | python | napari/napari | src/napari/layers/points/_tests/test_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_tests/test_points_mouse_bindings.py | BSD-3-Clause |
def _initialize_current_color_for_empty_layer(
self, color: ColorType, attribute: str
):
"""Initialize current_{edge,face}_color when starting with empty layer.
Parameters
----------
color : (N, 4) array or str
The value for setting edge or face_color
att... | Initialize current_{edge,face}_color when starting with empty layer.
Parameters
----------
color : (N, 4) array or str
The value for setting edge or face_color
attribute : str in {'edge', 'face'}
The name of the attribute to set the color of.
Should b... | _initialize_current_color_for_empty_layer | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def current_edge_color(self):
"""str: color of shape edges including lines and paths."""
hex_ = rgb_to_hex(self._current_edge_color)[0]
return hex_to_name.get(hex_, hex_) | str: color of shape edges including lines and paths. | current_edge_color | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _set_color_mode(self, color_mode: ColorMode | str, attribute: str):
"""Set the face_color_mode or edge_color_mode property
Parameters
----------
color_mode : str, ColorMode
The value for setting edge or face_color_mode. If color_mode is a string,
it should be... | Set the face_color_mode or edge_color_mode property
Parameters
----------
color_mode : str, ColorMode
The value for setting edge or face_color_mode. If color_mode is a string,
it should be one of: 'direct', 'cycle', or 'colormap'
attribute : str in {'edge', 'face... | _set_color_mode | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _set_color_cycle(
self, color_cycle: np.ndarray | cycle, attribute: str
):
"""Set the face_color_cycle or edge_color_cycle property
Parameters
----------
color_cycle : (N, 4) or (N, 1) array
The value for setting edge or face_color_cycle
attribute : s... | Set the face_color_cycle or edge_color_cycle property
Parameters
----------
color_cycle : (N, 4) or (N, 1) array
The value for setting edge or face_color_cycle
attribute : str in {'edge', 'face'}
The name of the attribute to set the color of.
Should b... | _set_color_cycle | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def edge_width(self, width):
"""Set edge width of shapes using float or list of float.
If list of float, must be of equal length to n shapes
Parameters
----------
width : float or list of float
width of all shapes, or each shape if list
"""
if isinst... | Set edge width of shapes using float or list of float.
If list of float, must be of equal length to n shapes
Parameters
----------
width : float or list of float
width of all shapes, or each shape if list
| edge_width | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def z_index(self, z_index):
"""Set z_index of shape using either int or list of int.
When list of int is provided, must be of equal length to n shapes.
Parameters
----------
z_index : int or list of int
z-index of shapes
"""
if isinstance(z_index, li... | Set z_index of shape using either int or list of int.
When list of int is provided, must be of equal length to n shapes.
Parameters
----------
z_index : int or list of int
z-index of shapes
| z_index | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _set_color(self, color, attribute: str):
"""Set the face_color or edge_color property
Parameters
----------
color : (N, 4) array or str
The value for setting edge or face_color
attribute : str in {'edge', 'face'}
The name of the attribute to set the c... | Set the face_color or edge_color property
Parameters
----------
color : (N, 4) array or str
The value for setting edge or face_color
attribute : str in {'edge', 'face'}
The name of the attribute to set the color of.
Should be 'edge' for edge_color or ... | _set_color | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _refresh_color(
self, attribute: str, update_color_mapping: bool = False
):
"""Calculate and update face or edge colors if using a cycle or color map
Parameters
----------
attribute : str in {'edge', 'face'}
The name of the attribute to set the color of.
... | Calculate and update face or edge colors if using a cycle or color map
Parameters
----------
attribute : str in {'edge', 'face'}
The name of the attribute to set the color of.
Should be 'edge' for edge_color or 'face' for face_color.
update_color_mapping : bool
... | _refresh_color | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _initialize_color(self, color, attribute: str, n_shapes: int):
"""Get the face/edge colors the Shapes layer will be initialized with
Parameters
----------
color : (N, 4) array or str
The value for setting edge or face_color
attribute : str in {'edge', 'face'}
... | Get the face/edge colors the Shapes layer will be initialized with
Parameters
----------
color : (N, 4) array or str
The value for setting edge or face_color
attribute : str in {'edge', 'face'}
The name of the attribute to set the color of.
Should be ... | _initialize_color | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _map_color(self, attribute: str, update_color_mapping: bool = False):
"""Calculate the mapping for face or edge colors if using a cycle or color map
Parameters
----------
attribute : str in {'edge', 'face'}
The name of the attribute to set the color of.
Shou... | Calculate the mapping for face or edge colors if using a cycle or color map
Parameters
----------
attribute : str in {'edge', 'face'}
The name of the attribute to set the color of.
Should be 'edge' for edge_color or 'face' for face_color.
update_color_mapping : ... | _map_color | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _get_new_shape_color(self, adding: int, attribute: str):
"""Get the color for the shape(s) to be added.
Parameters
----------
adding : int
the number of shapes that were added
(and thus the number of color entries to add)
attribute : str in {'edge', '... | Get the color for the shape(s) to be added.
Parameters
----------
adding : int
the number of shapes that were added
(and thus the number of color entries to add)
attribute : str in {'edge', 'face'}
The name of the attribute to set the color of.
... | _get_new_shape_color | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _is_color_mapped(self, color):
"""determines if the new color argument is for directly setting or cycle/colormap"""
if isinstance(color, str):
return color in self.properties
if isinstance(color, list | np.ndarray):
return False
raise ValueError(
... | determines if the new color argument is for directly setting or cycle/colormap | _is_color_mapped | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def add_rectangles(
self,
data,
*,
edge_width=None,
edge_color=None,
face_color=None,
z_index=None,
):
"""Add rectangles to the current layer.
Parameters
----------
data : Array | List[Array]
List of rectangle data ... | Add rectangles to the current layer.
Parameters
----------
data : Array | List[Array]
List of rectangle data where each element is a (4, D) array of 4 vertices
in D dimensions, or in 2D a (2, 2) array of 2 vertices that are
the top-left and bottom-right corne... | add_rectangles | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def add_ellipses(
self,
data,
*,
edge_width=None,
edge_color=None,
face_color=None,
z_index=None,
):
"""Add ellipses to the current layer.
Parameters
----------
data : Array | List[Array]
List of ellipse data where ... | Add ellipses to the current layer.
Parameters
----------
data : Array | List[Array]
List of ellipse data where each element is a (4, D) array of 4 vertices
in D dimensions representing a bounding box, or in 2D a (2, 2) array of
center position and radii magni... | add_ellipses | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def add_polygons(
self,
data,
*,
edge_width=None,
edge_color=None,
face_color=None,
z_index=None,
):
"""Add polygons to the current layer.
Parameters
----------
data : Array | List[Array]
List of polygon data where ... | Add polygons to the current layer.
Parameters
----------
data : Array | List[Array]
List of polygon data where each element is a (V, D) array of V vertices
in D dimensions representing a polygon. Can be a 3-dimensional array if
polygons have same number of ve... | add_polygons | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def add_lines(
self,
data,
*,
edge_width=None,
edge_color=None,
face_color=None,
z_index=None,
):
"""Add lines to the current layer.
Parameters
----------
data : Array | List[Array]
List of line data where each elem... | Add lines to the current layer.
Parameters
----------
data : Array | List[Array]
List of line data where each element is a (2, D) array of 2 vertices
in D dimensions representing a line. Can be a 3-dimensional array for
multiple shapes, or list of 2 vertices ... | add_lines | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def add_paths(
self,
data,
*,
edge_width=None,
edge_color=None,
face_color=None,
z_index=None,
):
"""Add paths to the current layer.
Parameters
----------
data : Array | List[Array]
List of path data where each elem... | Add paths to the current layer.
Parameters
----------
data : Array | List[Array]
List of path data where each element is a (V, D) array of V vertices
in D dimensions representing a path. Can be a 3-dimensional array
if all paths have same number of vertices, ... | add_paths | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def add(
self,
data,
*,
shape_type='rectangle',
edge_width=None,
edge_color=None,
face_color=None,
z_index=None,
gui=False,
):
"""Add shapes to the current layer.
Parameters
----------
data : Array | Tuple(Array... | Add shapes to the current layer.
Parameters
----------
data : Array | Tuple(Array,str) | List[Array | Tuple(Array, str)] | Tuple(List[Array], str)
List of shape data, where each element is either an (N, D) array of the
N vertices of a shape in D dimensions or a tuple con... | add | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _init_shapes(
self,
data,
*,
shape_type='rectangle',
edge_width=None,
edge_color=None,
edge_color_cycle,
edge_colormap,
edge_contrast_limits,
face_color=None,
face_color_cycle,
face_colormap,
face_contrast_limits... | Add shapes to the data view.
Parameters
----------
data : Array | Tuple(Array,str) | List[Array | Tuple(Array, str)] | Tuple(List[Array], str)
List of shape data, where each element is either an (N, D) array of the
N vertices of a shape in D dimensions or a tuple contain... | _init_shapes | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _add_shapes(
self,
data,
*,
shape_type='rectangle',
edge_width=None,
edge_color=None,
face_color=None,
z_index=None,
n_new_shapes=0,
):
"""Add shapes to the data view.
Parameters
----------
data : Array | Tu... | Add shapes to the data view.
Parameters
----------
data : Array | Tuple(Array,str) | List[Array | Tuple(Array, str)] | Tuple(List[Array], str)
List of shape data, where each element is either an (N, D) array of the
N vertices of a shape in D dimensions or a tuple contain... | _add_shapes | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _add_shapes_to_view(self, shape_inputs, data_view: ShapeList):
"""Build new shapes and add them to the _data_view"""
shape_inputs = tuple(shape_inputs)
# build all shapes
sh_inp = tuple(
(
shape_classes[st](
d,
edg... | Build new shapes and add them to the _data_view | _add_shapes_to_view | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _set_view_slice(self):
"""Set the view given the slicing indices."""
with self._data_view.batched_updates():
ndisplay = self._slice_input.ndisplay
if ndisplay != self._ndisplay_stored:
self.selected_data = set()
self._data_view.ndisplay = min(s... | Set the view given the slicing indices. | _set_view_slice | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def interaction_box(self, index):
"""Create the interaction box around a shape or list of shapes.
If a single index is passed then the bounding box will be inherited
from that shapes interaction box. If list of indices is passed it will
be computed directly.
Parameters
-... | Create the interaction box around a shape or list of shapes.
If a single index is passed then the bounding box will be inherited
from that shapes interaction box. If list of indices is passed it will
be computed directly.
Parameters
----------
index : int | list
... | interaction_box | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _outline_shapes(self):
"""Find outlines of any selected or hovered shapes.
Returns
-------
vertices : None | np.ndarray
Nx2 array of any vertices of outline or None
triangles : None | np.ndarray
Mx3 array of any indices of vertices for triangles of ou... | Find outlines of any selected or hovered shapes.
Returns
-------
vertices : None | np.ndarray
Nx2 array of any vertices of outline or None
triangles : None | np.ndarray
Mx3 array of any indices of vertices for triangles of outline or
None
| _outline_shapes | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _compute_vertices_and_box(self):
"""Compute location of highlight vertices and box for rendering.
Returns
-------
vertices : np.ndarray
Nx2 array of any vertices to be rendered as Markers
face_color : str
String of the face color of the Markers
... | Compute location of highlight vertices and box for rendering.
Returns
-------
vertices : np.ndarray
Nx2 array of any vertices to be rendered as Markers
face_color : str
String of the face color of the Markers
edge_color : str
String of the edg... | _compute_vertices_and_box | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _set_highlight(self, force=False) -> None:
"""Render highlights of shapes.
Includes boundaries, vertices, interaction boxes, and the drag
selection box when appropriate.
Parameters
----------
force : bool
Bool that forces a redraw to occur when `True`
... | Render highlights of shapes.
Includes boundaries, vertices, interaction boxes, and the drag
selection box when appropriate.
Parameters
----------
force : bool
Bool that forces a redraw to occur when `True`
| _set_highlight | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _finish_drawing(self, event=None) -> None:
"""Reset properties used in shape drawing."""
index = copy(self._moving_value[0])
self._is_moving = False
self._drag_start = None
self._drag_box = None
self._is_selecting = False
self._fixed_vertex = None
self... | Reset properties used in shape drawing. | _finish_drawing | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def block_thumbnail_update(self):
"""Use this context manager to block thumbnail updates"""
previous = self._allow_thumbnail_update
self._allow_thumbnail_update = False
try:
yield
finally:
self._allow_thumbnail_update = previous | Use this context manager to block thumbnail updates | block_thumbnail_update | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _update_thumbnail(self, event=None):
"""Update thumbnail with current shapes and colors."""
# Set the thumbnail to black, opacity 1
colormapped = np.zeros(self._thumbnail_shape)
colormapped[..., 3] = 1
# if the shapes layer is empty, don't update, just leave it black
... | Update thumbnail with current shapes and colors. | _update_thumbnail | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _rotate_box(self, angle, center=(0, 0)):
"""Perform a rotation on the selected box.
Parameters
----------
angle : float
angle specifying rotation of shapes in degrees.
center : list
coordinates of center of rotation.
"""
theta = np.rad... | Perform a rotation on the selected box.
Parameters
----------
angle : float
angle specifying rotation of shapes in degrees.
center : list
coordinates of center of rotation.
| _rotate_box | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _scale_box(self, scale, center=(0, 0)):
"""Perform a scaling on the selected box.
Parameters
----------
scale : float, list
scalar or list specifying rescaling of shape.
center : list
coordinates of center of rotation.
"""
if not isins... | Perform a scaling on the selected box.
Parameters
----------
scale : float, list
scalar or list specifying rescaling of shape.
center : list
coordinates of center of rotation.
| _scale_box | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _transform_box(self, transform, center=(0, 0)):
"""Perform a linear transformation on the selected box.
Parameters
----------
transform : np.ndarray
2x2 array specifying linear transform.
center : list
coordinates of center of rotation.
"""
... | Perform a linear transformation on the selected box.
Parameters
----------
transform : np.ndarray
2x2 array specifying linear transform.
center : list
coordinates of center of rotation.
| _transform_box | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _get_value(self, position):
"""Value of the data at a position in data coordinates.
Parameters
----------
position : tuple
Position in data coordinates.
Returns
-------
shape : int | None
Index of shape if any that is at the coordinat... | Value of the data at a position in data coordinates.
Parameters
----------
position : tuple
Position in data coordinates.
Returns
-------
shape : int | None
Index of shape if any that is at the coordinates. Returns `None`
if no shape ... | _get_value | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _get_value_3d(
self,
start_point: np.ndarray,
end_point: np.ndarray,
dims_displayed: list[int],
) -> tuple[float | int | None, None]:
"""Get the layer data value along a ray
Parameters
----------
start_point : np.ndarray
The start posi... | 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/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _get_index_and_intersection(
self,
start_point: np.ndarray,
end_point: np.ndarray,
dims_displayed: list[int],
) -> tuple[None | float | int, None | np.ndarray]:
"""Get the shape index and intersection point of the first shape
(i.e., closest to start_point) along t... | Get the shape index and intersection point of the first shape
(i.e., closest to start_point) along the specified 3D line segment.
Note: this method is meant to be used for 3D intersection and returns
(None, None) when used in 2D (i.e., len(dims_displayed) is 2).
Parameters
----... | _get_index_and_intersection | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def get_index_and_intersection(
self,
position: np.ndarray,
view_direction: np.ndarray,
dims_displayed: list[int],
) -> tuple[float | int | None, npt.NDArray | None]:
"""Get the shape index and intersection point of the first shape
(i.e., closest to start_point) "unde... | Get the shape index and intersection point of the first shape
(i.e., closest to start_point) "under" a mouse click.
See examples/add_points_on_nD_shapes.py for example usage.
Parameters
----------
position : tuple
Position in either data or world coordinates.
... | get_index_and_intersection | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def move_to_front(self) -> None:
"""Moves selected objects to be displayed in front of all others."""
if len(self.selected_data) == 0:
return
new_z_index = max(self._data_view._z_index) + 1
for index in self.selected_data:
self._data_view.update_z_index(index, new... | Moves selected objects to be displayed in front of all others. | move_to_front | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def move_to_back(self) -> None:
"""Moves selected objects to be displayed behind all others."""
if len(self.selected_data) == 0:
return
new_z_index = min(self._data_view._z_index) - 1
for index in self.selected_data:
self._data_view.update_z_index(index, new_z_ind... | Moves selected objects to be displayed behind all others. | move_to_back | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _paste_data(self) -> None:
"""Paste any shapes from clipboard and then selects them."""
cur_shapes = self.nshapes
if len(self._clipboard.keys()) > 0:
# Calculate offset based on dimension shifts
offset = [
self._data_slice.point[i] - self._clipboard['i... | Paste any shapes from clipboard and then selects them. | _paste_data | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def to_masks(self, mask_shape=None):
"""Return an array of binary masks, one for each shape.
Parameters
----------
mask_shape : np.ndarray | tuple | None
tuple defining shape of mask to be generated. If non specified,
takes the max of all the vertices
Re... | Return an array of binary masks, one for each shape.
Parameters
----------
mask_shape : np.ndarray | tuple | None
tuple defining shape of mask to be generated. If non specified,
takes the max of all the vertices
Returns
-------
masks : np.ndarray... | to_masks | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def to_labels(self, labels_shape=None):
"""Return an integer labels image.
Parameters
----------
labels_shape : np.ndarray | tuple | None
Tuple defining shape of labels image to be generated. If non
specified, takes the max of all the vertiecs
Returns
... | Return an integer labels image.
Parameters
----------
labels_shape : np.ndarray | tuple | None
Tuple defining shape of labels image to be generated. If non
specified, takes the max of all the vertiecs
Returns
-------
labels : np.ndarray
... | to_labels | python | napari/napari | src/napari/layers/shapes/shapes.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/shapes.py | BSD-3-Clause |
def _set_numba(value: bool) -> None:
"""Set the Numba backend to use.
Parameters
----------
value : bool
If True, use the Numba backend. If False, use the pure Python backend.
"""
global USE_NUMBA_FOR_EDGE_TRIANGULATION
val = value and (_accelerated_triangulate_numba is not None)
... | Set the Numba backend to use.
Parameters
----------
value : bool
If True, use the Numba backend. If False, use the pure Python backend.
| _set_numba | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_dispatch.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_dispatch.py | BSD-3-Clause |
def warmup_universal_numba() -> None:
"""Warm up the functions that are used even with compiled backends."""
if _accelerated_triangulate_numba is None:
# no numba, nothing to warm up
return
global UNIVERSAL_CACHE_WARMUP
if UNIVERSAL_CACHE_WARMUP:
return
UNIVERSAL_CACHE_WARMUP... | Warm up the functions that are used even with compiled backends. | warmup_universal_numba | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_dispatch.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_dispatch.py | BSD-3-Clause |
def _sign_abs(f: float) -> tuple[float, float]:
"""Return 1, -1, or 0 based on the sign of f, as well as the abs of f.
The order of if-statements shows what the function is optimized for given
the early returns. In this case, an array with many positive values will
execute more quickly than one with ma... | Return 1, -1, or 0 based on the sign of f, as well as the abs of f.
The order of if-statements shows what the function is optimized for given
the early returns. In this case, an array with many positive values will
execute more quickly than one with many negative values.
| _sign_abs | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_numba.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_numba.py | BSD-3-Clause |
def _orthogonal_vector(v: np.ndarray, ccw: bool = True) -> np.ndarray:
"""Return an orthogonal vector to v (2D).
Parameters
----------
v : np.ndarray of float, shape (2,)
The input vector.
ccw : bool
Whether you want the orthogonal vector in the counterclockwise
direction (i... | Return an orthogonal vector to v (2D).
Parameters
----------
v : np.ndarray of float, shape (2,)
The input vector.
ccw : bool
Whether you want the orthogonal vector in the counterclockwise
direction (in the napari reference frame) or clockwise.
Returns
-------
np.nd... | _orthogonal_vector | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_numba.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_numba.py | BSD-3-Clause |
def _normalize_triangle_orientation(
triangles: np.ndarray, centers: np.ndarray, offsets: np.ndarray
) -> None:
"""Ensure vertices of all triangles are listed in the same orientation.
In terms of napari's preferred coordinate frame (axis 0, y, is pointing
down, axis 1, x is pointing right), this orient... | Ensure vertices of all triangles are listed in the same orientation.
In terms of napari's preferred coordinate frame (axis 0, y, is pointing
down, axis 1, x is pointing right), this orientation is positive for
anti-clockwise and negative for clockwise. This function normalises all
triangle data in-plac... | _normalize_triangle_orientation | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_numba.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_numba.py | BSD-3-Clause |
def _orientation(
p1: np.ndarray, p2: np.ndarray, p3: np.ndarray
) -> Orientation:
"""Compute the orientation of three points.
In terms of napari's preferred coordinate frame (axis 0, y, is pointing
down, axis 1, x is pointing right), this orientation is positive for
anti-clockwise and negative for... | Compute the orientation of three points.
In terms of napari's preferred coordinate frame (axis 0, y, is pointing
down, axis 1, x is pointing right), this orientation is positive for
anti-clockwise and negative for clockwise.
Parameters
----------
p1, p2, p3: np.ndarray, shape (2,)
The ... | _orientation | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_numba.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_numba.py | BSD-3-Clause |
def _are_polar_angles_monotonic(
vertices: CoordinateArray2D, centroid: np.ndarray
) -> bool:
"""Check if vertices are monastical in a polar system.
The function checks if in a polar coordinate system
with point 0 in centroid, the angle component
of vertices coordinate is increasing.
This is a... | Check if vertices are monastical in a polar system.
The function checks if in a polar coordinate system
with point 0 in centroid, the angle component
of vertices coordinate is increasing.
This is a second part of the polygon convexity check.
Parameters
----------
vertices: np.ndarray
... | _are_polar_angles_monotonic | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_numba.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_numba.py | BSD-3-Clause |
def is_convex(vertices: CoordinateArray2D) -> bool:
"""Check if a polygon is convex.
A polygon is convex when all its internal angles
are less than or equal to 180 degrees and its edges don't
self-intersect.
This function determines convexity by:
1. Checking if all non-collinear angles have th... | Check if a polygon is convex.
A polygon is convex when all its internal angles
are less than or equal to 180 degrees and its edges don't
self-intersect.
This function determines convexity by:
1. Checking if all non-collinear angles have the same
orientation (clockwise or counterclockwise)
... | is_convex | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_numba.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_numba.py | BSD-3-Clause |
def _cut_end_if_repetition(path: np.ndarray) -> np.ndarray:
"""Cut the last point of the path if it is the same as the second to last point.
Parameters
----------
path : np.ndarray
Nx2 array of central coordinates of path to be triangulated
Returns
-------
np.ndarray
Nx2 or... | Cut the last point of the path if it is the same as the second to last point.
Parameters
----------
path : np.ndarray
Nx2 array of central coordinates of path to be triangulated
Returns
-------
np.ndarray
Nx2 or (N-1)x2 array of central coordinates of path to be triangulated
... | _cut_end_if_repetition | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_numba.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_numba.py | BSD-3-Clause |
def remove_path_duplicates(path: np.ndarray, closed: bool) -> np.ndarray:
"""Remove consecutive duplicates from a path.
Parameters
----------
path : np.ndarray
Nx2 or Nx3 array of central coordinates of path to be deduplicated
Returns
-------
np.ndarray
Nx2 or Nx3 array of ... | Remove consecutive duplicates from a path.
Parameters
----------
path : np.ndarray
Nx2 or Nx3 array of central coordinates of path to be deduplicated
Returns
-------
np.ndarray
Nx2 or Nx3 array of central coordinates of deduplicated path
| remove_path_duplicates | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_numba.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_numba.py | BSD-3-Clause |
def create_box_from_bounding(bounding_box: np.ndarray) -> np.ndarray:
"""Creates the axis aligned interaction box of a bounding box
Parameters
----------
bounding_box : np.ndarray
2x2 array of the bounding box. The first row is the minimum values and
the second row is the maximum values... | Creates the axis aligned interaction box of a bounding box
Parameters
----------
bounding_box : np.ndarray
2x2 array of the bounding box. The first row is the minimum values and
the second row is the maximum values
Returns
-------
box : np.ndarray
9x2 array of vertices ... | create_box_from_bounding | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_numba.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_numba.py | BSD-3-Clause |
def _sign_cross(x: np.ndarray, y: np.ndarray) -> npt.NDArray[np.int32]:
"""sign of cross product (faster for 2d)"""
if x.shape[1] == y.shape[1] == 2:
return _sign_nonzero(x[:, 0] * y[:, 1] - x[:, 1] * y[:, 0])
if x.shape[1] == y.shape[1] == 3:
return _sign_nonzero(np.cross(x, y))
raise ... | sign of cross product (faster for 2d) | _sign_cross | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_python.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_python.py | BSD-3-Clause |
def reconstruct_polygons_from_edges_py(
vertices: CoordinateArray, edges: EdgeArray
) -> list[CoordinateArray2D] | list[CoordinateArray3D]:
"""
Reconstruct polygons from vertices and edges.
Parameters
----------
vertices : np.ndarray
Array of vertex coordinates with shape (N, 2) or (N, ... |
Reconstruct polygons from vertices and edges.
Parameters
----------
vertices : np.ndarray
Array of vertex coordinates with shape (N, 2) or (N, 3)
edges : np.ndarray
Array of edge indices with shape (M, 2)
Returns
-------
list of np.ndarray
List of polygons, whe... | reconstruct_polygons_from_edges_py | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_python.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_python.py | BSD-3-Clause |
def _are_polar_angles_monotonic(poly: npt.NDArray, orientation_: int) -> bool:
"""Check whether a polygon with same oriented angles between successive edges is simple.
A polygon is considered simple if its edges do not intersect themselves.
This is determined by checking whether the angles between successi... | Check whether a polygon with same oriented angles between successive edges is simple.
A polygon is considered simple if its edges do not intersect themselves.
This is determined by checking whether the angles between successive
vertices, measured from the centroid, increase consistently around the
poly... | _are_polar_angles_monotonic | python | napari/napari | src/napari/layers/shapes/_accelerated_triangulate_python.py | https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_python.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.