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 make_full(
cls,
point=None,
margin_left=None,
margin_right=None,
ndim=None,
):
"""
Make a full slice based on minimal input.
If ndim is provided, it will be used to crop or prepend zeros to the given values.
Values not provided will be fil... |
Make a full slice based on minimal input.
If ndim is provided, it will be used to crop or prepend zeros to the given values.
Values not provided will be filled zeros.
| make_full | python | napari/napari | src/napari/layers/utils/_slice_input.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_slice_input.py | BSD-3-Clause |
def copy_with(
self,
point=None,
margin_left=None,
margin_right=None,
ndim=None,
):
"""Create a copy, but modifying the given fields."""
return self.make_full(
point=point or self.point,
margin_left=margin_left or self.margin_left,
... | Create a copy, but modifying the given fields. | copy_with | python | napari/napari | src/napari/layers/utils/_slice_input.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_slice_input.py | BSD-3-Clause |
def from_array(cls, arr: npt.NDArray) -> _ThickNDSlice:
"""Construct from a (3, D) array of point, left margin and right margin."""
return cls(
point=tuple(arr[0]),
margin_left=tuple(arr[1]),
margin_right=tuple(arr[2]),
) | Construct from a (3, D) array of point, left margin and right margin. | from_array | python | napari/napari | src/napari/layers/utils/_slice_input.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_slice_input.py | BSD-3-Clause |
def with_ndim(self, ndim: int) -> _SliceInput:
"""Returns a new instance with the given number of layer dimensions."""
old_ndim = self.ndim
world_slice = self.world_slice.copy_with(ndim=ndim)
if old_ndim > ndim:
order = reorder_after_dim_reduction(self.order[-ndim:])
... | Returns a new instance with the given number of layer dimensions. | with_ndim | python | napari/napari | src/napari/layers/utils/_slice_input.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_slice_input.py | BSD-3-Clause |
def data_slice(
self,
world_to_data: Affine,
) -> _ThickNDSlice[float | int]:
"""Transforms this thick_slice into data coordinates with only relevant dimensions.
The elements in non-displayed dimensions will be real numbers.
The elements in displayed dimensions will be ``sli... | Transforms this thick_slice into data coordinates with only relevant dimensions.
The elements in non-displayed dimensions will be real numbers.
The elements in displayed dimensions will be ``slice(None)``.
| data_slice | python | napari/napari | src/napari/layers/utils/_slice_input.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_slice_input.py | BSD-3-Clause |
def is_orthogonal(self, world_to_data: Affine) -> bool:
"""Returns True if this slice represents an orthogonal slice through a layer's data, False otherwise."""
# Subspace spanned by non displayed dimensions
non_displayed_subspace = np.zeros(self.ndim)
for d in self.not_displayed:
... | Returns True if this slice represents an orthogonal slice through a layer's data, False otherwise. | is_orthogonal | python | napari/napari | src/napari/layers/utils/_slice_input.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_slice_input.py | BSD-3-Clause |
def _calculate_bbox_centers(view_data: np.ndarray | list) -> np.ndarray:
"""
Calculate the bounding box of the given centers,
Parameters
----------
view_data : np.ndarray | list of ndarray
if an ndarray, return the center across the 0-th axis.
if a list, return the bbox center for e... |
Calculate the bounding box of the given centers,
Parameters
----------
view_data : np.ndarray | list of ndarray
if an ndarray, return the center across the 0-th axis.
if a list, return the bbox center for each items.
Returns
-------
An ndarray of the centers.
| _calculate_bbox_centers | python | napari/napari | src/napari/layers/utils/_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_text_utils.py | BSD-3-Clause |
def _calculate_bbox_extents(
view_data: np.ndarray | list,
) -> tuple[npt.NDArray, npt.NDArray]:
"""Calculate the extents of the bounding box"""
if isinstance(view_data, np.ndarray):
if view_data.ndim == 2:
# if the data are a list of coordinates, just return the coord (e.g., points)
... | Calculate the extents of the bounding box | _calculate_bbox_extents | python | napari/napari | src/napari/layers/utils/_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_text_utils.py | BSD-3-Clause |
def test_set_color_direct(color):
"""Test setting the colors via the set_color method in direct mode"""
# create an empty color manager
cm = ColorManager()
np.testing.assert_allclose(cm.colors, np.empty((0, 4)))
assert cm.color_mode == 'direct'
# set colors
expected_colors = np.array([[1, 0... | Test setting the colors via the set_color method in direct mode | test_set_color_direct | python | napari/napari | src/napari/layers/utils/_tests/test_color_manager.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_color_manager.py | BSD-3-Clause |
def test_color_cycle(color_cycle):
"""Test setting color with a color cycle list"""
# create Points using list color cycle
n_colors = 10
properties = {
'name': 'point_type',
'values': _make_cycled_properties(['A', 'B'], n_colors),
}
cm = ColorManager(
color_mode='cycle',
... | Test setting color with a color cycle list | test_color_cycle | python | napari/napari | src/napari/layers/utils/_tests/test_color_manager.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_color_manager.py | BSD-3-Clause |
def test_init_color_manager_cycle_with_colors_dict():
"""Test initializing color cycle ColorManager from layer kwargs
where the colors are given as a dictionary of ColorManager
fields/values
"""
n_colors = 10
color_cycle = [[0, 0, 0, 1], [1, 1, 1, 1]]
properties = {'point_type': _make_cycled... | Test initializing color cycle ColorManager from layer kwargs
where the colors are given as a dictionary of ColorManager
fields/values
| test_init_color_manager_cycle_with_colors_dict | python | napari/napari | src/napari/layers/utils/_tests/test_color_manager.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_color_manager.py | BSD-3-Clause |
def test_init_color_manager_colormap_with_colors_dict():
"""Test initializing colormap ColorManager from layer kwargs
where the colors are given as a dictionary of ColorManager
fields/values
"""
n_colors = 10
color_cycle = [[0, 0, 0, 1], [1, 1, 1, 1]]
properties = {'point_type': _make_cycled... | Test initializing colormap ColorManager from layer kwargs
where the colors are given as a dictionary of ColorManager
fields/values
| test_init_color_manager_colormap_with_colors_dict | python | napari/napari | src/napari/layers/utils/_tests/test_color_manager.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_color_manager.py | BSD-3-Clause |
def test_color_manager_invalid_color_properties():
"""Passing an invalid property name for color_properties
should raise a KeyError
"""
n_colors = 10
color_cycle = [[0, 0, 0, 1], [1, 1, 1, 1]]
properties = {'point_type': _make_cycled_properties([0, 1.5], n_colors)}
colors_dict = {
'c... | Passing an invalid property name for color_properties
should raise a KeyError
| test_color_manager_invalid_color_properties | python | napari/napari | src/napari/layers/utils/_tests/test_color_manager.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_color_manager.py | BSD-3-Clause |
def test_is_colormapped_dict():
"""Colors passed as dicts are treated as colormapped"""
color = {0: np.array([1, 1, 1, 1]), 1: np.array([1, 1, 0, 1])}
properties = {
'hello': np.array([1, 1, 1, 1]),
'hi': np.array([1, 0, 0, 1]),
}
assert is_color_mapped(color, properties) | Colors passed as dicts are treated as colormapped | test_is_colormapped_dict | python | napari/napari | src/napari/layers/utils/_tests/test_color_manager_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_color_manager_utils.py | BSD-3-Clause |
def test_is_colormapped_array():
"""Colors passed as list/array are treated as not colormapped"""
color_list = [[1, 1, 1, 1], [1, 1, 0, 1]]
properties = {
'hello': np.array([1, 1, 1, 1]),
'hi': np.array([1, 0, 0, 1]),
}
assert not is_color_mapped(color_list, properties)
color_ar... | Colors passed as list/array are treated as not colormapped | test_is_colormapped_array | python | napari/napari | src/napari/layers/utils/_tests/test_color_manager_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_color_manager_utils.py | BSD-3-Clause |
def test_transform_color_basic():
"""Test inner method with the same name."""
shape = (10, 2)
np.random.seed(0)
data = 20 * np.random.random(shape)
colorarray = transform_color_with_defaults(
num_entries=len(data),
colors='r',
elem_name='edge_color',
default='black',
... | Test inner method with the same name. | test_transform_color_basic | python | napari/napari | src/napari/layers/utils/_tests/test_color_transforms.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_color_transforms.py | BSD-3-Clause |
def test_link_image_layers_all_attributes(key, value):
"""Test linking common attributes across layers of similar types."""
l1 = layers.Image(np.random.rand(10, 10), contrast_limits=(0, 0.8))
l2 = layers.Image(np.random.rand(10, 10), contrast_limits=(0.1, 0.9))
link_layers([l1, l2])
# linking does (... | Test linking common attributes across layers of similar types. | test_link_image_layers_all_attributes | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_link_different_type_layers_all_attributes(key, value):
"""Test linking common attributes across layers of different types."""
l1 = layers.Image(np.random.rand(10, 10))
l2 = layers.Points(None)
link_layers([l1, l2])
# once we set either... they will both be changed
assert getattr(l1, ke... | Test linking common attributes across layers of different types. | test_link_different_type_layers_all_attributes | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_link_invalid_param():
"""Test that linking non-shared attributes raises."""
l1 = layers.Image(np.random.rand(10, 10))
l2 = layers.Points(None)
with pytest.raises(ValueError, match='not shared by all layers'):
link_layers([l1, l2], ('rendering',)) | Test that linking non-shared attributes raises. | test_link_invalid_param | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_adding_points_to_linked_layer():
"""Test that points can be added to a Points layer that is linked"""
l1 = layers.Points(None)
l2 = layers.Points(None)
link_layers([l1, l2])
l2.add([20, 20])
assert len(l2.data) | Test that points can be added to a Points layer that is linked | test_adding_points_to_linked_layer | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_linking_layers_with_different_modes():
"""Test that layers with different modes can be linked"""
l1 = layers.Image(np.empty((10, 10)))
l2 = layers.Labels(np.empty((10, 10), dtype=np.uint8))
link_layers([l1, l2])
l2.mode = 'paint'
assert l1.mode == 'pan_zoom'
assert l2.mode == 'pain... | Test that layers with different modes can be linked | test_linking_layers_with_different_modes | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_double_linking_noop():
"""Test that linking already linked layers is a noop."""
l1 = layers.Points(None)
l2 = layers.Points(None)
l3 = layers.Points(None)
# no callbacks to begin with
assert len(l1.events.opacity.callbacks) == 0
# should have two after linking layers
link_layer... | Test that linking already linked layers is a noop. | test_double_linking_noop | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_context_manager():
"""Test that we can temporarily link layers."""
l1 = layers.Points(None)
l2 = layers.Points(None)
l3 = layers.Points(None)
assert len(l1.events.opacity.callbacks) == 0
with layers_linked([l1, l2, l3], ('opacity',)):
assert len(l1.events.opacity.callbacks) == 2... | Test that we can temporarily link layers. | test_context_manager | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_unlink_layers():
"""Test that we can unlink layers."""
l1 = layers.Points(None)
l2 = layers.Points(None)
l3 = layers.Points(None)
link_layers([l1, l2, l3])
assert len(l1.events.opacity.callbacks) == 2
unlink_layers([l1, l2], ('opacity',)) # just unlink opacity on l1/l2
assert... | Test that we can unlink layers. | test_unlink_layers | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_unlink_single_layer():
"""Test that we can unlink a single layer from all others."""
l1 = layers.Points(None)
l2 = layers.Points(None)
l3 = layers.Points(None)
link_layers([l1, l2, l3])
assert len(l1.events.opacity.callbacks) == 2
unlink_layers([l1], ('opacity',)) # just unlink L1... | Test that we can unlink a single layer from all others. | test_unlink_single_layer | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_link_layers_with_images_then_loaded_not_linked():
"""See https://github.com/napari/napari/issues/6372"""
l1 = layers.Image(np.zeros((5, 5)))
l2 = layers.Image(np.ones((5, 5)))
assert l1.loaded
assert l2.loaded
link_layers([l1, l2])
l1._set_loaded(False)
assert not l1.loaded
... | See https://github.com/napari/napari/issues/6372 | test_link_layers_with_images_then_loaded_not_linked | python | napari/napari | src/napari/layers/utils/_tests/test_link_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_link_layers.py | BSD-3-Clause |
def test_plane_3_tuple():
"""Test for failure to instantiate with non 3-sequences of numbers"""
with pytest.raises(ValidationError):
plane = SlicingPlane( # noqa: F841
position=(32, 32, 32, 32),
normal=(1, 0, 0, 0),
) | Test for failure to instantiate with non 3-sequences of numbers | test_plane_3_tuple | python | napari/napari | src/napari/layers/utils/_tests/test_plane.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_plane.py | BSD-3-Clause |
def test_stack_to_images_basic():
"""Test that a 2 channel zcyx stack is split into 2 image layers"""
data = np.random.randint(0, 100, (10, 2, 128, 128))
stack = Image(data)
images = stack_to_images(stack, 1, colormap=None)
assert isinstance(images, list)
assert images[0].colormap.name == 'mage... | Test that a 2 channel zcyx stack is split into 2 image layers | test_stack_to_images_basic | python | napari/napari | src/napari/layers/utils/_tests/test_stack_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_stack_utils.py | BSD-3-Clause |
def test_stack_to_images_multiscale():
"""Test that a 3 channel multiscale image returns 3 multiscale images."""
data = []
data.append(np.zeros((3, 128, 128)))
data.append(np.zeros((3, 64, 64)))
data.append(np.zeros((3, 32, 32)))
data.append(np.zeros((3, 16, 16)))
stack = Image(data)
im... | Test that a 3 channel multiscale image returns 3 multiscale images. | test_stack_to_images_multiscale | python | napari/napari | src/napari/layers/utils/_tests/test_stack_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_stack_utils.py | BSD-3-Clause |
def test_stack_to_images_rgb():
"""Test 3 channel RGB image (channel axis = -1) into single channels."""
data = np.random.randint(0, 100, (10, 128, 128, 3))
stack = Image(data)
images = stack_to_images(stack, -1, colormap=None)
assert isinstance(images, list)
assert len(images) == 3
for i ... | Test 3 channel RGB image (channel axis = -1) into single channels. | test_stack_to_images_rgb | python | napari/napari | src/napari/layers/utils/_tests/test_stack_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_stack_utils.py | BSD-3-Clause |
def test_stack_to_images_4_channels():
"""Test 4x128x128 stack is split into 4 channels w/ colormap keyword"""
data = np.random.randint(0, 100, (4, 128, 128))
stack = Image(data)
images = stack_to_images(stack, 0, colormap=['red', 'blue'])
assert isinstance(images, list)
assert len(images) == 4... | Test 4x128x128 stack is split into 4 channels w/ colormap keyword | test_stack_to_images_4_channels | python | napari/napari | src/napari/layers/utils/_tests/test_stack_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_stack_utils.py | BSD-3-Clause |
def test_stack_to_images_0_rgb():
"""Split RGB along the first axis (z or t) so the images remain rgb"""
data = np.random.randint(0, 100, (10, 128, 128, 3))
stack = Image(data)
images = stack_to_images(stack, 0, colormap=None)
assert isinstance(images, list)
assert len(images) == 10
for i i... | Split RGB along the first axis (z or t) so the images remain rgb | test_stack_to_images_0_rgb | python | napari/napari | src/napari/layers/utils/_tests/test_stack_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_stack_utils.py | BSD-3-Clause |
def test_images_to_stack_with_scale():
"""Test that 3-Image list is combined to stack with scale and translate."""
images = [
Image(np.random.randint(0, 255, (10, 128, 128))) for _ in range(3)
]
stack = images_to_stack(
images, 1, colormap='green', scale=(3, 1, 1, 1), translate=(1, 0, 2... | Test that 3-Image list is combined to stack with scale and translate. | test_images_to_stack_with_scale | python | napari/napari | src/napari/layers/utils/_tests/test_stack_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_stack_utils.py | BSD-3-Clause |
def test_images_to_stack_none_scale():
"""Test combining images using scale & translate from 1st image in list"""
images = [
Image(
np.random.randint(0, 255, (10, 128, 128)),
scale=(4, 1, 1),
translate=(0, -1, 2),
)
for _ in range(3)
]
stack =... | Test combining images using scale & translate from 1st image in list | test_images_to_stack_none_scale | python | napari/napari | src/napari/layers/utils/_tests/test_stack_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_stack_utils.py | BSD-3-Clause |
def test_split_and_merge_rgb():
"""Test merging 3 images with RGB colormaps into single RGB image."""
# Make an RGB
data = np.random.randint(0, 100, (10, 128, 128, 3))
stack = Image(data)
assert stack.rgb is True
# split the RGB into 3 images
images = split_rgb(stack)
assert len(images)... | Test merging 3 images with RGB colormaps into single RGB image. | test_split_and_merge_rgb | python | napari/napari | src/napari/layers/utils/_tests/test_stack_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_stack_utils.py | BSD-3-Clause |
def test_split_channels_multiscale(kwargs):
"""Test split_channels with multiscale expecting List[LayerData]"""
data = []
data.append(np.zeros((3, 128, 128)))
data.append(np.zeros((3, 64, 64)))
data.append(np.zeros((3, 32, 32)))
data.append(np.zeros((3, 16, 16)))
result_list = split_channels... | Test split_channels with multiscale expecting List[LayerData] | test_split_channels_multiscale | python | napari/napari | src/napari/layers/utils/_tests/test_stack_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_stack_utils.py | BSD-3-Clause |
def test_empty_text_manager_property():
"""Test creating an empty text manager in property mode.
This is for creating an empty layer with text initialized.
"""
properties = {'confidence': np.empty(0, dtype=float)}
text_manager = TextManager(
text='confidence', n_text=0, properties=properties... | Test creating an empty text manager in property mode.
This is for creating an empty layer with text initialized.
| test_empty_text_manager_property | python | napari/napari | src/napari/layers/utils/_tests/test_text_manager.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_manager.py | BSD-3-Clause |
def test_empty_text_manager_format():
"""Test creating an empty text manager in formatted mode.
This is for creating an empty layer with text initialized.
"""
properties = {'confidence': np.empty(0, dtype=float)}
text = 'confidence: {confidence:.2f}'
text_manager = TextManager(text=text, n_text=... | Test creating an empty text manager in formatted mode.
This is for creating an empty layer with text initialized.
| test_empty_text_manager_format | python | napari/napari | src/napari/layers/utils/_tests/test_text_manager.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_manager.py | BSD-3-Clause |
def test_compute_text_coords(ndim, ndisplay, translation):
"""See https://github.com/napari/napari/issues/5111"""
num_points = 3
text_manager = TextManager(
features=pd.DataFrame(index=range(num_points)),
translation=translation,
)
np.random.seed(0)
# Cannot just use `rand(num_po... | See https://github.com/napari/napari/issues/5111 | test_compute_text_coords | python | napari/napari | src/napari/layers/utils/_tests/test_text_manager.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_manager.py | BSD-3-Clause |
def test_bbox_center(view_data, expected_coords):
"""Unit test for _calculate_anchor_center. Roundtrip test in test_get_text_anchors"""
anchor_data = _calculate_anchor_center(view_data, ndisplay=2)
expected_anchor_data = (expected_coords, 'center', 'center')
np.testing.assert_equal(anchor_data, expected... | Unit test for _calculate_anchor_center. Roundtrip test in test_get_text_anchors | test_bbox_center | python | napari/napari | src/napari/layers/utils/_tests/test_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_utils.py | BSD-3-Clause |
def test_bbox_upper_left(view_data, expected_coords):
"""Unit test for _calculate_anchor_upper_left. Roundtrip test in test_get_text_anchors"""
expected_anchor_data = (expected_coords, 'left', 'top')
anchor_data = _calculate_anchor_upper_left(view_data, ndisplay=2)
np.testing.assert_equal(anchor_data, e... | Unit test for _calculate_anchor_upper_left. Roundtrip test in test_get_text_anchors | test_bbox_upper_left | python | napari/napari | src/napari/layers/utils/_tests/test_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_utils.py | BSD-3-Clause |
def test_bbox_upper_right(view_data, expected_coords):
"""Unit test for _calculate_anchor_upper_right. Roundtrip test in test_get_text_anchors"""
expected_anchor_data = (expected_coords, 'right', 'top')
anchor_data = _calculate_anchor_upper_right(view_data, ndisplay=2)
np.testing.assert_equal(anchor_dat... | Unit test for _calculate_anchor_upper_right. Roundtrip test in test_get_text_anchors | test_bbox_upper_right | python | napari/napari | src/napari/layers/utils/_tests/test_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_utils.py | BSD-3-Clause |
def test_bbox_lower_left(view_data, expected_coords):
"""Unit test for _calculate_anchor_lower_left. Roundtrip test in test_get_text_anchors"""
expected_anchor_data = (expected_coords, 'left', 'bottom')
anchor_data = _calculate_anchor_lower_left(view_data, ndisplay=2)
np.testing.assert_equal(anchor_data... | Unit test for _calculate_anchor_lower_left. Roundtrip test in test_get_text_anchors | test_bbox_lower_left | python | napari/napari | src/napari/layers/utils/_tests/test_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_utils.py | BSD-3-Clause |
def test_bbox_lower_right(view_data, expected_coords):
"""Unit test for _calculate_anchor_lower_right. Roundtrip test in test_get_text_anchors"""
expected_anchor_data = (expected_coords, 'right', 'bottom')
anchor_data = _calculate_anchor_lower_right(view_data, ndisplay=2)
np.testing.assert_equal(anchor_... | Unit test for _calculate_anchor_lower_right. Roundtrip test in test_get_text_anchors | test_bbox_lower_right | python | napari/napari | src/napari/layers/utils/_tests/test_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_utils.py | BSD-3-Clause |
def test_get_text_anchors(anchor_type, ndisplay, expected_coords):
"""Round trip tests for getting anchor coordinates."""
coords = [np.array([[0, 0], [10, 0], [0, 10], [10, 10]])]
anchor_coords, _, _ = get_text_anchors(
coords, anchor=anchor_type, ndisplay=ndisplay
)
np.testing.assert_equal(... | Round trip tests for getting anchor coordinates. | test_get_text_anchors | python | napari/napari | src/napari/layers/utils/_tests/test_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_utils.py | BSD-3-Clause |
def test_bbox_centers_exception():
"""_calculate_bbox_centers should raise a TypeError for non ndarray or list inputs"""
with pytest.raises(TypeError):
_ = _calculate_bbox_centers({'bad_data_type': True}) | _calculate_bbox_centers should raise a TypeError for non ndarray or list inputs | test_bbox_centers_exception | python | napari/napari | src/napari/layers/utils/_tests/test_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_utils.py | BSD-3-Clause |
def test_bbox_extents_exception():
"""_calculate_bbox_extents should raise a TypeError for non ndarray or list inputs"""
with pytest.raises(TypeError):
_ = _calculate_bbox_extents({'bad_data_type': True}) | _calculate_bbox_extents should raise a TypeError for non ndarray or list inputs | test_bbox_extents_exception | python | napari/napari | src/napari/layers/utils/_tests/test_text_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/utils/_tests/test_text_utils.py | BSD-3-Clause |
def _view_face_color(self) -> np.ndarray:
"""(Mx4) np.ndarray : colors for the M in view triangles"""
# Create as many colors as there are visible vectors.
# Using fancy array indexing implicitly creates a new
# array rather than creating a view of the original one
# in ColorMan... | (Mx4) np.ndarray : colors for the M in view triangles | _view_face_color | python | napari/napari | src/napari/layers/vectors/vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/vectors.py | BSD-3-Clause |
def _make_slice_request(self, dims) -> _VectorSliceRequest:
"""Make a Vectors slice request based on the given dims and these data."""
slice_input = self._make_slice_input(dims)
# TODO: [see Image]
# For the existing sync slicing, slice_indices is passed through
# to avoid some... | Make a Vectors slice request based on the given dims and these data. | _make_slice_request | python | napari/napari | src/napari/layers/vectors/vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/vectors.py | BSD-3-Clause |
def _update_thumbnail(self):
"""Update thumbnail with current vectors and colors."""
# Set the default thumbnail to black, opacity 1
colormapped = np.zeros(self._thumbnail_shape, dtype=np.uint8)
colormapped[..., 3] = 1
if len(self.data) == 0:
self.thumbnail = colormap... | Update thumbnail with current vectors and colors. | _update_thumbnail | python | napari/napari | src/napari/layers/vectors/vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/vectors.py | BSD-3-Clause |
def convert_image_to_coordinates(vectors: npt.NDArray) -> npt.NDArray:
"""To convert an image-like array with elements (y-proj, x-proj) into a
position list of coordinates
Every pixel position (n, m) results in two output coordinates of (N,2)
Parameters
----------
vectors : (N1, N2, ..., ND, D)... | To convert an image-like array with elements (y-proj, x-proj) into a
position list of coordinates
Every pixel position (n, m) results in two output coordinates of (N,2)
Parameters
----------
vectors : (N1, N2, ..., ND, D) array
"image-like" data where there is a length D vector of the
... | convert_image_to_coordinates | python | napari/napari | src/napari/layers/vectors/_vector_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_vector_utils.py | BSD-3-Clause |
def fix_data_vectors(
vectors: np.ndarray | None, ndim: int | None
) -> tuple[np.ndarray, int]:
"""
Ensure that vectors array is 3d and have second dimension of size 2
and third dimension of size ndim (default 2 for empty arrays)
Parameters
----------
vectors : (N, 2, D) or (N1, N2, ..., ND... |
Ensure that vectors array is 3d and have second dimension of size 2
and third dimension of size ndim (default 2 for empty arrays)
Parameters
----------
vectors : (N, 2, D) or (N1, N2, ..., ND, D) array
A (N, 2, D) array is interpreted as "coordinate-like" data and a list
of N vecto... | fix_data_vectors | python | napari/napari | src/napari/layers/vectors/_vector_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_vector_utils.py | BSD-3-Clause |
def test_random_vectors():
"""Test instantiating Vectors layer with random coordinate-like 2D data."""
shape = (10, 2, 2)
np.random.seed(0)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
layer = Vectors(data)
np.testing.assert_array_equal(layer.data, data)
assert layer... | Test instantiating Vectors layer with random coordinate-like 2D data. | test_random_vectors | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_random_vectors_image():
"""Test instantiating Vectors layer with random image-like 2D data."""
shape = (20, 10, 2)
np.random.seed(0)
data = np.random.random(shape)
layer = Vectors(data)
assert layer.data.shape == (20 * 10, 2, 2)
assert layer.ndim == 2
assert layer._view_data.sha... | Test instantiating Vectors layer with random image-like 2D data. | test_random_vectors_image | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_no_args_vectors():
"""Test instantiating Vectors layer with no arguments"""
layer = Vectors()
assert layer.data.shape == (0, 2, 2) | Test instantiating Vectors layer with no arguments | test_no_args_vectors | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_no_data_vectors_with_ndim():
"""Test instantiating Vectors layers with no data but specifying ndim"""
layer = Vectors(ndim=2)
assert layer.data.shape[-1] == 2 | Test instantiating Vectors layers with no data but specifying ndim | test_no_data_vectors_with_ndim | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_incompatible_ndim_vectors():
"""Test instantiating Vectors layer with ndim argument incompatible with data"""
data = np.empty((0, 2, 2))
with pytest.raises(ValueError, match='must be equal to ndim'):
Vectors(data, ndim=3) | Test instantiating Vectors layer with ndim argument incompatible with data | test_incompatible_ndim_vectors | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_empty_vectors():
"""Test instantiating Vectors layer with empty coordinate-like 2D data."""
shape = (0, 2, 2)
data = np.empty(shape)
layer = Vectors(data)
np.testing.assert_array_equal(layer.data, data)
assert layer.data.shape == shape
assert layer.ndim == shape[2]
assert layer.... | Test instantiating Vectors layer with empty coordinate-like 2D data. | test_empty_vectors | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_empty_layer_with_edge_colormap():
"""Test creating an empty layer where the edge color is a colormap"""
shape = (0, 2, 2)
data = np.empty(shape)
default_properties = {'angle': np.array([1.5], dtype=float)}
layer = Vectors(
data=data,
property_choices=default_properties,
... | Test creating an empty layer where the edge color is a colormap | test_empty_layer_with_edge_colormap | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_empty_layer_with_edge_color_cycle():
"""Test creating an empty layer where the edge color is a color cycle"""
shape = (0, 2, 2)
data = np.empty(shape)
default_properties = {'vector_type': np.array(['A'])}
layer = Vectors(
data=data,
property_choices=default_properties,
... | Test creating an empty layer where the edge color is a color cycle | test_empty_layer_with_edge_color_cycle | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_random_3D_vectors():
"""Test instantiating Vectors layer with random coordinate-like 3D data."""
shape = (10, 2, 3)
np.random.seed(0)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
layer = Vectors(data)
np.testing.assert_array_equal(layer.data, data)
assert la... | Test instantiating Vectors layer with random coordinate-like 3D data. | test_random_3D_vectors | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_random_3D_vectors_image():
"""Test instantiating Vectors layer with random image-like 3D data."""
shape = (12, 20, 10, 3)
np.random.seed(0)
data = np.random.random(shape)
layer = Vectors(data)
assert layer.data.shape == (12 * 20 * 10, 2, 3)
assert layer.ndim == 3
assert layer._v... | Test instantiating Vectors layer with random image-like 3D data. | test_random_3D_vectors_image | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_empty_3D_vectors():
"""Test instantiating Vectors layer with empty coordinate-like 3D data."""
shape = (0, 2, 3)
data = np.empty(shape)
layer = Vectors(data)
np.testing.assert_array_equal(layer.data, data)
assert layer.data.shape == shape
assert layer.ndim == shape[2]
assert lay... | Test instantiating Vectors layer with empty coordinate-like 3D data. | test_empty_3D_vectors | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_properties_dataframe():
"""test if properties can be provided as a DataFrame"""
shape = (10, 2)
np.random.seed(0)
shape = (10, 2, 2)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
properties = {'vector_type': np.array(['A', 'B'] * int(shape[0] / 2))}
propertie... | test if properties can be provided as a DataFrame | test_properties_dataframe | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_adding_properties():
"""test adding properties to a Vectors layer"""
shape = (10, 2)
np.random.seed(0)
shape = (10, 2, 2)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
properties = {'vector_type': np.array(['A', 'B'] * int(shape[0] / 2))}
layer = Vectors(data... | test adding properties to a Vectors layer | test_adding_properties | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_invalid_edge_color():
"""Test providing an invalid edge color raises an exception"""
np.random.seed(0)
shape = (10, 2, 2)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
layer = Vectors(data)
with pytest.raises(ValueError, match='should be the name of a color'):
... | Test providing an invalid edge color raises an exception | test_invalid_edge_color | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_edge_color_cycle():
"""Test creating Vectors where edge color is set by a color cycle"""
np.random.seed(0)
shape = (10, 2, 2)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
properties = {'vector_type': np.array(['A', 'B'] * int(shape[0] / 2))}
color_cycle = ['red'... | Test creating Vectors where edge color is set by a color cycle | test_edge_color_cycle | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_edge_color_colormap():
"""Test creating Vectors where edge color is set by a colormap"""
shape = (10, 2)
shape = (10, 2, 2)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
properties = {'angle': np.array([0, 1.5] * int(shape[0] / 2))}
layer = Vectors(
data,... | Test creating Vectors where edge color is set by a colormap | test_edge_color_colormap | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_edge_color_map_non_numeric_property():
"""Test setting edge_color as a color map of a
non-numeric property raises an error
"""
np.random.seed(0)
shape = (10, 2, 2)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
properties = {'vector_type': np.array(['A', 'B'] ... | Test setting edge_color as a color map of a
non-numeric property raises an error
| test_edge_color_map_non_numeric_property | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_switching_edge_color_mode():
"""Test transitioning between all color modes"""
np.random.seed(0)
shape = (10, 2, 2)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
properties = {
'magnitude': np.arange(shape[0]),
'vector_type': np.array(['A', 'B'] * int(... | Test transitioning between all color modes | test_switching_edge_color_mode | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def test_properties_color_mode_without_properties():
"""Test that switching to a colormode requiring
properties without properties defined raises an exceptions
"""
np.random.seed(0)
shape = (10, 2, 2)
data = np.random.random(shape)
data[:, 0, :] = 20 * data[:, 0, :]
layer = Vectors(data)... | Test that switching to a colormode requiring
properties without properties defined raises an exceptions
| test_properties_color_mode_without_properties | python | napari/napari | src/napari/layers/vectors/_tests/test_vectors.py | https://github.com/napari/napari/blob/master/src/napari/layers/vectors/_tests/test_vectors.py | BSD-3-Clause |
def data_raw(
self,
) -> LayerDataProtocol | Sequence[LayerDataProtocol]:
"""Data, exactly as provided by the user."""
return self._data_raw | Data, exactly as provided by the user. | data_raw | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _extent_level_data(self) -> np.ndarray:
"""Extent of layer, accounting for current multiscale level, in data coordinates.
Returns
-------
extent_data : array, shape (2, D)
"""
shape = self.level_shapes[self.data_level]
return np.vstack([np.zeros(len(shape)), ... | Extent of layer, accounting for current multiscale level, in data coordinates.
Returns
-------
extent_data : array, shape (2, D)
| _extent_level_data | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _reset_plane_parameters(self):
"""Set plane attributes to something valid."""
self.plane.position = np.array(self.data.shape) / 2
self.plane.normal = (1, 0, 0) | Set plane attributes to something valid. | _reset_plane_parameters | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _update_plane_callbacks(self):
"""Set plane callbacks depending on depiction mode."""
plane_drag_callback_connected = (
plane_drag_callback in self.mouse_drag_callbacks
)
double_click_callback_connected = (
plane_double_click_callback in self.mouse_double_clic... | Set plane callbacks depending on depiction mode. | _update_plane_callbacks | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _set_view_slice(self) -> None:
"""Set the slice output based on this layer's current state."""
# 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... | Set the slice output based on this layer's current state. | _set_view_slice | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _make_slice_request(self, dims: Dims) -> _ImageSliceRequest:
"""Make an image slice request based on the given dims and this image."""
slice_input = self._make_slice_input(dims)
# For the existing sync slicing, indices is passed through
# to avoid some performance issues related to t... | Make an image slice request based on the given dims and this image. | _make_slice_request | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _make_slice_request_internal(
self,
*,
slice_input: _SliceInput,
data_slice: _ThickNDSlice,
dask_indexer: DaskIndexer,
) -> _ImageSliceRequest:
"""Needed to support old-style sync slicing through _slice_dims and
_set_view_slice.
This is temporary ... | Needed to support old-style sync slicing through _slice_dims and
_set_view_slice.
This is temporary scaffolding that should go away once we have completed
the async slicing project: https://github.com/napari/napari/issues/4795
| _make_slice_request_internal | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _update_slice_response(self, response: _ImageSliceResponse) -> None:
"""Update the slice output state currently on the layer. Currently used
for both sync and async slicing.
"""
response = response.to_displayed(self._raw_to_displayed)
# We call to_displayed here to ensure tha... | Update the slice output state currently on the layer. Currently used
for both sync and async slicing.
| _update_slice_response | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.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
-------
value : tuple
Value of the data.
"""
if self.mult... | Value of the data at a position in data coordinates.
Parameters
----------
position : tuple
Position in data coordinates.
Returns
-------
value : tuple
Value of the data.
| _get_value | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _get_value_ray(
self,
start_point: np.ndarray | None,
end_point: np.ndarray | None,
dims_displayed: list[int],
) -> int | None:
"""Get the first non-background value encountered along a ray.
Parameters
----------
start_point : np.ndarray
... | Get the first non-background value encountered along a ray.
Parameters
----------
start_point : np.ndarray
(n,) array containing the start point of the ray in data coordinates.
end_point : np.ndarray
(n,) array containing the end point of the ray in data coordina... | _get_value_ray | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _get_value_3d(
self,
start_point: np.ndarray | None,
end_point: np.ndarray | None,
dims_displayed: list[int],
) -> int | None | tuple[int, int | None]:
"""Get the first non-background value encountered along a ray.
Parameters
----------
start_poin... | Get the first non-background value encountered along a ray.
Parameters
----------
start_point : np.ndarray
(n,) array containing the start point of the ray in data coordinates.
end_point : np.ndarray
(n,) array containing the end point of the ray in data coordina... | _get_value_3d | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _display_bounding_box_at_level(
self, dims_displayed: list[int], data_level: int
) -> npt.NDArray:
"""An axis aligned (ndisplay, 2) bounding box around the data at a given level"""
shape = self.level_shapes[data_level]
extent_at_level = np.vstack([np.zeros(len(shape)), shape - 1]... | An axis aligned (ndisplay, 2) bounding box around the data at a given level | _display_bounding_box_at_level | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def _display_bounding_box_augmented_data_level(
self, dims_displayed: list[int]
) -> npt.NDArray:
"""An augmented, axis-aligned (ndisplay, 2) bounding box.
If the layer is multiscale layer, then returns the
bounding box of the data at the current level
"""
return self... | An augmented, axis-aligned (ndisplay, 2) bounding box.
If the layer is multiscale layer, then returns the
bounding box of the data at the current level
| _display_bounding_box_augmented_data_level | python | napari/napari | src/napari/layers/_scalar_field/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/layers/_scalar_field/scalar_field.py | BSD-3-Clause |
def test_dask_not_greedy(dtype):
"""Make sure that we don't immediately calculate dask arrays."""
FETCH_COUNT = 0
def get_plane(block_id):
if isinstance(block_id, tuple):
nonlocal FETCH_COUNT
FETCH_COUNT += 1
return np.random.rand(1, 1, 1, 10, 10)
arr = da.map_... | Make sure that we don't immediately calculate dask arrays. | test_dask_not_greedy | python | napari/napari | src/napari/layers/_tests/test_dask_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_dask_layers.py | BSD-3-Clause |
def test_dask_array_creates_cache():
"""Test that dask arrays create cache but turns off fusion."""
resize_dask_cache(1)
assert _dask_utils._DASK_CACHE.cache.available_bytes == 1
# by default we have no dask_cache and task fusion is active
original = dask.config.get('optimization.fuse.active', None)... | Test that dask arrays create cache but turns off fusion. | test_dask_array_creates_cache | python | napari/napari | src/napari/layers/_tests/test_dask_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_dask_layers.py | BSD-3-Clause |
def test_list_of_dask_arrays_doesnt_create_cache():
"""Test that adding a list of dask array also creates a dask cache."""
resize_dask_cache(1) # in case other tests created it
assert _dask_utils._DASK_CACHE.cache.available_bytes == 1
original = dask.config.get('optimization.fuse.active', None)
_ =... | Test that adding a list of dask array also creates a dask cache. | test_list_of_dask_arrays_doesnt_create_cache | python | napari/napari | src/napari/layers/_tests/test_dask_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_dask_layers.py | BSD-3-Clause |
def delayed_dask_stack():
"""A 4D (20, 10, 10, 10) delayed dask array, simulates disk io."""
# we will return a dict with a 'calls' variable that tracks call count
output = {'calls': 0}
# create a delayed version of function that simply generates np.arrays
# but also counts when it has been called
... | A 4D (20, 10, 10, 10) delayed dask array, simulates disk io. | delayed_dask_stack | python | napari/napari | src/napari/layers/_tests/test_dask_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_dask_layers.py | BSD-3-Clause |
def test_dask_global_optimized_slicing(delayed_dask_stack, monkeypatch):
"""Test that dask_configure reduces compute with dask stacks."""
# add dask stack to the viewer, making sure to pass multiscale and clims
v = ViewerModel()
dask_stack = delayed_dask_stack['stack']
layer = v.add_image(dask_stac... | Test that dask_configure reduces compute with dask stacks. | test_dask_global_optimized_slicing | python | napari/napari | src/napari/layers/_tests/test_dask_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_dask_layers.py | BSD-3-Clause |
def test_dask_cache_resizing(delayed_dask_stack):
"""Test that we can spin up, resize, and spin down the cache."""
# make sure we have a cache
# big enough for 10+ (10, 10, 10) "timepoints"
resize_dask_cache(100000)
# add dask stack to the viewer, making sure to pass multiscale and clims
v = ... | Test that we can spin up, resize, and spin down the cache. | test_dask_cache_resizing | python | napari/napari | src/napari/layers/_tests/test_dask_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_dask_layers.py | BSD-3-Clause |
def test_prevent_dask_cache(delayed_dask_stack):
"""Test that pre-emptively setting cache to zero keeps it off"""
resize_dask_cache(0)
v = ViewerModel()
dask_stack = delayed_dask_stack['stack']
# adding a new stack will not increase the cache size
v.add_image(dask_stack)
assert _dask_utils.... | Test that pre-emptively setting cache to zero keeps it off | test_prevent_dask_cache | python | napari/napari | src/napari/layers/_tests/test_dask_layers.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_dask_layers.py | BSD-3-Clause |
def test_get_value_at_subpixel_offsets(ImageClass, ndim):
"""check value at various shifts within a pixel/voxel's extent"""
if ndim == 3:
data = np.arange(1, 9).reshape(2, 2, 2)
elif ndim == 2:
data = np.arange(1, 5).reshape(2, 2)
# test using non-uniform scale per-axis
layer = Imag... | check value at various shifts within a pixel/voxel's extent | test_get_value_at_subpixel_offsets | python | napari/napari | src/napari/layers/_tests/test_layer_attributes.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_layer_attributes.py | BSD-3-Clause |
def test_layer_source():
"""Test basic layer source assignment mechanism"""
with layer_source(path='some_path', reader_plugin='napari'):
points = Points()
assert points.source == Source(path='some_path', reader_plugin='napari') | Test basic layer source assignment mechanism | test_layer_source | python | napari/napari | src/napari/layers/_tests/test_source.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_source.py | BSD-3-Clause |
def test_cant_overwrite_source():
"""Test that we can't overwrite the source of a layer."""
with layer_source(path='some_path', reader_plugin='napari'):
points = Points()
assert points.source == Source(path='some_path', reader_plugin='napari')
with pytest.raises(ValueError, match='Tried to set s... | Test that we can't overwrite the source of a layer. | test_cant_overwrite_source | python | napari/napari | src/napari/layers/_tests/test_source.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_source.py | BSD-3-Clause |
def test_source_context():
"""Test nested contexts, overrides, and resets."""
assert current_source() == Source()
# everything created within this context will have this sample source
with layer_source(sample=('samp', 'name')):
assert current_source() == Source(sample=('samp', 'name'))
... | Test nested contexts, overrides, and resets. | test_source_context | python | napari/napari | src/napari/layers/_tests/test_source.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/test_source.py | BSD-3-Clause |
def compare_dicts(dict1, dict2):
"""
The compare_dicts method compares two dictionaries for equality.
This is mainly used to allow for layer.data.events tests in order to avoid comparison of 2 arrays.
dict1
dict to be compared to other dict2
dict2
dict to be compared to other dict1... |
The compare_dicts method compares two dictionaries for equality.
This is mainly used to allow for layer.data.events tests in order to avoid comparison of 2 arrays.
dict1
dict to be compared to other dict2
dict2
dict to be compared to other dict1
Returns
-------
bool
... | compare_dicts | python | napari/napari | src/napari/layers/_tests/_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/_tests/_utils.py | BSD-3-Clause |
def format_exceptions(
plugin_name: str, as_html: bool = False, color='Neutral'
):
"""Return formatted tracebacks for all exceptions raised by plugin.
Parameters
----------
plugin_name : str
The name of a plugin for which to retrieve tracebacks.
as_html : bool
Whether to return ... | Return formatted tracebacks for all exceptions raised by plugin.
Parameters
----------
plugin_name : str
The name of a plugin for which to retrieve tracebacks.
as_html : bool
Whether to return the exception string as formatted html,
defaults to False.
Returns
-------
... | format_exceptions | python | napari/napari | src/napari/plugins/exceptions.py | https://github.com/napari/napari/blob/master/src/napari/plugins/exceptions.py | BSD-3-Clause |
def napari_provide_sample_data() -> dict[str, SampleData | SampleDict]:
"""Provide sample data.
Plugins may implement this hook to provide sample data for use in napari.
Sample data is accessible in the `File > Open Sample` menu, or
programmatically, with :meth:`napari.Viewer.open_sample`.
Plugins... | Provide sample data.
Plugins may implement this hook to provide sample data for use in napari.
Sample data is accessible in the `File > Open Sample` menu, or
programmatically, with :meth:`napari.Viewer.open_sample`.
Plugins implementing this hook specification must return a ``dict``, where
each ke... | napari_provide_sample_data | python | napari/napari | src/napari/plugins/hook_specifications.py | https://github.com/napari/napari/blob/master/src/napari/plugins/hook_specifications.py | BSD-3-Clause |
def napari_get_reader(path: str | list[str]) -> ReaderFunction | None:
"""Return a function capable of loading ``path`` into napari, or ``None``.
This is the primary "**reader plugin**" function. It accepts a path or
list of paths, and returns a list of data to be added to the ``Viewer``.
The function... | Return a function capable of loading ``path`` into napari, or ``None``.
This is the primary "**reader plugin**" function. It accepts a path or
list of paths, and returns a list of data to be added to the ``Viewer``.
The function may return ``[(None, )]`` to indicate that the file was read
successfully... | napari_get_reader | python | napari/napari | src/napari/plugins/hook_specifications.py | https://github.com/napari/napari/blob/master/src/napari/plugins/hook_specifications.py | BSD-3-Clause |
def napari_get_writer(
path: str, layer_types: list[str]
) -> WriterFunction | None:
"""Return function capable of writing napari layer data to ``path``.
This function will be called whenever the user attempts to save multiple
layers (e.g. via ``File -> Save Layers``, or
:func:`~napari.plugins.io.s... | Return function capable of writing napari layer data to ``path``.
This function will be called whenever the user attempts to save multiple
layers (e.g. via ``File -> Save Layers``, or
:func:`~napari.plugins.io.save_layers`).
This function must execute **quickly**, and should return ``None`` if
``pa... | napari_get_writer | python | napari/napari | src/napari/plugins/hook_specifications.py | https://github.com/napari/napari/blob/master/src/napari/plugins/hook_specifications.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.