From 34065070f6f8090b35851e474a5543d28bb172c8 Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Tue, 9 Jan 2024 17:32:27 +0100 Subject: [PATCH 01/15] add pseudo tests --- napari/_qt/_tests/test_qt_viewer.py | 5 ++++ napari/components/_tests/test_layers_list.py | 4 +++ napari/components/_tests/test_viewer_model.py | 25 +++++++++++++++++++ napari/layers/base/_tests/test_named_axes.py | 22 ++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 napari/layers/base/_tests/test_named_axes.py diff --git a/napari/_qt/_tests/test_qt_viewer.py b/napari/_qt/_tests/test_qt_viewer.py index 4f202125acc..1c7dc06f121 100644 --- a/napari/_qt/_tests/test_qt_viewer.py +++ b/napari/_qt/_tests/test_qt_viewer.py @@ -808,6 +808,11 @@ def test_axes_labels(make_napari_viewer): assert tuple(axes_visual.node.text.text) == ('2', '1', '0') +def test_axes_visual_corresponds_to_axes_labels(): + """If we create an axes overlay visual, the text should be corresponding to the axes_labels of the particular layer of + which the axes are visualized""" + + @pytest.fixture() def qt_viewer(qtbot): qt_viewer = QtViewer(ViewerModel()) diff --git a/napari/components/_tests/test_layers_list.py b/napari/components/_tests/test_layers_list.py index 3376e797091..df43ca6ac8b 100644 --- a/napari/components/_tests/test_layers_list.py +++ b/napari/components/_tests/test_layers_list.py @@ -555,3 +555,7 @@ def test_readd_layers(): with pytest.raises(ValueError): layers[:3] = layers[:] assert set(layers) == set(imgs) + + +def test_layerlist_axis_labels(): + "Test that layerlist.axis_labels correspond to the actual labels." diff --git a/napari/components/_tests/test_viewer_model.py b/napari/components/_tests/test_viewer_model.py index ef12a96d109..0150aec065f 100644 --- a/napari/components/_tests/test_viewer_model.py +++ b/napari/components/_tests/test_viewer_model.py @@ -972,3 +972,28 @@ def test_slice_order_with_mixed_dims(): assert image_2d._slice.image.view.shape == (4, 5) assert image_3d._slice.image.view.shape == (3, 5) assert image_4d._slice.image.view.shape == (2, 5) + + +def test_viewer_add_layer_with_axes_labels(): + """When adding a layer with axes labels the axes labels in the viewer model should be updated as should axes labels in + dims model. axes labels here should be the unification of axes labels of all layers in the model. + """ + + +def test_viewer_multiple_layer_axes_labels(): + """When adding multiple layers to the viewer with the same axes labels the axes labels attribute of the viewer model + should stay the same. When layers do not share axes labels, the axes labels in the viewer model should be expanded. + """ + + +def test_viewer_annotation_layer_axes_labels(): + """When adding a new layer to annotate (for example with shapes layer) an image layer, the axes labels of the parent + layer should be inherited.""" + + +def test_layer_select_updates_viewer_axes_labels(): + """In case we have more than 1 layer not sharing labels the visible axes labels should be updated when selecting a + different layer. This could require a property of displayed axis labels and hidden_axis labels for the viewer. Later + this kind of functionality would have to be moved to canvas where each canvas is for displaying a given set of axes + and if there is an axes not part of this set it would require a second canvas. For now those layers with hidden axes + labels could be set to not visible.""" diff --git a/napari/layers/base/_tests/test_named_axes.py b/napari/layers/base/_tests/test_named_axes.py new file mode 100644 index 00000000000..711e211d8b1 --- /dev/null +++ b/napari/layers/base/_tests/test_named_axes.py @@ -0,0 +1,22 @@ +# These tests would be for testing the layers itself +def test_get_layer_axes_labels(): + "For a given layer we should be able to retrieve axes labels." + + +def test_set_layer_axes_labels(): + "For a given layer we should be able to set the axes labels." + + +def test_default_axes_labels(): + """If no axes labels are given, default names should be assigned equal to the number of dimensions of a particular + layer.""" + # Note that for broadcasting the default names should be based on negative integers, so ..., -2, -1. + + +def test_ndim_match_length_axes_labels(): + """The number of dimensions must match the length of axes labels when creating a layer and should throw an error + if not the case""" + + +def test_slice_using_axes_labels(): + "We should be able to slice based on current axes labels and an interval." From ee606eaf1e595b0ed19b12c05c988227cdc7f9c4 Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Wed, 17 Jan 2024 23:28:54 +0100 Subject: [PATCH 02/15] written pseudotests --- napari/layers/base/_tests/test_named_axes.py | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/napari/layers/base/_tests/test_named_axes.py b/napari/layers/base/_tests/test_named_axes.py index 711e211d8b1..61ede02dd4a 100644 --- a/napari/layers/base/_tests/test_named_axes.py +++ b/napari/layers/base/_tests/test_named_axes.py @@ -1,10 +1,32 @@ +import numpy as np +import pytest + +from napari.layers import Image + + # These tests would be for testing the layers itself def test_get_layer_axes_labels(): "For a given layer we should be able to retrieve axes labels." + shape = (10, 15) + np.random.seed(0) + data = np.random.random(shape) + layer = Image(data, axes_labels=("y", "x")) + assert layer.axes_labels == ("y", "x") def test_set_layer_axes_labels(): "For a given layer we should be able to set the axes labels." + shape = (10, 15) + np.random.seed(0) + data = np.random.random(shape) + layer = Image(data, axes_label=("y", "x")) + with pytest.raises(ValueError): + layer.axes_labels = ("z", "y", "x") + + layer.axes_labels = ("z", "t") + assert layer.axes_labels == ("z", "t") + + # Note: should we give a warning if reversing axes labels for example y,x to x, y def test_default_axes_labels(): From d9456cdc343fceff7224f6c0281fedd8e69faa5e Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Wed, 17 Jan 2024 23:29:31 +0100 Subject: [PATCH 03/15] remove test --- napari/components/_tests/test_layers_list.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/napari/components/_tests/test_layers_list.py b/napari/components/_tests/test_layers_list.py index df43ca6ac8b..3376e797091 100644 --- a/napari/components/_tests/test_layers_list.py +++ b/napari/components/_tests/test_layers_list.py @@ -555,7 +555,3 @@ def test_readd_layers(): with pytest.raises(ValueError): layers[:3] = layers[:] assert set(layers) == set(imgs) - - -def test_layerlist_axis_labels(): - "Test that layerlist.axis_labels correspond to the actual labels." From dd3bb91b975071c0adf2001460fa63ed9618677f Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Wed, 17 Jan 2024 23:32:11 +0100 Subject: [PATCH 04/15] make tests reflect axes_labels not in viewermodel --- napari/components/_tests/test_viewer_model.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/napari/components/_tests/test_viewer_model.py b/napari/components/_tests/test_viewer_model.py index 0150aec065f..b19e9d1c3e4 100644 --- a/napari/components/_tests/test_viewer_model.py +++ b/napari/components/_tests/test_viewer_model.py @@ -975,25 +975,16 @@ def test_slice_order_with_mixed_dims(): def test_viewer_add_layer_with_axes_labels(): - """When adding a layer with axes labels the axes labels in the viewer model should be updated as should axes labels in - dims model. axes labels here should be the unification of axes labels of all layers in the model. - """ + "When we add a layer to the viewer model, the axis labels in the dims should be properly updated" def test_viewer_multiple_layer_axes_labels(): - """When adding multiple layers to the viewer with the same axes labels the axes labels attribute of the viewer model - should stay the same. When layers do not share axes labels, the axes labels in the viewer model should be expanded. + """When adding multiple layers to the viewer with the same axes labels the axes labels of the dims model should stay + the same. When layers do not share axes labels, the axes labels in the dims model should be updated. The attribute + not_displayed of the dims model should also be properly updated. """ def test_viewer_annotation_layer_axes_labels(): """When adding a new layer to annotate (for example with shapes layer) an image layer, the axes labels of the parent layer should be inherited.""" - - -def test_layer_select_updates_viewer_axes_labels(): - """In case we have more than 1 layer not sharing labels the visible axes labels should be updated when selecting a - different layer. This could require a property of displayed axis labels and hidden_axis labels for the viewer. Later - this kind of functionality would have to be moved to canvas where each canvas is for displaying a given set of axes - and if there is an axes not part of this set it would require a second canvas. For now those layers with hidden axes - labels could be set to not visible.""" From 0088f0761e3f6845f4c9cb91fd33f3f3fc3adcc5 Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Sat, 20 Jan 2024 19:52:26 +0100 Subject: [PATCH 05/15] add default_axes_labels test Co-authored-by: sesan_ajina olusesan.ajina@gmail.com --- napari/layers/base/_tests/test_named_axes.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/napari/layers/base/_tests/test_named_axes.py b/napari/layers/base/_tests/test_named_axes.py index 61ede02dd4a..84b0e2af5a1 100644 --- a/napari/layers/base/_tests/test_named_axes.py +++ b/napari/layers/base/_tests/test_named_axes.py @@ -33,6 +33,10 @@ def test_default_axes_labels(): """If no axes labels are given, default names should be assigned equal to the number of dimensions of a particular layer.""" # Note that for broadcasting the default names should be based on negative integers, so ..., -2, -1. + shape = (10, 15) + data = np.random.random(shape) + layer = Image(data) + assert layer.axes_labels == (-2, -1) def test_ndim_match_length_axes_labels(): From 9b6a8243aa8a9499aa4517c5840521494b4ce1e5 Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Sat, 27 Jan 2024 20:46:13 +0100 Subject: [PATCH 06/15] refactor script name --- napari/layers/_tests/{test_utils.py => _utils.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename napari/layers/_tests/{test_utils.py => _utils.py} (100%) diff --git a/napari/layers/_tests/test_utils.py b/napari/layers/_tests/_utils.py similarity index 100% rename from napari/layers/_tests/test_utils.py rename to napari/layers/_tests/_utils.py From 02e5c8c8efcbb204bf44cf8b18b696610fb33ce0 Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Sat, 27 Jan 2024 20:49:21 +0100 Subject: [PATCH 07/15] add pseudo tests --- napari/components/_tests/test_viewer_model.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/napari/components/_tests/test_viewer_model.py b/napari/components/_tests/test_viewer_model.py index b19e9d1c3e4..ddf4820d32e 100644 --- a/napari/components/_tests/test_viewer_model.py +++ b/napari/components/_tests/test_viewer_model.py @@ -976,6 +976,23 @@ def test_slice_order_with_mixed_dims(): def test_viewer_add_layer_with_axes_labels(): "When we add a layer to the viewer model, the axis labels in the dims should be properly updated" + viewer = ViewerModel(ndisplay=2) + assert viewer.dims.axes_labels == ('-2', '-1') + with pytest.raises(ValueError): + viewer.add_image(np.zeros((4, 5)), axes_labels=("z", "y", "x")) + viewer.add_image(np.zeros((4, 5)), axes_labels=("x", "y")) + assert viewer.dims.axes_labels == ("x", "y") + + # Ensure axes labels stay the same when image with same axes labels are added + viewer.add_image(np.zeros((4, 5)), axes_labels=("x", "y")) + assert viewer.dims.axes_labels == ("x", "y") + + # Ensure axes labels are updated when layer with different axes labels than currently present are added. + viewer.add_image(np.zeros((4, 5, 5)), axes_labels=("a", "b", "c")) + assert viewer.dims.axes_labels == ("a", "b", "c", "x", "y") + + assert viewer.dims.displayed == ("a", "b", "c") + assert viewer.dims.not_displayed == ("x", "y") def test_viewer_multiple_layer_axes_labels(): From 9eb080b978ef954fa4d8bbf3d023a626831c7d96 Mon Sep 17 00:00:00 2001 From: Olusesan Date: Wed, 7 Feb 2024 13:22:42 -0800 Subject: [PATCH 08/15] updated dim test function --- napari/layers/base/_tests/test_named_axes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/napari/layers/base/_tests/test_named_axes.py b/napari/layers/base/_tests/test_named_axes.py index 84b0e2af5a1..dcf5c2e5ef7 100644 --- a/napari/layers/base/_tests/test_named_axes.py +++ b/napari/layers/base/_tests/test_named_axes.py @@ -42,7 +42,14 @@ def test_default_axes_labels(): def test_ndim_match_length_axes_labels(): """The number of dimensions must match the length of axes labels when creating a layer and should throw an error if not the case""" +<<<<<<< Updated upstream:napari/layers/base/_tests/test_named_axes.py +======= + shape = (10, 15) + data = np.random.random(shape) + layer = Image(data, axes_labels=("y", "x")) + assert layer.dim == 2 +>>>>>>> Stashed changes:napari/layers/base/test_named_axes.py def test_slice_using_axes_labels(): "We should be able to slice based on current axes labels and an interval." From 6f0060423bc6cf518f4726d243f8b4408407af71 Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Sat, 24 Feb 2024 20:46:14 +0100 Subject: [PATCH 09/15] add axes to init of base, image, labels co-authored by: olusesan.ajina@gmail.com --- napari/layers/base/base.py | 1 + napari/layers/image/image.py | 3 +++ napari/layers/labels/labels.py | 2 ++ napari/layers/points/points.py | 1 + 4 files changed, 7 insertions(+) diff --git a/napari/layers/base/base.py b/napari/layers/base/base.py index 1ada9d97c35..f11e26d2297 100644 --- a/napari/layers/base/base.py +++ b/napari/layers/base/base.py @@ -295,6 +295,7 @@ def __init__( experimental_clipping_planes=None, mode='pan_zoom', projection_mode='none', + axes_labels: tuple[str] = () ) -> None: super().__init__() diff --git a/napari/layers/image/image.py b/napari/layers/image/image.py index 25b69f52a86..9571825a35b 100644 --- a/napari/layers/image/image.py +++ b/napari/layers/image/image.py @@ -236,6 +236,7 @@ def __init__( data, *, rgb=None, + axes_labels = (), colormap='gray', contrast_limits=None, gamma=1.0, @@ -273,6 +274,8 @@ def __init__( trans._('Image data must have at least 2 dimensions.') ) + self.axes_labels = tuple(i for i in range(-data.ndim, 0)) + # Determine if data is a multiscale self._data_raw = data if multiscale is None: diff --git a/napari/layers/labels/labels.py b/napari/layers/labels/labels.py index 36158e98c30..dfd7d078a39 100644 --- a/napari/layers/labels/labels.py +++ b/napari/layers/labels/labels.py @@ -301,6 +301,7 @@ def __init__( plane=None, experimental_clipping_planes=None, projection_mode='none', + axes_labels = (), ) -> None: if name is None and data is not None: name = magic_name(data) @@ -321,6 +322,7 @@ def __init__( self._cached_mapped_labels = np.zeros((0, 4), dtype=np.uint8) data = self._ensure_int_labels(data) + self.axes_labels = tuple(i for i in range(-data.ndim, 0)) super().__init__( data, diff --git a/napari/layers/points/points.py b/napari/layers/points/points.py index 37f3d65845c..855809b8e42 100644 --- a/napari/layers/points/points.py +++ b/napari/layers/points/points.py @@ -377,6 +377,7 @@ def __init__( antialiasing=1, shown=True, projection_mode='none', + axes_labels = (), ) -> None: if ndim is None and scale is not None: ndim = len(scale) From 4efa01478dc4c6afdf8467f71c53d6c57afe3900 Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Sat, 2 Mar 2024 20:28:20 +0100 Subject: [PATCH 10/15] add axis labels to base layer co-authored by: olusesan.ajina@gmail.com --- napari/layers/base/base.py | 40 +++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/napari/layers/base/base.py b/napari/layers/base/base.py index f11e26d2297..624211b5efa 100644 --- a/napari/layers/base/base.py +++ b/napari/layers/base/base.py @@ -7,6 +7,7 @@ import warnings from abc import ABC, abstractmethod from collections import defaultdict +from collections.abc import Iterable from contextlib import contextmanager from functools import cached_property from typing import ( @@ -16,6 +17,7 @@ Dict, List, Optional, + Sequence, Tuple, Type, Union, @@ -295,7 +297,7 @@ def __init__( experimental_clipping_planes=None, mode='pan_zoom', projection_mode='none', - axes_labels: tuple[str] = () + axis_labels: Sequence[str | int] | None = None, ) -> None: super().__init__() @@ -338,6 +340,8 @@ def __init__( self._ndim = ndim + self._axis_labels = self._validate_coerce_axis_labels(axis_labels) + self._slice_input = _SliceInput( ndisplay=2, world_slice=_ThickNDSlice.make_full(ndim=ndim), @@ -526,6 +530,40 @@ def _mode_setter_helper(self, mode_in: Union[Mode, str]) -> StringEnum: return mode + def _validate_coerce_axis_labels( + self, axis_labels: Sequence[str | int] | None + ) -> tuple[str]: + """Check proper input of axis labels and coerce it to a tuple of strings. + + Paramters + --------- + axis_labels : Sequence[str | int] | None + Axis labels of the layer + + Returns + ------- + tuple[str] + Validated axis labels coerced to a tuple of strings + """ + if axis_labels is None: + axis_labels = tuple(str(-i) for i in range(self._ndim, 0, -1)) + elif ( + isinstance(axis_labels, Iterable) + and len(axis_labels) == self._ndim + ): + axis_labels = tuple(str(i) for i in axis_labels) + + return axis_labels + + @property + def axis_labels(self) -> tuple[str]: + """The axis labels of the layer.""" + return self._axis_labels + + @axis_labels.setter + def axis_labels(self, axis_labels: Sequence[str | int] | None): + self._axis_labels = self._validate_coerce_axis_labels(axis_labels) + @property def mode(self) -> str: """str: Interactive mode From 31586285eb458873f1e18e441da9aeb008c0e1c8 Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Sat, 2 Mar 2024 20:34:14 +0100 Subject: [PATCH 11/15] add axis labels to iamge layer co-authored by: olusesan.ajina@gmail.com --- napari/layers/image/image.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/napari/layers/image/image.py b/napari/layers/image/image.py index 9571825a35b..809a1aee3b6 100644 --- a/napari/layers/image/image.py +++ b/napari/layers/image/image.py @@ -236,7 +236,7 @@ def __init__( data, *, rgb=None, - axes_labels = (), + axis_labels: Sequence[str | int] | None = None, colormap='gray', contrast_limits=None, gamma=1.0, @@ -274,8 +274,6 @@ def __init__( trans._('Image data must have at least 2 dimensions.') ) - self.axes_labels = tuple(i for i in range(-data.ndim, 0)) - # Determine if data is a multiscale self._data_raw = data if multiscale is None: @@ -317,6 +315,7 @@ def __init__( cache=cache, experimental_clipping_planes=experimental_clipping_planes, projection_mode=projection_mode, + axis_labels=axis_labels, ) self.events.add( From d69df88d65b165c8475aa6f10f601849eb5079bf Mon Sep 17 00:00:00 2001 From: Olusesan Date: Wed, 6 Mar 2024 06:58:37 -0800 Subject: [PATCH 12/15] test to see if number of dimension = number of axes label --- napari/layers/labels/labels.py | 7 +++---- napari/layers/points/points.py | 3 ++- napari/layers/shapes/shapes.py | 3 +++ napari/layers/surface/surface.py | 4 +++- napari/layers/tracks/tracks.py | 4 +++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/napari/layers/labels/labels.py b/napari/layers/labels/labels.py index dfd7d078a39..de7bd7f5303 100644 --- a/napari/layers/labels/labels.py +++ b/napari/layers/labels/labels.py @@ -7,6 +7,7 @@ Dict, List, Optional, + Sequence, Tuple, Union, cast, @@ -279,6 +280,7 @@ def __init__( self, data, *, + axis_labels: Sequence[str|int]|None=None, num_colors=49, features=None, properties=None, @@ -301,7 +303,6 @@ def __init__( plane=None, experimental_clipping_planes=None, projection_mode='none', - axes_labels = (), ) -> None: if name is None and data is not None: name = magic_name(data) @@ -321,12 +322,10 @@ def __init__( self._cached_labels = None self._cached_mapped_labels = np.zeros((0, 4), dtype=np.uint8) - data = self._ensure_int_labels(data) - self.axes_labels = tuple(i for i in range(-data.ndim, 0)) - super().__init__( data, rgb=False, + axis_labels=axis_labels, colormap=self._random_colormap, contrast_limits=[0.0, 2**23 - 1.0], interpolation2d='nearest', diff --git a/napari/layers/points/points.py b/napari/layers/points/points.py index 855809b8e42..626144bdd90 100644 --- a/napari/layers/points/points.py +++ b/napari/layers/points/points.py @@ -340,6 +340,7 @@ def __init__( self, data=None, *, + axis_labels: Sequence[str| int] | None=None ndim=None, features=None, feature_defaults=None, @@ -377,7 +378,6 @@ def __init__( antialiasing=1, shown=True, projection_mode='none', - axes_labels = (), ) -> None: if ndim is None and scale is not None: ndim = len(scale) @@ -411,6 +411,7 @@ def __init__( super().__init__( data, ndim, + axis_labels=axis_labels, name=name, metadata=metadata, scale=scale, diff --git a/napari/layers/shapes/shapes.py b/napari/layers/shapes/shapes.py index cf18ad5b219..c5e56c5b119 100644 --- a/napari/layers/shapes/shapes.py +++ b/napari/layers/shapes/shapes.py @@ -9,6 +9,7 @@ Dict, List, Optional, + Sequence, Set, Tuple, Union, @@ -416,6 +417,7 @@ class Shapes(Layer): def __init__( self, + axis_labels:Sequence [str|int]|None=None, data=None, *, ndim=None, @@ -467,6 +469,7 @@ def __init__( super().__init__( data, + axis_labels=axis_labels, ndim=ndim, name=name, metadata=metadata, diff --git a/napari/layers/surface/surface.py b/napari/layers/surface/surface.py index 5fd98b51b68..6dfc08ff8e5 100644 --- a/napari/layers/surface/surface.py +++ b/napari/layers/surface/surface.py @@ -1,6 +1,6 @@ import copy import warnings -from typing import Any, List, Optional, Tuple, Union +from typing import Any, List, Optional, Sequence, Tuple, Union import numpy as np @@ -183,6 +183,7 @@ class Surface(IntensityVisualizationMixin, Layer): def __init__( self, data, + axis_labels: Sequence[str|int]| None=None, *, colormap='gray', contrast_limits=None, @@ -211,6 +212,7 @@ def __init__( super().__init__( data, + axis_labels=axis_labels, ndim, name=name, metadata=metadata, diff --git a/napari/layers/tracks/tracks.py b/napari/layers/tracks/tracks.py index a1d878ea0ae..c015d3163d5 100644 --- a/napari/layers/tracks/tracks.py +++ b/napari/layers/tracks/tracks.py @@ -2,7 +2,7 @@ # from napari.utils.events import Event # from napari.utils.colormaps import AVAILABLE_COLORMAPS -from typing import Dict, List, Optional, Union +from typing import Dict, List, Optional, Sequence, Union from warnings import warn import numpy as np @@ -97,6 +97,7 @@ class Tracks(Layer): def __init__( self, data, + axis_labels: Sequence[str|int]| None=None, *, features=None, properties=None, @@ -131,6 +132,7 @@ def __init__( super().__init__( data, ndim, + axis_labels=axis_labels, name=name, metadata=metadata, scale=scale, From 6de45bd4a27a643df672f174ca6508439d9a1696 Mon Sep 17 00:00:00 2001 From: wmv_hpomen Date: Wed, 6 Mar 2024 23:08:32 +0100 Subject: [PATCH 13/15] small fix --- napari/layers/surface/surface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/napari/layers/surface/surface.py b/napari/layers/surface/surface.py index 6dfc08ff8e5..0945de5fa64 100644 --- a/napari/layers/surface/surface.py +++ b/napari/layers/surface/surface.py @@ -183,7 +183,7 @@ class Surface(IntensityVisualizationMixin, Layer): def __init__( self, data, - axis_labels: Sequence[str|int]| None=None, + axis_labels: Sequence[str | int] | None = None, *, colormap='gray', contrast_limits=None, @@ -213,7 +213,7 @@ def __init__( super().__init__( data, axis_labels=axis_labels, - ndim, + ndim=ndim, name=name, metadata=metadata, scale=scale, From fcd1ab819f9f1fb4cb81061c7091807fce0e43e1 Mon Sep 17 00:00:00 2001 From: Wouter-Michiel Vierdag Date: Sat, 23 Mar 2024 19:16:56 +0100 Subject: [PATCH 14/15] remove typehints to fix optional bug co-authored by: olusesan.ajina@gmail.com --- napari/layers/base/base.py | 2 +- napari/layers/image/image.py | 2 +- napari/layers/labels/labels.py | 3 +-- napari/layers/points/points.py | 2 +- napari/layers/shapes/shapes.py | 3 +-- napari/layers/surface/surface.py | 4 ++-- napari/layers/tracks/tracks.py | 4 ++-- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/napari/layers/base/base.py b/napari/layers/base/base.py index 624211b5efa..f1f17f7ff54 100644 --- a/napari/layers/base/base.py +++ b/napari/layers/base/base.py @@ -297,7 +297,7 @@ def __init__( experimental_clipping_planes=None, mode='pan_zoom', projection_mode='none', - axis_labels: Sequence[str | int] | None = None, + axis_labels=None, ) -> None: super().__init__() diff --git a/napari/layers/image/image.py b/napari/layers/image/image.py index 809a1aee3b6..0954e71ee35 100644 --- a/napari/layers/image/image.py +++ b/napari/layers/image/image.py @@ -236,7 +236,7 @@ def __init__( data, *, rgb=None, - axis_labels: Sequence[str | int] | None = None, + axis_labels=None, colormap='gray', contrast_limits=None, gamma=1.0, diff --git a/napari/layers/labels/labels.py b/napari/layers/labels/labels.py index de7bd7f5303..e10e43207ce 100644 --- a/napari/layers/labels/labels.py +++ b/napari/layers/labels/labels.py @@ -7,7 +7,6 @@ Dict, List, Optional, - Sequence, Tuple, Union, cast, @@ -280,7 +279,7 @@ def __init__( self, data, *, - axis_labels: Sequence[str|int]|None=None, + axis_labels=None, num_colors=49, features=None, properties=None, diff --git a/napari/layers/points/points.py b/napari/layers/points/points.py index 626144bdd90..b6df691a10c 100644 --- a/napari/layers/points/points.py +++ b/napari/layers/points/points.py @@ -340,7 +340,7 @@ def __init__( self, data=None, *, - axis_labels: Sequence[str| int] | None=None + axis_labels=None, ndim=None, features=None, feature_defaults=None, diff --git a/napari/layers/shapes/shapes.py b/napari/layers/shapes/shapes.py index c5e56c5b119..15bc4100978 100644 --- a/napari/layers/shapes/shapes.py +++ b/napari/layers/shapes/shapes.py @@ -9,7 +9,6 @@ Dict, List, Optional, - Sequence, Set, Tuple, Union, @@ -417,7 +416,7 @@ class Shapes(Layer): def __init__( self, - axis_labels:Sequence [str|int]|None=None, + axis_labels=None, data=None, *, ndim=None, diff --git a/napari/layers/surface/surface.py b/napari/layers/surface/surface.py index 0945de5fa64..5d954386893 100644 --- a/napari/layers/surface/surface.py +++ b/napari/layers/surface/surface.py @@ -1,6 +1,6 @@ import copy import warnings -from typing import Any, List, Optional, Sequence, Tuple, Union +from typing import Any, List, Optional, Tuple, Union import numpy as np @@ -183,7 +183,7 @@ class Surface(IntensityVisualizationMixin, Layer): def __init__( self, data, - axis_labels: Sequence[str | int] | None = None, + axis_labels=None, *, colormap='gray', contrast_limits=None, diff --git a/napari/layers/tracks/tracks.py b/napari/layers/tracks/tracks.py index c015d3163d5..69a42bee776 100644 --- a/napari/layers/tracks/tracks.py +++ b/napari/layers/tracks/tracks.py @@ -2,7 +2,7 @@ # from napari.utils.events import Event # from napari.utils.colormaps import AVAILABLE_COLORMAPS -from typing import Dict, List, Optional, Sequence, Union +from typing import Dict, List, Optional, Union from warnings import warn import numpy as np @@ -97,7 +97,7 @@ class Tracks(Layer): def __init__( self, data, - axis_labels: Sequence[str|int]| None=None, + axis_labels=None, *, features=None, properties=None, From bdd71afb36cbb451651904aaf3e0851f5f8611ee Mon Sep 17 00:00:00 2001 From: Wouter-Michiel Vierdag Date: Sat, 23 Mar 2024 19:48:18 +0100 Subject: [PATCH 15/15] check issue duplicate axes_labels co-authored by: olusesan.ajina@gmail.com --- napari/layers/base/_tests/test_named_axes.py | 5 +---- napari/layers/base/base.py | 6 ++++-- napari/layers/image/image.py | 4 ++-- napari/layers/labels/labels.py | 4 ++-- napari/layers/points/points.py | 4 ++-- napari/layers/shapes/shapes.py | 4 ++-- napari/layers/surface/surface.py | 4 ++-- napari/layers/tracks/tracks.py | 4 ++-- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/napari/layers/base/_tests/test_named_axes.py b/napari/layers/base/_tests/test_named_axes.py index dcf5c2e5ef7..91d0ad7d9a4 100644 --- a/napari/layers/base/_tests/test_named_axes.py +++ b/napari/layers/base/_tests/test_named_axes.py @@ -42,14 +42,11 @@ def test_default_axes_labels(): def test_ndim_match_length_axes_labels(): """The number of dimensions must match the length of axes labels when creating a layer and should throw an error if not the case""" -<<<<<<< Updated upstream:napari/layers/base/_tests/test_named_axes.py - -======= shape = (10, 15) data = np.random.random(shape) layer = Image(data, axes_labels=("y", "x")) assert layer.dim == 2 ->>>>>>> Stashed changes:napari/layers/base/test_named_axes.py + def test_slice_using_axes_labels(): "We should be able to slice based on current axes labels and an interval." diff --git a/napari/layers/base/base.py b/napari/layers/base/base.py index f1f17f7ff54..14e9b5d7f0c 100644 --- a/napari/layers/base/base.py +++ b/napari/layers/base/base.py @@ -297,7 +297,7 @@ def __init__( experimental_clipping_planes=None, mode='pan_zoom', projection_mode='none', - axis_labels=None, + layer_axis_labels=None, ) -> None: super().__init__() @@ -340,7 +340,9 @@ def __init__( self._ndim = ndim - self._axis_labels = self._validate_coerce_axis_labels(axis_labels) + self.layer_axis_labels = self._validate_coerce_axis_labels( + layer_axis_labels + ) self._slice_input = _SliceInput( ndisplay=2, diff --git a/napari/layers/image/image.py b/napari/layers/image/image.py index 0954e71ee35..515f45fb513 100644 --- a/napari/layers/image/image.py +++ b/napari/layers/image/image.py @@ -236,7 +236,7 @@ def __init__( data, *, rgb=None, - axis_labels=None, + layer_axis_labels=None, colormap='gray', contrast_limits=None, gamma=1.0, @@ -315,7 +315,7 @@ def __init__( cache=cache, experimental_clipping_planes=experimental_clipping_planes, projection_mode=projection_mode, - axis_labels=axis_labels, + layer_axis_labels=layer_axis_labels, ) self.events.add( diff --git a/napari/layers/labels/labels.py b/napari/layers/labels/labels.py index e10e43207ce..8e3dbb97651 100644 --- a/napari/layers/labels/labels.py +++ b/napari/layers/labels/labels.py @@ -279,7 +279,7 @@ def __init__( self, data, *, - axis_labels=None, + layer_axis_labels=None, num_colors=49, features=None, properties=None, @@ -324,7 +324,7 @@ def __init__( super().__init__( data, rgb=False, - axis_labels=axis_labels, + layer_axis_labels=layer_axis_labels, colormap=self._random_colormap, contrast_limits=[0.0, 2**23 - 1.0], interpolation2d='nearest', diff --git a/napari/layers/points/points.py b/napari/layers/points/points.py index b6df691a10c..707f6f7e873 100644 --- a/napari/layers/points/points.py +++ b/napari/layers/points/points.py @@ -340,7 +340,7 @@ def __init__( self, data=None, *, - axis_labels=None, + layer_axis_labels=None, ndim=None, features=None, feature_defaults=None, @@ -411,7 +411,7 @@ def __init__( super().__init__( data, ndim, - axis_labels=axis_labels, + layer_axis_labels=layer_axis_labels, name=name, metadata=metadata, scale=scale, diff --git a/napari/layers/shapes/shapes.py b/napari/layers/shapes/shapes.py index 15bc4100978..9be43238d63 100644 --- a/napari/layers/shapes/shapes.py +++ b/napari/layers/shapes/shapes.py @@ -416,7 +416,7 @@ class Shapes(Layer): def __init__( self, - axis_labels=None, + layer_axis_labels=None, data=None, *, ndim=None, @@ -468,7 +468,7 @@ def __init__( super().__init__( data, - axis_labels=axis_labels, + layer_axis_labels=layer_axis_labels, ndim=ndim, name=name, metadata=metadata, diff --git a/napari/layers/surface/surface.py b/napari/layers/surface/surface.py index 5d954386893..ebb682364d6 100644 --- a/napari/layers/surface/surface.py +++ b/napari/layers/surface/surface.py @@ -183,7 +183,7 @@ class Surface(IntensityVisualizationMixin, Layer): def __init__( self, data, - axis_labels=None, + layer_axis_labels=None, *, colormap='gray', contrast_limits=None, @@ -212,7 +212,7 @@ def __init__( super().__init__( data, - axis_labels=axis_labels, + layer_axis_labels=layer_axis_labels, ndim=ndim, name=name, metadata=metadata, diff --git a/napari/layers/tracks/tracks.py b/napari/layers/tracks/tracks.py index 69a42bee776..e9848857e03 100644 --- a/napari/layers/tracks/tracks.py +++ b/napari/layers/tracks/tracks.py @@ -97,7 +97,7 @@ class Tracks(Layer): def __init__( self, data, - axis_labels=None, + layer_axis_labels=None, *, features=None, properties=None, @@ -132,7 +132,7 @@ def __init__( super().__init__( data, ndim, - axis_labels=axis_labels, + layer_axis_labels=layer_axis_labels, name=name, metadata=metadata, scale=scale,