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 transform_with_box(
layer: 'Layer', event: Event
) -> Generator[None, None, None]:
"""
Translate, rescale or rotate a layer by dragging a TransformBox handle.
"""
if len(event.dims_displayed) != 2:
return
# we work in data space so we're axis aligned which simplifies calculation
... |
Translate, rescale or rotate a layer by dragging a TransformBox handle.
| transform_with_box | python | napari/napari | src/napari/layers/base/_base_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/base/_base_mouse_bindings.py | BSD-3-Clause |
def _get_state(self) -> dict[str, Any]:
"""Get dictionary of layer state.
Returns
-------
state : dict of str to Any
Dictionary of layer state.
"""
state = self._get_base_state()
state.update(
{
'rgb': self.rgb,
... | Get dictionary of layer state.
Returns
-------
state : dict of str to Any
Dictionary of layer state.
| _get_state | python | napari/napari | src/napari/layers/image/image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/image.py | BSD-3-Clause |
def _update_thumbnail(self):
"""Update thumbnail with current image data and colormap."""
# don't bother updating thumbnail if we don't have any data
# this also avoids possible dtype mismatch issues below
# for example np.clip may raise an OverflowError (in numpy 2.0)
if self._s... | Update thumbnail with current image data and colormap. | _update_thumbnail | python | napari/napari | src/napari/layers/image/image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/image.py | BSD-3-Clause |
def _calc_data_range(
self, mode: Literal['data', 'slice'] = 'data'
) -> tuple[float, float]:
"""
Calculate the range of the data values in the currently viewed slice
or full data array
"""
if mode == 'data':
input_data = self.data[-1] if self.multiscale e... |
Calculate the range of the data values in the currently viewed slice
or full data array
| _calc_data_range | python | napari/napari | src/napari/layers/image/image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/image.py | BSD-3-Clause |
def move_plane_along_normal(
layer: Image, event: Event
) -> None | Generator[None, None, None]:
"""Move a layers slicing plane along its normal vector on click and drag."""
# early exit clauses
if (
'Shift' not in event.modifiers
or layer.visible is False
or layer.mouse_pan is F... | Move a layers slicing plane along its normal vector on click and drag. | move_plane_along_normal | python | napari/napari | src/napari/layers/image/_image_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_image_mouse_bindings.py | BSD-3-Clause |
def set_plane_position(layer: Image, event: Event) -> None:
"""Set plane position on double click."""
# early exit clauses
if (
layer.visible is False
or layer.mouse_pan is False
or len(event.dims_displayed) < 3
):
return
# Calculate intersection of click with plane ... | Set plane position on double click. | set_plane_position | python | napari/napari | src/napari/layers/image/_image_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_image_mouse_bindings.py | BSD-3-Clause |
def guess_rgb(shape: tuple[int, ...], min_side_len: int = 30) -> bool:
"""Guess if the passed shape comes from rgb data.
If last dim is 3 or 4 and other dims are larger (>30), assume the data is
rgb, including rgba.
Parameters
----------
shape : list of int
Shape of the data that shoul... | Guess if the passed shape comes from rgb data.
If last dim is 3 or 4 and other dims are larger (>30), assume the data is
rgb, including rgba.
Parameters
----------
shape : list of int
Shape of the data that should be checked.
Returns
-------
bool
If data is rgb or not.... | guess_rgb | python | napari/napari | src/napari/layers/image/_image_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_image_utils.py | BSD-3-Clause |
def guess_multiscale(
data: MultiScaleData | list | tuple,
) -> tuple[bool, LayerDataProtocol | Sequence[LayerDataProtocol]]:
"""Guess whether the passed data is multiscale, process it accordingly.
If shape of arrays along first axis is strictly decreasing, the data is
multiscale. If it is the same sha... | Guess whether the passed data is multiscale, process it accordingly.
If shape of arrays along first axis is strictly decreasing, the data is
multiscale. If it is the same shape everywhere, it is not. Various
ambiguous conditions in between will result in a ValueError being raised,
or in an "unwrapping"... | guess_multiscale | python | napari/napari | src/napari/layers/image/_image_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_image_utils.py | BSD-3-Clause |
def guess_labels(data: Any) -> Literal['labels', 'image']:
"""Guess if array contains labels data."""
if hasattr(data, 'dtype') and data.dtype in (
np.int32,
np.uint32,
np.int64,
np.uint64,
):
return 'labels'
return 'image' | Guess if array contains labels data. | guess_labels | python | napari/napari | src/napari/layers/image/_image_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_image_utils.py | BSD-3-Clause |
def project_slice(
data: npt.NDArray, axis: tuple[int, ...], mode: ImageProjectionMode
) -> npt.NDArray:
"""Project a thick slice along axis based on mode."""
func: Callable
if mode == ImageProjectionMode.SUM:
func = np.sum
elif mode == ImageProjectionMode.MEAN:
func = np.mean
el... | Project a thick slice along axis based on mode. | project_slice | python | napari/napari | src/napari/layers/image/_image_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_image_utils.py | BSD-3-Clause |
def from_raw(
cls, *, raw: np.ndarray, converter: Callable[[np.ndarray], np.ndarray]
) -> '_ImageView':
"""Makes an image view from the raw image and a conversion function."""
view = converter(raw)
return cls(raw=raw, view=view) | Makes an image view from the raw image and a conversion function. | from_raw | python | napari/napari | src/napari/layers/image/_slice.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_slice.py | BSD-3-Clause |
def make_empty(
cls,
*,
slice_input: _SliceInput,
rgb: bool,
request_id: int | None = None,
dtype: 'DTypeLike' = np.uint8,
) -> '_ImageSliceResponse':
"""Returns an empty image slice response.
An empty slice indicates that there is no valid slice data... | Returns an empty image slice response.
An empty slice indicates that there is no valid slice data for an
image layer, but allows other functionality that relies on slice
data existing to continue to work without special casing.
Parameters
----------
slice_input : _Slice... | make_empty | python | napari/napari | src/napari/layers/image/_slice.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_slice.py | BSD-3-Clause |
def to_displayed(
self, converter: Callable[[np.ndarray], np.ndarray]
) -> '_ImageSliceResponse':
"""
Returns a raw slice converted for display,
which is needed for Labels and Image.
Parameters
----------
converter : Callable[[np.ndarray], np.ndarray]
... |
Returns a raw slice converted for display,
which is needed for Labels and Image.
Parameters
----------
converter : Callable[[np.ndarray], np.ndarray]
A function that converts the raw image to a vispy viewable image.
Returns
-------
_ImageSli... | to_displayed | python | napari/napari | src/napari/layers/image/_slice.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_slice.py | BSD-3-Clause |
def _thick_slice_at_level(self, level: int) -> _ThickNDSlice:
"""
Get the data_slice rescaled for a specific level.
"""
slice_arr = self.data_slice.as_array()
# downsample based on level
slice_arr /= self.downsample_factors[level]
slice_arr[0] = np.clip(slice_arr[... |
Get the data_slice rescaled for a specific level.
| _thick_slice_at_level | python | napari/napari | src/napari/layers/image/_slice.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_slice.py | BSD-3-Clause |
def _project_thick_slice(
self, data: ArrayLike, data_slice: _ThickNDSlice
) -> np.ndarray:
"""
Slice the given data with the given data slice and project the extra dims.
This is also responsible for materializing the data if it is backed
by a lazy store or compute graph (e.... |
Slice the given data with the given data slice and project the extra dims.
This is also responsible for materializing the data if it is backed
by a lazy store or compute graph (e.g. dask).
| _project_thick_slice | python | napari/napari | src/napari/layers/image/_slice.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_slice.py | BSD-3-Clause |
def _get_order(self) -> tuple[int, ...]:
"""Return the ordered displayed dimensions, but reduced to fit in the slice space."""
order = reorder_after_dim_reduction(self.slice_input.displayed)
if self.rgb:
# if rgb need to keep the final axis fixed during the
# transpose. T... | Return the ordered displayed dimensions, but reduced to fit in the slice space. | _get_order | python | napari/napari | src/napari/layers/image/_slice.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_slice.py | BSD-3-Clause |
def _slice_out_of_bounds(self) -> bool:
"""Check if the data slice is out of bounds for any dimension."""
data = self.data[0] if self.multiscale else self.data
for d in self.slice_input.not_displayed:
pt = self.data_slice.point[d]
max_idx = data.shape[d] - 1
i... | Check if the data slice is out of bounds for any dimension. | _slice_out_of_bounds | python | napari/napari | src/napari/layers/image/_slice.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_slice.py | BSD-3-Clause |
def test_non_visible_images():
"""Test loading non-visible images doesn't trigger compute."""
data_dask_2D = da.random.random((100_000, 100_000))
layer = Image(
data_dask_2D,
visible=False,
multiscale=False,
contrast_limits=[0, 1],
)
assert layer.data.shape == data_da... | Test loading non-visible images doesn't trigger compute. | test_non_visible_images | python | napari/napari | src/napari/layers/image/_tests/test_big_image_timing.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_big_image_timing.py | BSD-3-Clause |
def test_random_image():
"""Test instantiating Image layer with random 2D data."""
shape = (10, 15)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_array_equal(layer.extent.data... | Test instantiating Image layer with random 2D data. | test_random_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_negative_image():
"""Test instantiating Image layer with negative data."""
shape = (10, 15)
np.random.seed(0)
# Data between -1.0 and 1.0
data = 2 * np.random.random(shape) - 1.0
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.t... | Test instantiating Image layer with negative data. | test_negative_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_all_zeros_image():
"""Test instantiating Image layer with all zeros data."""
shape = (10, 15)
data = np.zeros(shape, dtype=float)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_array_equal(layer.extent.data[1], [s - 1 fo... | Test instantiating Image layer with all zeros data. | test_all_zeros_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_integer_image():
"""Test instantiating Image layer with integer data."""
shape = (10, 15)
np.random.seed(0)
data = np.round(10 * np.random.random(shape)).astype(int)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_arr... | Test instantiating Image layer with integer data. | test_integer_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_bool_image():
"""Test instantiating Image layer with bool data."""
shape = (10, 15)
data = np.zeros(shape, dtype=bool)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_array_equal(layer.extent.data[1], [s - 1 for s in shap... | Test instantiating Image layer with bool data. | test_bool_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_3D_image():
"""Test instantiating Image layer with random 3D data."""
shape = (10, 15, 6)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_array_equal(layer.extent.data[... | Test instantiating Image layer with random 3D data. | test_3D_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_3D_image_shape_1():
"""Test instantiating Image layer with random 3D data with shape 1 axis."""
shape = (1, 10, 15)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_arra... | Test instantiating Image layer with random 3D data with shape 1 axis. | test_3D_image_shape_1 | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_4D_image():
"""Test instantiating Image layer with random 4D data."""
shape = (10, 15, 6, 8)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_array_equal(layer.extent.da... | Test instantiating Image layer with random 4D data. | test_4D_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_5D_image_shape_1():
"""Test instantiating Image layer with random 5D data with shape 1 axis."""
shape = (4, 1, 2, 10, 15)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.asser... | Test instantiating Image layer with random 5D data with shape 1 axis. | test_5D_image_shape_1 | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_rgb_image():
"""Test instantiating Image layer with RGB data."""
shape = (40, 45, 3)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape) - 1
np.testing.assert_array_equal(
layer.exte... | Test instantiating Image layer with RGB data. | test_rgb_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_rgba_image():
"""Test instantiating Image layer with RGBA data."""
shape = (40, 45, 4)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape) - 1
np.testing.assert_array_equal(
layer.ex... | Test instantiating Image layer with RGBA data. | test_rgba_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_negative_rgba_image():
"""Test instantiating Image layer with negative RGBA data."""
shape = (40, 45, 4)
np.random.seed(0)
# Data between -1.0 and 1.0
data = 2 * np.random.random(shape) - 1
layer = Image(data)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shap... | Test instantiating Image layer with negative RGBA data. | test_negative_rgba_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_non_rgb_image():
"""Test forcing Image layer to be 3D and not rgb."""
shape = (10, 15, 3)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data, rgb=False)
assert np.array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_array_equal(layer.e... | Test forcing Image layer to be 3D and not rgb. | test_non_rgb_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_error_non_rgb_image(shape):
"""Test error on trying non rgb as rgb."""
# If rgb is set to be True in constructor but the last dim has a
# size > 4 or ndim not >= 3 then data cannot actually be rgb
data = np.empty(shape)
with pytest.raises(ValueError, match="'rgb' was set to True but"):
... | Test error on trying non rgb as rgb. | test_error_non_rgb_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_changing_image_dims():
"""Test changing Image data including dimensionality."""
shape_a = (10, 15)
shape_b = (20, 12, 6)
np.random.seed(0)
data_a = np.random.random(shape_a)
data_b = np.random.random(shape_b)
layer = Image(data_a)
# Prep indices for switch to 3D
layer.data ... | Test changing Image data including dimensionality. | test_changing_image_dims | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_value():
"""Test getting the value of the data at the current coordinates."""
np.random.seed(0)
data = np.random.random((10, 15))
layer = Image(data)
value = layer.get_value((0,) * 2)
assert value == data[0, 0] | Test getting the value of the data at the current coordinates. | test_value | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_message():
"""Test converting value and coords to message."""
np.random.seed(0)
data = np.random.random((10, 15))
layer = Image(data)
msg = layer.get_status((0,) * 2)
assert isinstance(msg, dict) | Test converting value and coords to message. | test_message | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_message_3d():
"""Test converting values and coords to message in 3D."""
np.random.seed(0)
data = np.random.random((10, 15, 15))
layer = Image(data)
layer._slice_dims(Dims(ndim=3, ndisplay=3))
msg = layer.get_status(
(0, 0, 0), view_direction=[1, 0, 0], dims_displayed=[0, 1, 2]
... | Test converting values and coords to message in 3D. | test_message_3d | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_thumbnail():
"""Test the image thumbnail for square data."""
np.random.seed(0)
data = np.random.random((30, 30))
layer = Image(data)
layer._update_thumbnail()
assert layer.thumbnail.shape == layer._thumbnail_shape | Test the image thumbnail for square data. | test_thumbnail | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_narrow_thumbnail():
"""Ensure that the thumbnail generation works for very narrow images.
See: https://github.com/napari/napari/issues/641 and
https://github.com/napari/napari/issues/489
"""
image = np.random.random((1, 2048))
layer = Image(image)
layer._update_thumbnail()
thum... | Ensure that the thumbnail generation works for very narrow images.
See: https://github.com/napari/napari/issues/641 and
https://github.com/napari/napari/issues/489
| test_narrow_thumbnail | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_image_state_update():
"""Test that an image can be updated from the output of its
_get_state method()
"""
image = Image(np.ones((32, 32, 32)))
state = image._get_state()
for k, v in state.items():
setattr(image, k, v) | Test that an image can be updated from the output of its
_get_state method()
| test_image_state_update | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_instantiate_with_plane_parameter_dict():
"""Test that an image layer can be instantiated with plane parameters
in a dictionary.
"""
plane_parameters = {
'position': (32, 32, 32),
'normal': (1, 1, 1),
'thickness': 22,
}
image = Image(np.ones((32, 32, 32)), plane=p... | Test that an image layer can be instantiated with plane parameters
in a dictionary.
| test_instantiate_with_plane_parameter_dict | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_instiantiate_with_plane():
"""Test that an image layer can be instantiated with plane parameters
in a Plane.
"""
plane = SlicingPlane(position=(32, 32, 32), normal=(1, 1, 1), thickness=22)
image = Image(np.ones((32, 32, 32)), plane=plane)
for k, v in plane.dict().items():
assert... | Test that an image layer can be instantiated with plane parameters
in a Plane.
| test_instiantiate_with_plane | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_tensorstore_image():
"""Test an image coming from a tensorstore array."""
ts = pytest.importorskip('tensorstore')
data = ts.array(
np.full(shape=(1024, 1024), fill_value=255, dtype=np.uint8)
)
layer = Image(data)
assert np.array_equal(layer.data, data) | Test an image coming from a tensorstore array. | test_tensorstore_image | python | napari/napari | src/napari/layers/image/_tests/test_image.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image.py | BSD-3-Clause |
def test_guess_multiscale_non_array_list():
"""Check that non-decreasing list input raises ValueError"""
data = [np.empty((10, 15, 6))] * 2
with pytest.raises(ValueError, match='decreasing size'):
_, _ = guess_multiscale(data) | Check that non-decreasing list input raises ValueError | test_guess_multiscale_non_array_list | python | napari/napari | src/napari/layers/image/_tests/test_image_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_image_utils.py | BSD-3-Clause |
def test_random_multiscale():
"""Test instantiating Image layer with random 2D multiscale data."""
shapes = [(40, 20), (20, 10), (10, 5)]
np.random.seed(0)
data = [np.random.random(s) for s in shapes]
layer = Image(data, multiscale=True)
assert layer.data == data
assert layer.multiscale is T... | Test instantiating Image layer with random 2D multiscale data. | test_random_multiscale | python | napari/napari | src/napari/layers/image/_tests/test_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_multiscale.py | BSD-3-Clause |
def test_blocking_multiscale():
"""Test instantiating Image layer blocking 2D multiscale data."""
shape = (40, 20)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data, multiscale=False)
np.testing.assert_array_equal(layer.data, data)
assert layer.multiscale is False
asser... | Test instantiating Image layer blocking 2D multiscale data. | test_blocking_multiscale | python | napari/napari | src/napari/layers/image/_tests/test_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_multiscale.py | BSD-3-Clause |
def test_multiscale_tuple():
"""Test instantiating Image layer multiscale tuple."""
shape = (40, 20)
np.random.seed(0)
img = np.random.random(shape)
if skimage.__version__ > '0.19':
pyramid_kwargs = {'channel_axis': None}
else:
pyramid_kwargs = {'multichannel': False}
data ... | Test instantiating Image layer multiscale tuple. | test_multiscale_tuple | python | napari/napari | src/napari/layers/image/_tests/test_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_multiscale.py | BSD-3-Clause |
def test_3D_multiscale():
"""Test instantiating Image layer with 3D data."""
shapes = [(8, 40, 20), (4, 20, 10), (2, 10, 5)]
np.random.seed(0)
data = [np.random.random(s) for s in shapes]
layer = Image(data, multiscale=True)
assert layer.data == data
assert layer.ndim == len(shapes[0])
n... | Test instantiating Image layer with 3D data. | test_3D_multiscale | python | napari/napari | src/napari/layers/image/_tests/test_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_multiscale.py | BSD-3-Clause |
def test_non_uniform_3D_multiscale():
"""Test instantiating Image layer non-uniform 3D data."""
shapes = [(8, 40, 20), (8, 20, 10), (8, 10, 5)]
np.random.seed(0)
data = [np.random.random(s) for s in shapes]
layer = Image(data, multiscale=True)
assert layer.data == data
assert layer.ndim == l... | Test instantiating Image layer non-uniform 3D data. | test_non_uniform_3D_multiscale | python | napari/napari | src/napari/layers/image/_tests/test_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_multiscale.py | BSD-3-Clause |
def test_3D_rgb_multiscale():
"""Test instantiating Image layer with 3D RGB data."""
shapes = [(8, 40, 32, 3), (4, 20, 16, 3), (2, 10, 8, 3)]
np.random.seed(0)
data = [np.random.random(s) for s in shapes]
layer = Image(data, multiscale=True)
assert layer.data == data
assert layer.ndim == len... | Test instantiating Image layer with 3D RGB data. | test_3D_rgb_multiscale | python | napari/napari | src/napari/layers/image/_tests/test_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_multiscale.py | BSD-3-Clause |
def test_corner_value():
"""Test getting the value of the data at the new position."""
shapes = [(40, 20), (20, 10), (10, 5)]
np.random.seed(0)
data = [np.random.random(s) for s in shapes]
layer = Image(data, multiscale=True)
value = layer.get_value((0,) * 2)
target_position = (39, 19)
t... | Test getting the value of the data at the new position. | test_corner_value | python | napari/napari | src/napari/layers/image/_tests/test_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_multiscale.py | BSD-3-Clause |
def test_multiscale_data_protocol():
"""Test multiscale data provides basic data protocol."""
shapes = [(2, 5, 20, 20), (2, 5, 10, 10), (2, 5, 5, 5)]
np.random.seed(0)
data = [np.random.random(s) for s in shapes]
layer = Image(data, multiscale=True)
assert '3 levels' in repr(layer.data)
asse... | Test multiscale data provides basic data protocol. | test_multiscale_data_protocol | python | napari/napari | src/napari/layers/image/_tests/test_multiscale.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_multiscale.py | BSD-3-Clause |
def test_switching_displayed_dimensions():
"""Test instantiating data then switching to displayed."""
shape = (10, 15, 20)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data)
np.testing.assert_array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.asser... | Test instantiating data then switching to displayed. | test_switching_displayed_dimensions | python | napari/napari | src/napari/layers/image/_tests/test_volume.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_volume.py | BSD-3-Clause |
def test_4D_volume():
"""Test instantiating multiple Image layers with random 4D data."""
shape = (10, 15, 6, 8)
np.random.seed(0)
data = np.random.random(shape)
layer = Image(data)
layer._slice_dims(Dims(ndim=4, ndisplay=3))
np.testing.assert_array_equal(layer.data, data)
assert layer.n... | Test instantiating multiple Image layers with random 4D data. | test_4D_volume | python | napari/napari | src/napari/layers/image/_tests/test_volume.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_volume.py | BSD-3-Clause |
def test_plane_drag_callback():
"""Plane drag callback should only be active when depicting as plane."""
np.random.seed(0)
data = np.random.random((10, 15, 20))
layer = Image(data, depiction='volume')
assert move_plane_along_normal not in layer.mouse_drag_callbacks
layer.depiction = 'plane'
... | Plane drag callback should only be active when depicting as plane. | test_plane_drag_callback | python | napari/napari | src/napari/layers/image/_tests/test_volume.py | https://github.com/napari/napari/blob/master/src/napari/layers/image/_tests/test_volume.py | BSD-3-Clause |
def _slice_dtype(self):
"""Calculate dtype of data view based on data dtype and current colormap"""
return self.colormap._data_to_texture(
np.zeros(0, dtype=normalize_dtype(self.dtype))
).dtype | Calculate dtype of data view based on data dtype and current colormap | _slice_dtype | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _is_default_colors(self, color):
"""Returns True if color contains only default colors, otherwise False.
Default colors are black for `None` and transparent for
`self.colormap.background_value`.
Parameters
----------
color : Dict
Dictionary of label valu... | Returns True if color contains only default colors, otherwise False.
Default colors are black for `None` and transparent for
`self.colormap.background_value`.
Parameters
----------
color : Dict
Dictionary of label value to color array
Returns
------... | _is_default_colors | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _ensure_int_labels(self, data):
"""Ensure data is integer by converting from bool if required, raising an error otherwise."""
looks_multiscale, data = guess_multiscale(data)
if not looks_multiscale:
data = [data]
int_data = []
for data_level in data:
#... | Ensure data is integer by converting from bool if required, raising an error otherwise. | _ensure_int_labels | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def swap_selected_and_background_labels(self):
"""Swap between the selected label and the background label."""
if self.selected_label != self.colormap.background_value:
self.selected_label = self.colormap.background_value
else:
self.selected_label = self._prev_selected_la... | Swap between the selected label and the background label. | swap_selected_and_background_labels | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _partial_labels_refresh(self):
"""Prepares and displays only an updated part of the labels."""
if self._updated_slice is None or not self.loaded:
return
dims_displayed = self._slice_input.displayed
raw_displayed = self._slice.image.raw
# Keep only the dimension... | Prepares and displays only an updated part of the labels. | _partial_labels_refresh | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _calculate_contour(
self, labels: np.ndarray, data_slice: tuple[slice, ...]
) -> np.ndarray | None:
"""Calculate the contour of a given label array within the specified data slice.
Parameters
----------
labels : np.ndarray
The label array.
data_slice ... | Calculate the contour of a given label array within the specified data slice.
Parameters
----------
labels : np.ndarray
The label array.
data_slice : Tuple[slice, ...]
The slice of the label array on which to calculate the contour.
Returns
------... | _calculate_contour | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _raw_to_displayed(
self, raw, data_slice: tuple[slice, ...] | None = None
) -> np.ndarray:
"""Determine displayed image from a saved raw image and a saved seed.
This function ensures that the 0 label gets mapped to the 0 displayed
pixel.
Parameters
----------
... | Determine displayed image from a saved raw image and a saved seed.
This function ensures that the 0 label gets mapped to the 0 displayed
pixel.
Parameters
----------
raw : array or int
Raw integer input image.
data_slice : numpy array slice
Slic... | _raw_to_displayed | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def get_color(self, label):
"""Return the color corresponding to a specific label."""
if label == self.colormap.background_value:
col = None
elif label is None or (
self.show_selected_label and label != self.selected_label
):
col = self.colormap.map(se... | Return the color corresponding to a specific label. | get_color | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _commit_staged_history(self):
"""Save staged history to undo history and clear it."""
if self._staged_history:
self._append_to_undo_history(self._staged_history)
self._staged_history = [] | Save staged history to undo history and clear it. | _commit_staged_history | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _save_history(self, value):
"""Save a history "atom" to the undo history.
A history "atom" is a single change operation to the array. A history
*item* is a collection of atoms that were applied together to make a
single change. For example, when dragging and painting, at each mouse
... | Save a history "atom" to the undo history.
A history "atom" is a single change operation to the array. A history
*item* is a collection of atoms that were applied together to make a
single change. For example, when dragging and painting, at each mouse
callback we create a history "atom"... | _save_history | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _load_history(self, before, after, undoing=True):
"""Load a history item and apply it to the array.
Parameters
----------
before : list of history items
The list of elements from which we want to load.
after : list of history items
The list of element... | Load a history item and apply it to the array.
Parameters
----------
before : list of history items
The list of elements from which we want to load.
after : list of history items
The list of element to which to append the loaded element. In the
case o... | _load_history | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def fill(self, coord, new_label, refresh=True):
"""Replace an existing label with a new label, either just at the
connected component if the `contiguous` flag is `True` or everywhere
if it is `False`, working in the number of dimensions specified by
the `n_edit_dimensions` flag.
... | Replace an existing label with a new label, either just at the
connected component if the `contiguous` flag is `True` or everywhere
if it is `False`, working in the number of dimensions specified by
the `n_edit_dimensions` flag.
Parameters
----------
coord : sequence of ... | fill | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _draw(self, new_label, last_cursor_coord, coordinates):
"""Paint into coordinates, accounting for mode and cursor movement.
The draw operation depends on the current mode of the layer.
Parameters
----------
new_label : int
value of label to paint
last_cu... | Paint into coordinates, accounting for mode and cursor movement.
The draw operation depends on the current mode of the layer.
Parameters
----------
new_label : int
value of label to paint
last_cursor_coord : sequence
last painted cursor coordinates
... | _draw | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def paint(self, coord, new_label, refresh=True):
"""Paint over existing labels with a new label, using the selected
brush shape and size, either only on the visible slice or in all
n dimensions.
Parameters
----------
coord : sequence of int
Position of mouse ... | Paint over existing labels with a new label, using the selected
brush shape and size, either only on the visible slice or in all
n dimensions.
Parameters
----------
coord : sequence of int
Position of mouse cursor in image coordinates.
new_label : int
... | paint | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def paint_polygon(self, points, new_label):
"""Paint a polygon over existing labels with a new label.
Parameters
----------
points : list of coordinates
List of coordinates of the vertices of a polygon.
new_label : int
Value of the new label to be filled ... | Paint a polygon over existing labels with a new label.
Parameters
----------
points : list of coordinates
List of coordinates of the vertices of a polygon.
new_label : int
Value of the new label to be filled in.
| paint_polygon | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _paint_indices(
self,
mask_indices,
new_label,
shape,
dims_to_paint,
slice_coord=None,
refresh=True,
):
"""Paint over existing labels with a new label, using the selected
mask indices, either only on the visible slice or in all n dimensions... | Paint over existing labels with a new label, using the selected
mask indices, either only on the visible slice or in all n dimensions.
Parameters
----------
mask_indices : numpy array of integer coordinates
Mask to paint represented by an array of its coordinates.
ne... | _paint_indices | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _get_pt_not_disp(self) -> dict[int, int]:
"""
Get indices of current visible slice.
"""
slice_input = self._slice.slice_input
point = np.round(
self.world_to_data(slice_input.world_slice.point)
).astype(int)
return {dim: point[dim] for dim in slice... |
Get indices of current visible slice.
| _get_pt_not_disp | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def data_setitem(self, indices, value, refresh=True):
"""Set `indices` in `data` to `value`, while writing to edit history.
Parameters
----------
indices : tuple of arrays of int
Indices in data to overwrite. Must be a tuple of arrays of length
equal to the numbe... | Set `indices` in `data` to `value`, while writing to edit history.
Parameters
----------
indices : tuple of arrays of int
Indices in data to overwrite. Must be a tuple of arrays of length
equal to the number of data dimensions. (Fancy indexing in [2]_).
value : i... | data_setitem | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def get_status(
self,
position: npt.ArrayLike | None = None,
*,
view_direction: npt.ArrayLike | None = None,
dims_displayed: list[int] | None = None,
world: bool = False,
value: Any | None = None,
) -> dict[str, str]:
"""Status message information of t... | 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 coordinates.
... | get_status | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _get_tooltip_text(
self,
position,
*,
view_direction: np.ndarray | None = None,
dims_displayed: list[int] | None = None,
world: bool = False,
):
"""
tooltip message of the data at a coordinate position.
Parameters
----------
... |
tooltip message 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 coordinates.
... | _get_tooltip_text | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def _coerce_indices_for_vectorization(array, indices: list) -> tuple:
"""Coerces indices so that they can be used for vectorized indexing in the given data array."""
if _is_array_type(array, 'xarray.DataArray'):
# Fix indexing for xarray if necessary
# See http://xarray.pydata.org/en/stable/inde... | Coerces indices so that they can be used for vectorized indexing in the given data array. | _coerce_indices_for_vectorization | python | napari/napari | src/napari/layers/labels/labels.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/labels.py | BSD-3-Clause |
def new_label(layer: Labels):
"""Set the currently selected label to the largest used label plus one."""
if isinstance(layer.data, np.ndarray):
new_selected_label = np.max(layer.data) + 1
if layer.selected_label == new_selected_label:
show_info(
trans._(
... | Set the currently selected label to the largest used label plus one. | new_label | python | napari/napari | src/napari/layers/labels/_labels_key_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_key_bindings.py | BSD-3-Clause |
def complete_polygon(layer: Labels):
"""Complete the drawing of the current polygon."""
# Because layer._overlays has type Overlay, mypy doesn't know that
# ._overlays["polygon"] has type LabelsPolygonOverlay, so type ignore for now
# TODO: Improve typing of layer._overlays to fix this
from napari.c... | Complete the drawing of the current polygon. | complete_polygon | python | napari/napari | src/napari/layers/labels/_labels_key_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_key_bindings.py | BSD-3-Clause |
def draw(layer, event):
"""Draw with the currently selected label to a coordinate.
This method have different behavior when draw is called
with different labeling layer mode.
In PAINT mode the cursor functions like a paint brush changing any
pixels it brushes over to the current label. If the back... | Draw with the currently selected label to a coordinate.
This method have different behavior when draw is called
with different labeling layer mode.
In PAINT mode the cursor functions like a paint brush changing any
pixels it brushes over to the current label. If the background label
`0` is selecte... | draw | python | napari/napari | src/napari/layers/labels/_labels_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_mouse_bindings.py | BSD-3-Clause |
def pick(layer, event):
"""Change the selected label to the same as the region clicked."""
# on press
layer.selected_label = (
layer.get_value(
event.position,
view_direction=event.view_direction,
dims_displayed=event.dims_displayed,
world=True,
... | Change the selected label to the same as the region clicked. | pick | python | napari/napari | src/napari/layers/labels/_labels_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_mouse_bindings.py | BSD-3-Clause |
def interpolate_coordinates(old_coord, new_coord, brush_size):
"""Interpolates coordinates depending on brush size.
Useful for ensuring painting is continuous in labels layer.
Parameters
----------
old_coord : np.ndarray, 1x2
Last position of cursor.
new_coord : np.ndarray, 1x2
... | Interpolates coordinates depending on brush size.
Useful for ensuring painting is continuous in labels layer.
Parameters
----------
old_coord : np.ndarray, 1x2
Last position of cursor.
new_coord : np.ndarray, 1x2
Current position of cursor.
brush_size : float
Size of br... | interpolate_coordinates | python | napari/napari | src/napari/layers/labels/_labels_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_utils.py | BSD-3-Clause |
def sphere_indices(radius, scale):
"""Generate centered indices within circle or n-dim ellipsoid.
Parameters
----------
radius : float
Radius of circle/sphere
scale : tuple of float
The scaling to apply to the sphere along each axis
Returns
-------
mask_indices : array
... | Generate centered indices within circle or n-dim ellipsoid.
Parameters
----------
radius : float
Radius of circle/sphere
scale : tuple of float
The scaling to apply to the sphere along each axis
Returns
-------
mask_indices : array
Centered indices within circle/sph... | sphere_indices | python | napari/napari | src/napari/layers/labels/_labels_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_utils.py | BSD-3-Clause |
def indices_in_shape(idxs, shape):
"""Return idxs after filtering out indices that are not in given shape.
Parameters
----------
idxs : tuple of array of int, or 2D array of int
The input coordinates. These should be in one of two formats:
- a tuple of 1D arrays, as for NumPy fancy ind... | Return idxs after filtering out indices that are not in given shape.
Parameters
----------
idxs : tuple of array of int, or 2D array of int
The input coordinates. These should be in one of two formats:
- a tuple of 1D arrays, as for NumPy fancy indexing, or
- a 2D array of shape (n... | indices_in_shape | python | napari/napari | src/napari/layers/labels/_labels_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_utils.py | BSD-3-Clause |
def get_dtype(layer):
"""Returns dtype of layer data
Parameters
----------
layer : Labels
Labels layer (may be multiscale)
Returns
-------
dtype
dtype of Layer data
"""
layer_data = layer.data
if not isinstance(layer_data, list):
layer_data = [layer_data... | Returns dtype of layer data
Parameters
----------
layer : Labels
Labels layer (may be multiscale)
Returns
-------
dtype
dtype of Layer data
| get_dtype | python | napari/napari | src/napari/layers/labels/_labels_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_utils.py | BSD-3-Clause |
def first_nonzero_coordinate(data, start_point, end_point):
"""Coordinate of the first nonzero element between start and end points.
Parameters
----------
data : nD array, shape (N1, N2, ..., ND)
A data volume.
start_point : array, shape (D,)
The start coordinate to check.
end_p... | Coordinate of the first nonzero element between start and end points.
Parameters
----------
data : nD array, shape (N1, N2, ..., ND)
A data volume.
start_point : array, shape (D,)
The start coordinate to check.
end_point : array, shape (D,)
The end coordinate to check.
... | first_nonzero_coordinate | python | napari/napari | src/napari/layers/labels/_labels_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_utils.py | BSD-3-Clause |
def mouse_event_to_labels_coordinate(layer, event):
"""Return the data coordinate of a Labels layer mouse event in 2D or 3D.
In 2D, this is just the event's position transformed by the layer's
world_to_data transform.
In 3D, a ray is cast in data coordinates, and the coordinate of the first
nonzer... | Return the data coordinate of a Labels layer mouse event in 2D or 3D.
In 2D, this is just the event's position transformed by the layer's
world_to_data transform.
In 3D, a ray is cast in data coordinates, and the coordinate of the first
nonzero value along that ray is returned. If the ray only contain... | mouse_event_to_labels_coordinate | python | napari/napari | src/napari/layers/labels/_labels_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_utils.py | BSD-3-Clause |
def get_contours(labels: np.ndarray, thickness: int, background_label: int):
"""Computes the contours of a 2D label image.
Parameters
----------
labels : array of integers
An input labels image.
thickness : int
It controls the thickness of the inner boundaries. The outside thickness... | Computes the contours of a 2D label image.
Parameters
----------
labels : array of integers
An input labels image.
thickness : int
It controls the thickness of the inner boundaries. The outside thickness is always 1.
The final thickness of the contours will be `thickness + 1`.
... | get_contours | python | napari/napari | src/napari/layers/labels/_labels_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_utils.py | BSD-3-Clause |
def expand_slice(
axes_slice: tuple[slice, ...], shape: tuple, offset: int
) -> tuple[slice, ...]:
"""Expands or shrinks a provided multi-axis slice by a given offset"""
return tuple(
slice(
max(0, min(max_size, s.start - offset)),
max(0, min(max_size, s.stop + offset)),
... | Expands or shrinks a provided multi-axis slice by a given offset | expand_slice | python | napari/napari | src/napari/layers/labels/_labels_utils.py | https://github.com/napari/napari/blob/master/src/napari/layers/labels/_labels_utils.py | BSD-3-Clause |
def test_random_labels():
"""Test instantiating Labels layer with random 2D data."""
shape = (10, 15)
np.random.seed(0)
data = np.random.randint(20, size=shape)
layer = Labels(data)
np.testing.assert_array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_array_eq... | Test instantiating Labels layer with random 2D data. | test_random_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_all_zeros_labels():
"""Test instantiating Labels layer with all zeros data."""
shape = (10, 15)
data = np.zeros(shape, dtype=int)
layer = Labels(data)
np.testing.assert_array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_array_equal(layer.extent.data[1], ... | Test instantiating Labels layer with all zeros data. | test_all_zeros_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_3D_labels():
"""Test instantiating Labels layer with random 3D data."""
shape = (6, 10, 15)
np.random.seed(0)
data = np.random.randint(20, size=shape)
layer = Labels(data)
np.testing.assert_array_equal(layer.data, data)
assert layer.ndim == len(shape)
np.testing.assert_array_equ... | Test instantiating Labels layer with random 3D data. | test_3D_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_float_labels():
"""Test instantiating labels layer with floats"""
np.random.seed(0)
data = np.random.uniform(0, 20, size=(10, 10))
with pytest.raises(TypeError):
Labels(data)
data0 = np.random.uniform(20, size=(20, 20))
data1 = data0[::2, ::2].astype(np.int32)
data = [data0... | Test instantiating labels layer with floats | test_float_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_bool_labels():
"""Test instantiating labels layer with bools"""
data = np.zeros((10, 10), dtype=bool)
layer = Labels(data)
assert np.issubdtype(layer.data.dtype, np.integer)
data0 = np.zeros((20, 20), dtype=bool)
data1 = data0[::2, ::2].astype(np.int32)
data = [data0, data1]
la... | Test instantiating labels layer with bools | test_bool_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_changing_labels_dims():
"""Test changing Labels data including dimensionality."""
shape_a = (10, 15)
shape_b = (20, 12, 6)
np.random.seed(0)
data_a = np.random.randint(20, size=shape_a)
data_b = np.random.randint(20, size=shape_b)
layer = Labels(data_a)
layer.data = data_b
... | Test changing Labels data including dimensionality. | test_changing_labels_dims | 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_default_properties_assignment():
"""Test that the default properties value can be assigned to properties
see https://github.com/napari/napari/issues/2477
"""
np.random.seed(0)
data = np.random.randint(20, size=(10, 15))
layer = Labels(data)
layer.properties = {}
assert layer.pr... | Test that the default properties value can be assigned to properties
see https://github.com/napari/napari/issues/2477
| test_default_properties_assignment | 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_multiscale_properties():
"""Test adding labels with multiscale properties."""
np.random.seed(0)
data0 = np.random.randint(20, size=(10, 15))
data1 = data0[::2, ::2]
data = [data0, data1]
layer = Labels(data)
assert isinstance(layer.properties, dict)
assert len(layer.properties)... | Test adding labels with multiscale properties. | test_multiscale_properties | 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_colormap_simple_data_types(colormap_like):
"""Test that setting colormap with list or dict of colors works."""
data = np.random.randint(20, size=(10, 15))
# test in constructor
_ = Labels(data, colormap=colormap_like)
# test assignment
layer = Labels(data)
layer.colormap = colormap_... | Test that setting colormap with list or dict of colors works. | test_colormap_simple_data_types | 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_n_edit_dimensions():
"""Test changing the number of editable dimensions."""
np.random.seed(0)
data = np.random.randint(20, size=(5, 10, 15))
layer = Labels(data)
layer.n_edit_dimensions = 2
layer.n_edit_dimensions = 3 | Test changing the number of editable dimensions. | test_n_edit_dimensions | 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_contour_large_new_labels():
"""Check that new labels larger than the lookup table work in contour mode.
References
----------
[1]: https://forum.image.sc/t/data-specific-reason-for-indexerror-in-raw-to-displayed/60808
[2]: https://github.com/napari/napari/pull/3697
"""
viewer = Vie... | Check that new labels larger than the lookup table work in contour mode.
References
----------
[1]: https://forum.image.sc/t/data-specific-reason-for-indexerror-in-raw-to-displayed/60808
[2]: https://github.com/napari/napari/pull/3697
| test_contour_large_new_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_contour_local_updates():
"""Checks if contours are rendered correctly with local updates"""
data = np.zeros((7, 7), dtype=np.int32)
layer = Labels(data)
layer.contour = 1
assert np.allclose(
layer._raw_to_displayed(layer._slice.image.raw),
np.zeros((7, 7), dtype=np.float32)... | Checks if contours are rendered correctly with local updates | test_contour_local_updates | 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_data_setitem_multi_dim():
"""
this test checks if data_setitem works when some of the indices are
outside currently rendered slice
"""
# create zarr zeros array in memory
data = zarr.zeros((10, 10, 10), chunks=(5, 5, 5), dtype=np.uint32)
labels = Labels(data)
labels.data_setitem... |
this test checks if data_setitem works when some of the indices are
outside currently rendered slice
| test_data_setitem_multi_dim | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.