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_show_selected_label():
"""Test color of labels when filtering to selected labels"""
np.random.seed(0)
data = np.random.randint(20, size=(10, 15))
layer = Labels(data)
original_color = layer.get_color(1)
layer.show_selected_label = True
original_background_color = layer.get_color(
... | Test color of labels when filtering to selected labels | test_show_selected_label | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_paint():
"""Test painting labels with different circle brush sizes."""
np.random.seed(0)
data = np.random.randint(20, size=(10, 15))
data[:10, :10] = 1
layer = Labels(data)
assert np.unique(layer.data[:5, :5]) == 1
assert np.unique(layer.data[5:10, 5:10]) == 1
layer.brush_size... | Test painting labels with different circle brush sizes. | test_paint | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_paint_with_preserve_labels():
"""Test painting labels with square brush while preserving existing labels."""
data = np.zeros((15, 10), dtype=np.uint32)
data[:3, :3] = 1
layer = Labels(data)
layer.preserve_labels = True
assert np.unique(layer.data[:3, :3]) == 1
layer.brush_size = 9... | Test painting labels with square brush while preserving existing labels. | test_paint_with_preserve_labels | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_setting_prev_selected_label():
"""Test that _prev_selected_label is set when selected_label
is set to the colormap background_value."""
data = np.zeros((15, 10), dtype=np.uint32)
layer = Labels(data)
# set the selected label, _prev_selected_label should be None
layer.selected_label = 1... | Test that _prev_selected_label is set when selected_label
is set to the colormap background_value. | test_setting_prev_selected_label | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_paint_swap_with_preserve_labels():
"""Test painting and swapping labels & background while preserving labels."""
data = np.zeros((15, 10), dtype=np.uint32)
data[:3, :3] = 1
layer = Labels(data)
layer.preserve_labels = True
assert np.unique(layer.data[:3, :3]) == 1
layer.brush_size... | Test painting and swapping labels & background while preserving labels. | test_paint_swap_with_preserve_labels | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_paint_2d():
"""Test painting labels with circle brush."""
data = np.zeros((40, 40), dtype=np.uint32)
layer = Labels(data)
layer.brush_size = 12
layer.mode = 'paint'
layer.paint((0, 0), 3)
layer.brush_size = 12
layer.paint((15, 8), 4)
layer.brush_size = 13
layer.paint((... | Test painting labels with circle brush. | test_paint_2d | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_paint_2d_xarray():
"""Test the memory usage of painting a xarray indirectly via timeout."""
now = time.monotonic()
data = xr.DataArray(np.zeros((3, 3, 1024, 1024), dtype=np.uint32))
layer = Labels(data)
layer.brush_size = 12
layer.mode = 'paint'
layer.paint((1, 1, 512, 512), 3)
... | Test the memory usage of painting a xarray indirectly via timeout. | test_paint_2d_xarray | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_paint_3d():
"""Test painting labels with circle brush on 3D image."""
data = np.zeros((30, 40, 40), dtype=np.uint32)
layer = Labels(data)
layer.brush_size = 12
layer.mode = 'paint'
# Paint in 2D
layer.paint((10, 10, 10), 3)
# Paint in 3D
layer.n_edit_dimensions = 3
lay... | Test painting labels with circle brush on 3D image. | test_paint_3d | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_paint_polygon_2d_in_3d():
"""Test painting labels with polygons in a 3D array"""
data = np.zeros((3, 10, 10), dtype=int)
layer = Labels(data)
assert layer.n_edit_dimensions == 2
layer.paint_polygon([[1, 0, 0], [1, 0, 9], [1, 9, 9], [1, 9, 0]], 1)
assert np.array_equiv(data[1, :], 1)
... | Test painting labels with polygons in a 3D array | test_paint_polygon_2d_in_3d | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_fill():
"""Test filling labels with different brush sizes."""
np.random.seed(0)
data = np.random.randint(20, size=(10, 15))
data[:10, :10] = 2
data[:5, :5] = 1
layer = Labels(data)
assert np.unique(layer.data[:5, :5]) == 1
assert np.unique(layer.data[5:10, 5:10]) == 2
layer... | Test filling labels with different brush sizes. | test_fill | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_fill_swap_with_preserve_labels():
"""Test fill and swap background while preserving existing labels."""
data = np.zeros((15, 10), dtype=np.uint32)
data[:3, :3] = 1
layer = Labels(data)
layer.preserve_labels = True
assert np.unique(layer.data[:3, :3]) == 1
layer.selected_label = 2
... | Test fill and swap background while preserving existing labels. | test_fill_swap_with_preserve_labels | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_fill_with_xarray():
"""See https://github.com/napari/napari/issues/2374"""
data = xr.DataArray(np.zeros((5, 4, 4), dtype=int))
layer = Labels(data)
layer.fill((0, 2, 2), 1)
np.testing.assert_array_equal(layer.data[0, :, :], np.ones((4, 4)))
np.testing.assert_array_equal(layer.data[1:,... | See https://github.com/napari/napari/issues/2374 | test_fill_with_xarray | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_get_value_ray_3d():
"""Test using _get_value_ray to interrogate labels in 3D"""
# make a mock mouse event
mouse_event = MouseEvent(
pos=[25, 25],
position=[10, 5, 5],
dims_point=[1, 0, 0, 0],
dims_displayed=[1, 2, 3],
view_direction=[1, 0, 0],
)
data ... | Test using _get_value_ray to interrogate labels in 3D | test_get_value_ray_3d | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_get_value_ray_3d_rolled():
"""Test using _get_value_ray to interrogate labels in 3D
with the dimensions rolled.
"""
# make a mock mouse event
mouse_event = MouseEvent(
pos=[25, 25],
position=[10, 5, 5, 1],
dims_point=[0, 0, 0, 1],
dims_displayed=[0, 1, 2],
... | Test using _get_value_ray to interrogate labels in 3D
with the dimensions rolled.
| test_get_value_ray_3d_rolled | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_get_value_ray_3d_transposed():
"""Test using _get_value_ray to interrogate labels in 3D
with the dimensions transposed.
"""
# make a mock mouse event
mouse_event = MouseEvent(
pos=[25, 25],
position=[10, 5, 5, 1],
dims_point=[0, 0, 0, 1],
dims_displayed=[1, 3... | Test using _get_value_ray to interrogate labels in 3D
with the dimensions transposed.
| test_get_value_ray_3d_transposed | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_get_value_ray_2d():
"""_get_value_ray currently only returns None in 2D
(i.e., it shouldn't be used for 2D).
"""
# make a mock mouse event
mouse_event = MouseEvent(
pos=[25, 25],
position=[5, 5],
dims_point=[1, 10, 0, 0],
dims_displayed=[2, 3],
view_d... | _get_value_ray currently only returns None in 2D
(i.e., it shouldn't be used for 2D).
| test_get_value_ray_2d | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_cursor_ray_3d_rolled():
"""Test that the cursor works when the displayed
viewer axes have been rolled
"""
# make a mock mouse event
mouse_event_1 = MouseEvent(
pos=[25, 25],
position=[10, 27, 10, 1],
dims_point=[0, 0, 0, 1],
dims_displayed=[0, 1, 2],
... | Test that the cursor works when the displayed
viewer axes have been rolled
| test_cursor_ray_3d_rolled | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_cursor_ray_3d_transposed():
"""Test that the cursor works when the displayed
viewer axes have been transposed
"""
# make a mock mouse event
mouse_event_1 = MouseEvent(
pos=[25, 25],
position=[10, 27, 10, 1],
dims_point=[0, 0, 0, 1],
dims_displayed=[0, 2, 1],
... | Test that the cursor works when the displayed
viewer axes have been transposed
| test_cursor_ray_3d_transposed | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_labels_state_update():
"""Test that a labels layer can be updated from the output of its
_get_state() method
"""
data = np.random.randint(20, size=(10, 15))
layer = Labels(data)
state = layer._get_state()
for k, v in state.items():
setattr(layer, k, v) | Test that a labels layer can be updated from the output of its
_get_state() method
| test_labels_state_update | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_is_default_color():
"""Test labels layer default color for None and background
Previously, setting color to just default values would
change color mode to DIRECT and display a black layer.
This test ensures `is_default_color` is
correctly checking against layer defaults, and `color_mode`
... | Test labels layer default color for None and background
Previously, setting color to just default values would
change color mode to DIRECT and display a black layer.
This test ensures `is_default_color` is
correctly checking against layer defaults, and `color_mode`
is only changed when appropriate.... | test_is_default_color | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_large_labels_direct_color():
"""Make sure direct color works with large label ranges"""
pytest.importorskip('numba')
data = np.array([[0, 1], [2**16, 2**20]], dtype=np.uint32)
colors = {1: 'white', 2**16: 'green', 2**20: 'magenta'}
layer = Labels(
data,
colormap=DirectLabelC... | Make sure direct color works with large label ranges | test_large_labels_direct_color | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_invalidate_cache_when_change_color_mode(
direct_colormap, random_colormap
):
"""Checks if the cache is invalidated when color mode is changed."""
data = np.zeros((4, 10), dtype=np.int32)
data[1, :] = np.arange(0, 10)
layer = Labels(data)
layer.selected_label = 0
gt_auto = layer._ra... | Checks if the cache is invalidated when color mode is changed. | test_invalidate_cache_when_change_color_mode | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_color_mapping_when_color_is_changed():
"""Checks if the color mapping is computed correctly when the color palette is changed."""
data = np.zeros((4, 5), dtype=np.int32)
data[1, :] = np.arange(0, 5)
layer = Labels(
data,
colormap=DirectLabelColormap(
color_dict={1: ... | Checks if the color mapping is computed correctly when the color palette is changed. | test_color_mapping_when_color_is_changed | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_color_mapping_with_show_selected_label():
"""Checks if the color mapping is computed correctly when show_selected_label is activated."""
data = np.arange(5, dtype=np.int32)[:, np.newaxis].repeat(5, axis=1)
layer = Labels(data)
mapped_colors_all = layer.colormap.map(data)
layer.show_select... | Checks if the color mapping is computed correctly when show_selected_label is activated. | test_color_mapping_with_show_selected_label | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_color_mapping_when_seed_is_changed():
"""Checks if the color mapping is updated when the color palette seed is changed."""
np.random.seed(0)
layer = Labels(np.random.randint(50, size=(10, 10)))
mapped_colors1 = layer.colormap.map(
layer._to_vispy_texture_dtype(layer._slice.image.raw)
... | Checks if the color mapping is updated when the color palette seed is changed. | test_color_mapping_when_seed_is_changed | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_color_shuffling_above_num_colors(num_colors):
r"""Check that the color shuffle does not result in the same collisions.
See https://github.com/napari/napari/issues/6448.
Note that we don't support more than 2\ :sup:`16` colors, and behavior
with more colors is undefined, so we don't test it he... | Check that the color shuffle does not result in the same collisions.
See https://github.com/napari/napari/issues/6448.
Note that we don't support more than 2\ :sup:`16` colors, and behavior
with more colors is undefined, so we don't test it here.
| test_color_shuffling_above_num_colors | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_negative_label():
"""Test negative label values are supported."""
data = np.random.randint(low=-1, high=20, size=(10, 10))
original_data = np.copy(data)
layer = Labels(data)
layer.selected_label = -1
layer.brush_size = 3
layer.paint((5, 5), -1)
assert np.count_nonzero(layer.data... | Test negative label values are supported. | test_negative_label | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_negative_label_slicing():
"""Test negative label color doesn't change during slicing."""
data = np.array([[[0, 1], [-1, -1]], [[100, 100], [-1, -2]]])
layer = Labels(data)
assert tuple(layer.get_color(1)) != tuple(layer.get_color(-1))
layer._slice_dims(Dims(ndim=3, point=(1, 0, 0)))
ass... | Test negative label color doesn't change during slicing. | test_negative_label_slicing | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_get_status_with_custom_index():
"""See https://github.com/napari/napari/issues/3811"""
data = np.zeros((10, 10), dtype=np.uint8)
data[2:5, 2:-2] = 1
data[5:-2, 2:-2] = 2
layer = Labels(data)
df = pd.DataFrame(
{'text1': [1, 3], 'text2': [7, -2], 'index': [1, 2]}, index=[1, 2]
... | See https://github.com/napari/napari/issues/3811 | test_get_status_with_custom_index | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_new_colormap_int8():
"""Check that int8 labels colors can be shuffled without overflow.
See https://github.com/napari/napari/issues/7277.
"""
data = np.arange(-128, 128, dtype=np.int8).reshape((16, 16))
layer = Labels(data)
layer.new_colormap(seed=0) | Check that int8 labels colors can be shuffled without overflow.
See https://github.com/napari/napari/issues/7277.
| test_new_colormap_int8 | python | napari/napari | src/napari/layers/labels/_tests/test_labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels.py | BSD-3-Clause |
def test_paint_scale(MouseEvent):
"""Test painting labels with circle brush when scaled."""
data = np.ones((20, 20), dtype=np.int32)
layer = Labels(data, scale=(2, 2))
layer.brush_size = 10
layer.mode = 'paint'
layer.selected_label = 3
# Simulate click
event = ReadOnlyWrapper(
... | Test painting labels with circle brush when scaled. | test_paint_scale | python | napari/napari | src/napari/layers/labels/_tests/test_labels_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels_mouse_bindings.py | BSD-3-Clause |
def test_erase(MouseEvent):
"""Test erasing labels with different brush shapes."""
data = np.ones((20, 20), dtype=np.int32)
layer = Labels(data)
layer.brush_size = 10
layer.mode = 'erase'
layer.selected_label = 3
# Simulate click
event = ReadOnlyWrapper(
MouseEvent(
... | Test erasing labels with different brush shapes. | test_erase | python | napari/napari | src/napari/layers/labels/_tests/test_labels_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels_mouse_bindings.py | BSD-3-Clause |
def test_erase_3d_undo(MouseEvent):
"""Test erasing labels in 3D then undoing the erase.
Specifically, this test checks that undo is correctly filled even
when a click and drag starts outside of the data volume.
"""
data = np.zeros((20, 20, 20), dtype=np.int32)
data[10, :, :] = 1
layer = La... | Test erasing labels in 3D then undoing the erase.
Specifically, this test checks that undo is correctly filled even
when a click and drag starts outside of the data volume.
| test_erase_3d_undo | python | napari/napari | src/napari/layers/labels/_tests/test_labels_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels_mouse_bindings.py | BSD-3-Clause |
def test_erase_3d_undo_empty(MouseEvent):
"""Nothing should be added to undo queue when clicks fall outside data."""
data = np.zeros((20, 20, 20), dtype=np.int32)
data[10, :, :] = 1
layer = Labels(data)
layer.brush_size = 5
layer.mode = 'erase'
layer._slice_dims(Dims(ndim=3, ndisplay=3))
... | Nothing should be added to undo queue when clicks fall outside data. | test_erase_3d_undo_empty | python | napari/napari | src/napari/layers/labels/_tests/test_labels_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels_mouse_bindings.py | BSD-3-Clause |
def test_random_multiscale():
"""Test instantiating Labels layer with random 2D multiscale data."""
shapes = [(40, 20), (20, 10), (10, 5)]
np.random.seed(0)
data = [np.random.randint(20, size=s) for s in shapes]
layer = Labels(data, multiscale=True)
assert layer.data == data
assert layer.mul... | Test instantiating Labels layer with random 2D multiscale data. | test_random_multiscale | python | napari/napari | src/napari/layers/labels/_tests/test_labels_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels_multiscale.py | BSD-3-Clause |
def test_3D_multiscale_labels_in_2D():
"""Test instantiating Labels layer with 3D data, 2D dims."""
data_multiscale, layer = instantiate_3D_multiscale_labels()
assert layer.data == data_multiscale
assert layer.multiscale is True
assert layer.editable is False
assert layer.ndim == len(data_multi... | Test instantiating Labels layer with 3D data, 2D dims. | test_3D_multiscale_labels_in_2D | python | napari/napari | src/napari/layers/labels/_tests/test_labels_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels_multiscale.py | BSD-3-Clause |
def test_3D_multiscale_labels_in_3D():
"""Test instantiating Labels layer with 3D data, 3D dims."""
data_multiscale, layer = instantiate_3D_multiscale_labels()
# use 3D dims
layer._slice_dims(Dims(ndim=3, ndisplay=3))
assert layer._data_view.ndim == 3
# check corner pixels, should be value of ... | Test instantiating Labels layer with 3D data, 3D dims. | test_3D_multiscale_labels_in_3D | python | napari/napari | src/napari/layers/labels/_tests/test_labels_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels_multiscale.py | BSD-3-Clause |
def test_interpolate_with_none():
"""Test that interpolating with one None coordinate returns original."""
coord = np.array([5, 5])
expected = coord[np.newaxis, :]
actual = interpolate_coordinates(coord, None, brush_size=1)
np.testing.assert_array_equal(actual, expected)
actual2 = interpolate_co... | Test that interpolating with one None coordinate returns original. | test_interpolate_with_none | python | napari/napari | src/napari/layers/labels/_tests/test_labels_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_tests/test_labels_utils.py | BSD-3-Clause |
def _extent_data(self) -> np.ndarray:
"""Extent of layer in data coordinates.
Returns
-------
extent_data : array, shape (2, D)
"""
if len(self.data) == 0:
extrema = np.full((2, self.ndim), np.nan)
else:
maxs = np.max(self.data, axis=0)
... | Extent of layer in data coordinates.
Returns
-------
extent_data : array, shape (2, D)
| _extent_data | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def antialiasing(self, value: float) -> None:
"""Set the amount of antialiasing in canvas pixels.
Values can only be positive.
"""
if value < 0:
warnings.warn(
message=trans._(
'antialiasing value must be positive, value will be set to 0.'... | Set the amount of antialiasing in canvas pixels.
Values can only be positive.
| antialiasing | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def current_border_color(self) -> str:
"""str: border color of marker for the next added point or the selected point(s)."""
hex_ = rgb_to_hex(self._border.current_color)[0]
return hex_to_name.get(hex_, hex_) | str: border color of marker for the next added point or the selected point(s). | current_border_color | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def current_face_color(self) -> str:
"""Face color of marker for the next added point or the selected point(s)."""
hex_ = rgb_to_hex(self._face.current_color)[0]
return hex_to_name.get(hex_, hex_) | Face color of marker for the next added point or the selected point(s). | current_face_color | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _set_color_mode(
self,
color_mode: ColorMode | str,
attribute: Literal['border', 'face'],
) -> None:
"""Set the face_color_mode or border_color_mode property
Parameters
----------
color_mode : str, ColorMode
The value for setting border or fac... | Set the face_color_mode or border_color_mode property
Parameters
----------
color_mode : str, ColorMode
The value for setting border or face_color_mode. If color_mode is a string,
it should be one of: 'direct', 'cycle', or 'colormap'
attribute : str in {'border',... | _set_color_mode | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def interaction_box(self, index: list[int]) -> np.ndarray | None:
"""Create the interaction box around a list of points in view.
Parameters
----------
index : list
List of points around which to construct the interaction box.
Returns
-------
box : np... | Create the interaction box around a list of points in view.
Parameters
----------
index : list
List of points around which to construct the interaction box.
Returns
-------
box : np.ndarray or None
4x2 array of corners of the interaction box in c... | interaction_box | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _view_data(self) -> np.ndarray:
"""Get the coords of the points in view
Returns
-------
view_data : (N x D) np.ndarray
Array of coordinates for the N points in view
"""
if len(self._indices_view) > 0:
data = self.data[
np.ix_(s... | Get the coords of the points in view
Returns
-------
view_data : (N x D) np.ndarray
Array of coordinates for the N points in view
| _view_data | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _view_text(self) -> np.ndarray:
"""Get the values of the text elements in view
Returns
-------
text : (N x 1) np.ndarray
Array of text strings for the N text elements in view
"""
# This may be triggered when the string encoding instance changed,
#... | Get the values of the text elements in view
Returns
-------
text : (N x 1) np.ndarray
Array of text strings for the N text elements in view
| _view_text | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _view_text_coords(self) -> tuple[np.ndarray, str, str]:
"""Get the coordinates of the text elements in view
Returns
-------
text_coords : (N x D) np.ndarray
Array of coordinates for the N text elements in view
anchor_x : str
The vispy text anchor for ... | Get the coordinates of the text elements in view
Returns
-------
text_coords : (N x D) np.ndarray
Array of coordinates for the N text elements in view
anchor_x : str
The vispy text anchor for the x axis
anchor_y : str
The vispy text anchor for... | _view_text_coords | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _view_size(self) -> np.ndarray:
"""Get the sizes of the points in view
Returns
-------
view_size : (N,) np.ndarray
Array of sizes for the N points in view
"""
if len(self._indices_view) > 0:
sizes = self.size[self._indices_view] * self._view_s... | Get the sizes of the points in view
Returns
-------
view_size : (N,) np.ndarray
Array of sizes for the N points in view
| _view_size | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _reset_editable(self) -> None:
"""Set editable mode based on layer properties."""
# interaction currently does not work for 2D layers being rendered in 3D
self.editable = not (
self.ndim == 2 and self._slice_input.ndisplay == 3
) | Set editable mode based on layer properties. | _reset_editable | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _get_value(self, position) -> int | None:
"""Index of the point at a given 2D position in data coordinates.
Parameters
----------
position : tuple
Position in data coordinates.
Returns
-------
value : int or None
Index of point that i... | Index of the point at a given 2D position in data coordinates.
Parameters
----------
position : tuple
Position in data coordinates.
Returns
-------
value : int or None
Index of point that is at the current coordinate if any.
| _get_value | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _get_value_3d(
self,
start_point: np.ndarray,
end_point: np.ndarray,
dims_displayed: list[int],
) -> int | None:
"""Get the layer data value along a ray
Parameters
----------
start_point : np.ndarray
The start position of the ray used ... | 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/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def get_ray_intersections(
self,
position: list[float],
view_direction: np.ndarray,
dims_displayed: list[int],
world: bool = True,
) -> tuple[np.ndarray, np.ndarray] | tuple[None, 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 displayed bounding box.
This method overrides the base layer, replacing the bounding box used
to calculate intersections with a larger one which includes the size
of points in view.
Parameters
--... | get_ray_intersections | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _set_view_slice(self) -> None:
"""Sets the view given the indices to slice with."""
# The new slicing code makes a request from the existing state and
# executes the request on the calling thread directly.
# For async slicing, the calling thread will not be the main thread.
... | Sets the view given the indices to slice with. | _set_view_slice | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _make_slice_request(self, dims: 'Dims') -> _PointSliceRequest:
"""Make a Points slice request based on the given dims and these data."""
slice_input = self._make_slice_input(dims)
# See Image._make_slice_request to understand why we evaluate this here
# instead of using `self._data_s... | Make a Points slice request based on the given dims and these data. | _make_slice_request | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _set_highlight(self, force: bool = False) -> None:
"""Render highlights of shapes including boundaries, vertices,
interaction boxes, and the drag selection box when appropriate.
Highlighting only occurs in Mode.SELECT.
Parameters
----------
force : bool
B... | Render highlights of shapes including boundaries, vertices,
interaction boxes, and the drag selection box when appropriate.
Highlighting only occurs in Mode.SELECT.
Parameters
----------
force : bool
Bool that forces a redraw to occur when `True`
| _set_highlight | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _update_thumbnail(self) -> None:
"""Update thumbnail with current points and colors."""
colormapped = np.zeros(self._thumbnail_shape)
colormapped[..., 3] = 1
view_data = self._view_data
if len(view_data) > 0:
# Get the zoom factor required to fit all data in the t... | Update thumbnail with current points and colors. | _update_thumbnail | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def add(self, coords):
"""Adds points at coordinates.
Parameters
----------
coords : array
Point or points to add to the layer data.
"""
cur_points = len(self.data)
self.events.data(
value=self.data,
action=ActionType.ADDING,
... | Adds points at coordinates.
Parameters
----------
coords : array
Point or points to add to the layer data.
| add | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _move(
self,
selection_indices: Sequence[int],
position: Sequence[int | float],
) -> None:
"""Move points relative to drag start location.
Parameters
----------
selection_indices : Sequence[int]
Integer indices of points to move in self.data
... | Move points relative to drag start location.
Parameters
----------
selection_indices : Sequence[int]
Integer indices of points to move in self.data
position : tuple
Position to move points to in data coordinates.
| _move | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _set_drag_start(
self,
selection_indices: Sequence[int],
position: Sequence[int | float],
center_by_data: bool = True,
) -> None:
"""Store the initial position at the start of a drag event.
Parameters
----------
selection_indices : set of int
... | Store the initial position at the start of a drag event.
Parameters
----------
selection_indices : set of int
integer indices of selected data used to index into self.data
position : Sequence of numbers
position of the drag start in data coordinates.
cent... | _set_drag_start | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def _paste_data(self) -> None:
"""Paste any point from clipboard and select them."""
npoints = len(self._view_data)
totpoints = len(self.data)
if len(self._clipboard.keys()) > 0:
not_disp = self._slice_input.not_displayed
data = deepcopy(self._clipboard['data'])
... | Paste any point from clipboard and select them. | _paste_data | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def to_mask(
self,
*,
shape: tuple,
data_to_world: Affine | None = None,
isotropic_output: bool = True,
) -> npt.NDArray:
"""Return a binary mask array of all the points as balls.
Parameters
----------
shape : tuple
The shape of th... | Return a binary mask array of all the points as balls.
Parameters
----------
shape : tuple
The shape of the mask to be generated.
data_to_world : Optional[Affine]
The data-to-world transform of the output mask image. This likely comes from a reference image.
... | to_mask | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def get_status(
self,
position: tuple | None = None,
*,
view_direction: np.ndarray | None = None,
dims_displayed: list[int] | None = None,
world: bool = False,
) -> dict:
"""Status message information of the data at a coordinate position.
# Parameters... | Status message information of the data at a coordinate position.
# Parameters
# ----------
# position : tuple
# Position in either data or world coordinates.
# view_direction : Optional[np.ndarray]
# A unit vector giving the direction of the ray in nD world coord... | get_status | python | napari/napari | src/napari/layers/points/points.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/points.py | BSD-3-Clause |
def select(layer, event):
"""Select points.
Clicking on a point will select that point. If holding shift while clicking
that point will be added to or removed from the existing selection
depending on whether it is selected or not.
Clicking and dragging a point that is already selected will drag al... | Select points.
Clicking on a point will select that point. If holding shift while clicking
that point will be added to or removed from the existing selection
depending on whether it is selected or not.
Clicking and dragging a point that is already selected will drag all the
currently selected poin... | select | python | napari/napari | src/napari/layers/points/_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_mouse_bindings.py | BSD-3-Clause |
def add(layer, event):
"""Add a new point at the clicked position."""
start_pos = event.pos
dist = 0
yield
while event.type == 'mouse_move':
dist = np.linalg.norm(start_pos - event.pos)
if dist < DRAG_DIST_THRESHOLD:
# prevent vispy from moving the canvas if we're below ... | Add a new point at the clicked position. | add | python | napari/napari | src/napari/layers/points/_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_mouse_bindings.py | BSD-3-Clause |
def _toggle_selected(selection: set[_T], value: _T) -> set[_T]:
"""Add or remove value from the selection set.
This function returns a copy of the existing selection.
Parameters
----------
selection : set
Set of selected data points to be modified.
value : int
Index of point to... | Add or remove value from the selection set.
This function returns a copy of the existing selection.
Parameters
----------
selection : set
Set of selected data points to be modified.
value : int
Index of point to add or remove from selected data set.
Returns
-------
sel... | _toggle_selected | python | napari/napari | src/napari/layers/points/_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_mouse_bindings.py | BSD-3-Clause |
def _update_drag_vectors_from_event(layer, event):
"""Update the drag normal and up vectors on layer from a mouse event.
Note that in 2D mode, the layer._drag_normal and layer._drag_up
are set to None.
Parameters
----------
layer : "napari.layers.Points"
The Points layer to update.
... | Update the drag normal and up vectors on layer from a mouse event.
Note that in 2D mode, the layer._drag_normal and layer._drag_up
are set to None.
Parameters
----------
layer : "napari.layers.Points"
The Points layer to update.
event
The mouse event object.
| _update_drag_vectors_from_event | python | napari/napari | src/napari/layers/points/_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_mouse_bindings.py | BSD-3-Clause |
def _select_points_from_drag(layer, modify_selection: bool, n_display: int):
"""Select points on a Points layer after a drag event.
Parameters
----------
layer : napari.layers.Points
The points layer to select points on.
modify_selection : bool
Set to true if the selection should mo... | Select points on a Points layer after a drag event.
Parameters
----------
layer : napari.layers.Points
The points layer to select points on.
modify_selection : bool
Set to true if the selection should modify the current selected data
in layer.selected_data.
n_display : int
... | _select_points_from_drag | python | napari/napari | src/napari/layers/points/_points_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_mouse_bindings.py | BSD-3-Clause |
def _create_box_from_corners_3d(
box_corners: np.ndarray, box_normal: np.ndarray, up_vector: np.ndarray
) -> np.ndarray:
"""Get front corners for 3D box from opposing corners and edge directions.
The resulting box will include the two corners passed in as box_corners,
lie in a plane with normal box_nor... | Get front corners for 3D box from opposing corners and edge directions.
The resulting box will include the two corners passed in as box_corners,
lie in a plane with normal box_normal, and have one of its axes aligned
with the up_vector.
Parameters
----------
box_corners : np.ndarray
Th... | _create_box_from_corners_3d | python | napari/napari | src/napari/layers/points/_points_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_utils.py | BSD-3-Clause |
def create_box(data: npt.NDArray) -> npt.NDArray:
"""Create the axis aligned interaction box of a list of points
Parameters
----------
data : (N, 2) array
Points around which the interaction box is created
Returns
-------
box : (4, 2) array
Vertices of the interaction box
... | Create the axis aligned interaction box of a list of points
Parameters
----------
data : (N, 2) array
Points around which the interaction box is created
Returns
-------
box : (4, 2) array
Vertices of the interaction box
| create_box | python | napari/napari | src/napari/layers/points/_points_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_utils.py | BSD-3-Clause |
def points_to_squares(points: npt.NDArray, sizes: npt.NDArray) -> npt.NDArray:
"""Expand points to squares defined by their size
Parameters
----------
points : (N, 2) array
Points to be turned into squares
sizes : (N,) array
Size of each point
Returns
-------
rect : (4N... | Expand points to squares defined by their size
Parameters
----------
points : (N, 2) array
Points to be turned into squares
sizes : (N,) array
Size of each point
Returns
-------
rect : (4N, 2) array
Vertices of the expanded points
| points_to_squares | python | napari/napari | src/napari/layers/points/_points_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_utils.py | BSD-3-Clause |
def _points_in_box_3d(
box_corners: np.ndarray,
points: np.ndarray,
sizes: np.ndarray,
box_normal: np.ndarray,
up_direction: np.ndarray,
) -> list[int]:
"""Determine which points are inside of 2D bounding box.
The 2D bounding box extends infinitely in both directions along its normal
ve... | Determine which points are inside of 2D bounding box.
The 2D bounding box extends infinitely in both directions along its normal
vector.
Point selection algorithm:
1. Project the points in view and drag box corners on to a plane
parallel to the canvas (i.e., normal direction is the view di... | _points_in_box_3d | python | napari/napari | src/napari/layers/points/_points_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_utils.py | BSD-3-Clause |
def points_in_box(
corners: np.ndarray, points: np.ndarray, sizes: np.ndarray
) -> list[int]:
"""Find which points are in an axis aligned box defined by its corners.
Parameters
----------
corners : (2, 2) array
The top-left and bottom-right corners of the box.
points : (N, 2) array
... | Find which points are in an axis aligned box defined by its corners.
Parameters
----------
corners : (2, 2) array
The top-left and bottom-right corners of the box.
points : (N, 2) array
Points to be checked
sizes : (N,) array
Size of each point
Returns
-------
i... | points_in_box | python | napari/napari | src/napari/layers/points/_points_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_utils.py | BSD-3-Clause |
def fix_data_points(
points: np.ndarray | None, ndim: int | None
) -> tuple[np.ndarray, int]:
"""
Ensure that points array is 2d and have second dimension of size ndim (default 2 for empty arrays)
Parameters
----------
points : (N, M) array or None
Points to be checked
ndim : int or... |
Ensure that points array is 2d and have second dimension of size ndim (default 2 for empty arrays)
Parameters
----------
points : (N, M) array or None
Points to be checked
ndim : int or None
number of expected dimensions
Returns
-------
points : (N, M) array
Po... | fix_data_points | python | napari/napari | src/napari/layers/points/_points_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_utils.py | BSD-3-Clause |
def symbol_conversion(symbol: str | Symbol) -> Symbol:
"""
Convert a string or Symbol to a Symbol instance.
"""
if isinstance(symbol, str):
symbol = SYMBOL_ALIAS.get(symbol, symbol)
return Symbol(symbol) |
Convert a string or Symbol to a Symbol instance.
| symbol_conversion | python | napari/napari | src/napari/layers/points/_points_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_utils.py | BSD-3-Clause |
def fast_dict_get(symbols: np.ndarray | list, d: dict) -> np.ndarray:
"""
Get the values from a dictionary using a list of keys.
"""
# dtype has to be object, otherwise np.vectorize will cut it down to `U(N)`,
# where N is the biggest string currently in the array.
return np.vectorize(d.__getite... |
Get the values from a dictionary using a list of keys.
| fast_dict_get | python | napari/napari | src/napari/layers/points/_points_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_utils.py | BSD-3-Clause |
def coerce_symbols(
symbol: str | Symbol | Sequence[str | Symbol],
) -> np.ndarray:
"""
Parse an array of symbols and convert it to the correct strings.
If single value is given, it is converted to single element array.
Ensures that all strings are valid symbols and convert aliases.
Parameters... |
Parse an array of symbols and convert it to the correct strings.
If single value is given, it is converted to single element array.
Ensures that all strings are valid symbols and convert aliases.
Parameters
----------
symbol : str or Symbol or Sequence of str or Symbol
data to be conv... | coerce_symbols | python | napari/napari | src/napari/layers/points/_points_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/points/_points_utils.py | BSD-3-Clause |
def test_empty_points_with_features():
"""See the following for the issues this covers:
https://github.com/napari/napari/issues/5632
https://github.com/napari/napari/issues/5634
"""
points = Points(
features={'a': np.empty(0, int)},
feature_defaults={'a': 0},
face_color='a',
... | See the following for the issues this covers:
https://github.com/napari/napari/issues/5632
https://github.com/napari/napari/issues/5634
| test_empty_points_with_features | 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_points_with_properties():
"""Test instantiating an empty Points layer with properties
See: https://github.com/napari/napari/pull/1069
"""
properties = {
'label': np.array(['label1', 'label2']),
'cont_prop': np.array([0], dtype=float),
}
pts = Points(property_choic... | Test instantiating an empty Points layer with properties
See: https://github.com/napari/napari/pull/1069
| test_empty_points_with_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_empty_points_with_properties_list():
"""Test instantiating an empty Points layer with properties
stored in a list
See: https://github.com/napari/napari/pull/1069
"""
properties = {'label': ['label1', 'label2'], 'cont_prop': [0]}
pts = Points(property_choices=properties)
current_pro... | Test instantiating an empty Points layer with properties
stored in a list
See: https://github.com/napari/napari/pull/1069
| test_empty_points_with_properties_list | 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_layer_with_face_colormap():
"""Test creating an empty layer where the face color is a colormap
See: https://github.com/napari/napari/pull/1069
"""
default_properties = {'point_type': np.array([1.5], dtype=float)}
layer = Points(
property_choices=default_properties,
fac... | Test creating an empty layer where the face color is a colormap
See: https://github.com/napari/napari/pull/1069
| test_empty_layer_with_face_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_set_current_properties_on_empty_layer_with_color_cycle(feature_name):
"""Test setting current_properties an empty layer where the face/border color
is a color cycle.
See: https://github.com/napari/napari/pull/3110
"""
default_properties = {'annotation': np.array(['tail', 'nose', 'paw'])}
... | Test setting current_properties an empty layer where the face/border color
is a color cycle.
See: https://github.com/napari/napari/pull/3110
| test_set_current_properties_on_empty_layer_with_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_empty_layer_with_text_properties():
"""Test initializing an empty layer with text defined"""
default_properties = {'point_type': np.array([1.5], dtype=float)}
text_kwargs = {'string': 'point_type', 'color': 'red'}
layer = Points(
property_choices=default_properties,
text=text_kw... | Test initializing an empty layer with text defined | test_empty_layer_with_text_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_random_points():
"""Test instantiating Points layer with random 2D data."""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == shape[1]
assert layer._view_data.ndim == 2
asse... | Test instantiating Points layer with random 2D data. | test_random_points | 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_integer_points():
"""Test instantiating Points layer with integer data."""
shape = (10, 2)
np.random.seed(0)
data = np.random.randint(20, size=shape)
layer = Points(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == shape[1]
assert layer._view_data.ndim == 2
... | Test instantiating Points layer with integer data. | test_integer_points | 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_negative_points():
"""Test instantiating Points layer with negative data."""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape) - 10
layer = Points(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == shape[1]
assert layer._view_data.ndim == 2
... | Test instantiating Points layer with negative data. | test_negative_points | 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_points_array():
"""Test instantiating Points layer with empty array."""
shape = (0, 2)
data = np.empty(shape)
layer = Points(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == shape[1]
assert layer._view_data.ndim == 2
assert len(layer.data) == 0 | Test instantiating Points layer with empty array. | test_empty_points_array | 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_3D_points():
"""Test instantiating Points layer with random 3D data."""
shape = (10, 3)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == shape[1]
assert layer._view_data.ndim == 2
assert l... | Test instantiating Points layer with random 3D data. | test_3D_points | 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_single_point_extent():
"""Test extent of a single 3D point at the origin."""
shape = (1, 3)
data = np.zeros(shape)
layer = Points(data)
assert np.array_equal(layer.extent.data, np.zeros((2, 3)))
assert np.array_equal(layer.extent.world, np.zeros((2, 3)))
assert np.array_equal(layer.... | Test extent of a single 3D point at the origin. | test_single_point_extent | 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_4D_points():
"""Test instantiating Points layer with random 4D data."""
shape = (10, 4)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == shape[1]
assert layer._view_data.ndim == 2
assert l... | Test instantiating Points layer with random 4D data. | test_4D_points | 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_points_to_empty():
"""Test adding Points data to empty."""
shape = (0, 2)
data = np.empty(shape)
layer = Points(data)
assert len(layer.data) == 0
coord = [20, 20]
layer.add(coord)
assert len(layer.data) == 1
assert np.array_equal(layer.data[0], coord)
assert laye... | Test adding Points data to empty. | test_adding_points_to_empty | 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_deleting_selected_value_changes():
"""Test deleting selected points appropriately sets self._value"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data)
# removing with self._value selected resets self._value to None
layer._value = 1
laye... | Test deleting selected points appropriately sets self._value | test_deleting_selected_value_changes | 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_remove_selected_updates_value():
"""Test that removing a point that is not layer._value
updates the index to account for the removed data.
"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data)
old_data = layer.data
layer.events.data ... | Test that removing a point that is not layer._value
updates the index to account for the removed data.
| test_remove_selected_updates_value | 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_remove_selected_removes_corresponding_attributes():
"""Test that removing points at specific indices also removes any per-point
attribute at the same index"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
size = np.random.rand(shape[0])
symbol = np.random.cho... | Test that removing points at specific indices also removes any per-point
attribute at the same index | test_remove_selected_removes_corresponding_attributes | 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_properties(attribute):
"""Test adding properties to an existing layer"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data)
# add properties
properties = {'point_type': _make_cycled_properties(['A', 'B'], shape[0])}
layer.propertie... | Test adding properties to an existing layer | test_adding_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_properties_dataframe():
"""Test if properties can be provided as a DataFrame"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
properties = {'point_type': _make_cycled_properties(['A', 'B'], shape[0])}
properties_df = pd.DataFrame(properties)
properties_df = p... | Test if properties can be provided as a DataFrame | test_properties_dataframe | 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_from_property_value(properties):
"""Test setting text from a property value"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(data, properties=copy(properties), text='point_type')
np.testing.assert_equal(layer.text.values, properties['point_ty... | Test setting text from a property value | test_text_from_property_value | 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_from_property_fstring(properties):
"""Test setting text with an f-string from the property value"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
layer = Points(
data, properties=copy(properties), text='type: {point_type}'
)
expected_text = ['ty... | Test setting text with an f-string from the property value | test_text_from_property_fstring | 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_error(properties):
"""creating a layer with text as the wrong type should raise an error"""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
# try adding text as the wrong type
with pytest.raises(ValidationError):
Points(data, properties=copy(properties... | creating a layer with text as the wrong type should raise an error | test_text_error | 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_select_properties_object_dtype():
"""selecting points when they have a property of object dtype should not fail"""
# pandas uses object as dtype for strings by default
properties = pd.DataFrame({'color': ['red', 'green']})
pl = Points(np.ones((2, 2)), properties=properties)
selection = {0, ... | selecting points when they have a property of object dtype should not fail | test_select_properties_object_dtype | 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_select_properties_unsortable():
"""selecting multiple points when they have properties that cannot be sorted should not fail
see https://github.com/napari/napari/issues/5174
"""
properties = pd.DataFrame({'unsortable': [{}, {}]})
pl = Points(np.ones((2, 2)), properties=properties)
sele... | selecting multiple points when they have properties that cannot be sorted should not fail
see https://github.com/napari/napari/issues/5174
| test_select_properties_unsortable | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.