napari.components.ViewerModel¶
-
class
napari.components.
ViewerModel
(title='napari', ndisplay=2, order=(), axis_labels=())[source]¶ Bases:
napari.utils.key_bindings.KeymapProvider
,napari.utils.mouse_bindings.MousemapProvider
,napari.utils.events.evented_model.EventedModel
Viewer containing the rendered scene, layers, and controlling elements including dimension sliders, and control bars for color limits.
- Parameters
title (string) – The title of the viewer window.
ndisplay ({2, 3}) – Number of displayed dimensions.
order (tuple of int) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3.
axis_labels (list of str) – Dimension names.
-
window
¶ Parent window.
- Type
Window
-
dims
¶ Contains axes, indices, dimensions and sliders.
- Type
Dimensions
Methods
Attributes
-
add_image
(data=None, *, channel_axis=None, rgb=None, colormap=None, contrast_limits=None, gamma=1, interpolation='nearest', rendering='mip', iso_threshold=0.5, attenuation=0.05, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=1, blending=None, visible=True, multiscale=None)[source]¶ Add an image layer to the layer list.
- Parameters
data (array or list of array) – Image data. Can be N dimensional. If the last dimension has length 3 or 4 can be interpreted as RGB or RGBA if rgb is True. If a list and arrays are decreasing in shape then the data is treated as a multiscale image.
channel_axis (int, optional) – Axis to expand image along. If provided, each channel in the data will be added as an individual image layer. In channel_axis mode, all other parameters MAY be provided as lists, and the Nth value will be applied to the Nth channel in the data. If a single value is provided, it will be broadcast to all Layers.
rgb (bool or list) – Whether the image is rgb RGB or RGBA. If not specified by user and the last dimension of the data has length 3 or 4 it will be set as True. If False the image is interpreted as a luminance image. If a list then must be same length as the axis that is being expanded as channels.
colormap (str, napari.utils.Colormap, tuple, dict, list) – Colormaps to use for luminance images. If a string must be the name of a supported colormap from vispy or matplotlib. If a tuple the first value must be a string to assign as a name to a colormap and the second item must be a Colormap. If a dict the key must be a string to assign as a name to a colormap and the value must be a Colormap. If a list then must be same length as the axis that is being expanded as channels, and each colormap is applied to each new image layer.
contrast_limits (list (2,)) – Color limits to be used for determining the colormap bounds for luminance images. If not passed is calculated as the min and max of the image. If list of lists then must be same length as the axis that is being expanded and then each colormap is applied to each image.
gamma (list, float) – Gamma correction for determining colormap linearity. Defaults to 1. If a list then must be same length as the axis that is being expanded as channels.
interpolation (str or list) – Interpolation mode used by vispy. Must be one of our supported modes. If a list then must be same length as the axis that is being expanded as channels.
rendering (str or list) – Rendering mode used by vispy. Must be one of our supported modes. If a list then must be same length as the axis that is being expanded as channels.
iso_threshold (float or list) – Threshold for isosurface. If a list then must be same length as the axis that is being expanded as channels.
attenuation (float or list) – Attenuation rate for attenuated maximum intensity projection. If a list then must be same length as the axis that is being expanded as channels.
name (str or list of str) – Name of the layer. If a list then must be same length as the axis that is being expanded as channels.
metadata (dict or list of dict) – Layer metadata. If a list then must be a list of dicts with the same length as the axis that is being expanded as channels.
scale (tuple of float or list) – Scale factors for the layer. If a list then must be a list of tuples of float with the same length as the axis that is being expanded as channels.
translate (tuple of float or list) – Translation values for the layer. If a list then must be a list of tuples of float with the same length as the axis that is being expanded as channels.
rotate (float, 3-tuple of float, n-D array or list.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed. If a list then must have same length as the axis that is being expanded as channels.
shear (1-D array or list.) – A vector of shear values for an upper triangular n-D shear matrix. If a list then must have same length as the axis that is being expanded as channels.
affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a lenght N translation vector and a 1 or a napari AffineTransform object. If provided then translate, scale, rotate, and shear values are ignored.
opacity (float or list) – Opacity of the layer visual, between 0.0 and 1.0. If a list then must be same length as the axis that is being expanded as channels.
blending (str or list) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}. If a list then must be same length as the axis that is being expanded as channels.
visible (bool or list of bool) – Whether the layer visual is currently being displayed. If a list then must be same length as the axis that is being expanded as channels.
multiscale (bool) – Whether the data is a multiscale image or not. Multiscale data is represented by a list of array like image data. If not specified by the user and if the data is a list of arrays that decrease in shape then it will be taken to be multiscale. The first image in the list should be the largest.
- Returns
layer – The newly-created image layer or list of image layers.
- Return type
napari.layers.Image
or list
-
add_labels
(data, *, num_colors=50, properties=None, color=None, seed=0.5, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', visible=True, multiscale=None)¶ Add a Labels layer to the layer list.
- Parameters
data (array or list of array) – Labels data as an array or multiscale.
num_colors (int) – Number of unique colors to use in colormap.
properties (dict {str: array (N,)}, DataFrame) – Properties for each label. Each property should be an array of length N, where N is the number of labels, and the first property corresponds to background.
color (dict of int to str or array) – Custom label to color mapping. Values must be valid color names or RGBA arrays.
seed (float) – Seed for colormap random generator.
name (str) – Name of the layer.
metadata (dict) – Layer metadata.
scale (tuple of float) – Scale factors for the layer.
translate (tuple of float) – Translation values for the layer.
rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.
shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.
affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a lenght N translation vector and a 1 or a napari AffineTransform object. If provided then translate, scale, rotate, and shear values are ignored.
opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.
blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.
visible (bool) – Whether the layer visual is currently being displayed.
multiscale (bool) – Whether the data is a multiscale image or not. Multiscale data is represented by a list of array like image data. If not specified by the user and if the data is a list of arrays that decrease in shape then it will be taken to be multiscale. The first image in the list should be the largest.
-
data
¶ Integer valued label data. Can be N dimensional. Every pixel contains an integer ID corresponding to the region it belongs to. The label 0 is rendered as transparent.
- Type
array
-
multiscale
¶ Whether the data is a multiscale image or not. Multiscale data is represented by a list of array like image data. The first image in the list should be the largest.
- Type
-
properties
¶ Properties for each label. Each property should be an array of length N, where N is the number of labels, and the first property corresponds to background.
- Type
dict {str: array (N,)}, DataFrame
-
color
¶ Custom label to color mapping. Values must be valid color names or RGBA arrays.
- Type
dict of int to str or array
-
contour
¶ If greater than 0, displays contours of labels instead of shaded regions with a thickness equal to its value.
- Type
-
mode
¶ Interactive mode. The normal, default mode is PAN_ZOOM, which allows for normal interactivity with the canvas.
In PICK mode the cursor functions like a color picker, setting the clicked on label to be the current label. If the background is picked it will select the background label 0.
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 selected than any pixels will be changed to background and this tool functions like an eraser. The size and shape of the cursor can be adjusted in the properties widget.
In FILL mode the cursor functions like a fill bucket replacing pixels of the label clicked on with the current label. It can either replace all pixels of that label or just those that are contiguous with the clicked on pixel. If the background label 0 is selected than any pixels will be changed to background and this tool functions like an eraser.
In ERASE mode the cursor functions similarly to PAINT mode, but to paint with background label, which effectively removes the label.
- Type
-
Extended Summary
-
----------
-
_data_raw
¶ 2D labels data for the currently viewed slice.
- Type
array (N, M)
-
_selected_color
¶ RGBA tuple of the color of the selected label, or None if the background label 0 is selected.
- Type
4-tuple or None
- Returns
layer – The newly-created labels layer.
- Return type
-
add_layer
(layer)[source]¶ Add a layer to the viewer.
- Parameters
layer (
napari.layers.Layer
) – Layer to add.- Returns
layer – The layer that was added (same as input).
- Return type
napari.layers.Layer
or list
-
add_points
(data=None, *, ndim=None, properties=None, text=None, symbol='o', size=10, edge_width=1, edge_color='black', edge_color_cycle=None, edge_colormap='viridis', edge_contrast_limits=None, face_color='white', face_color_cycle=None, face_colormap='viridis', face_contrast_limits=None, n_dimensional=False, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=1, blending='translucent', visible=True)¶ Add a Points layer to the layer list.
- Parameters
data (array (N, D)) – Coordinates for N points in D dimensions.
ndim (int) – Number of dimensions for shapes. When data is not None, ndim must be D. An empty points layer can be instantiated with arbitrary ndim.
properties (dict {str: array (N,)}, DataFrame) – Properties for each point. Each property should be an array of length N, where N is the number of points.
text (str, dict) – Text to be displayed with the points. If text is set to a key in properties, the value of that property will be displayed. Multiple properties can be composed using f-string-like syntax (e.g., ‘{property_1}, {float_property:.2f}). A dictionary can be provided with keyword arguments to set the text values and display properties. See TextManager.__init__() for the valid keyword arguments. For example usage, see /napari/examples/add_points_with_text.py.
symbol (str) – Symbol to be used for the point markers. Must be one of the following: arrow, clobber, cross, diamond, disc, hbar, ring, square, star, tailed_arrow, triangle_down, triangle_up, vbar, x.
size (float, array) – Size of the point marker. If given as a scalar, all points are made the same size. If given as an array, size must be the same broadcastable to the same shape as the data.
edge_width (float) – Width of the symbol edge in pixels.
edge_color (str, array-like) – Color of the point marker border. Numeric color values should be RGB(A).
edge_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to edge_color if a categorical attribute is used color the vectors.
edge_colormap (str, napari.utils.Colormap) – Colormap to set edge_color if a continuous attribute is used to set face_color.
edge_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())
face_color (str, array-like) – Color of the point marker body. Numeric color values should be RGB(A).
face_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to face_color if a categorical attribute is used color the vectors.
face_colormap (str, napari.utils.Colormap) – Colormap to set face_color if a continuous attribute is used to set face_color.
face_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())
n_dimensional (bool) – If True, renders points not just in central plane but also in all n-dimensions according to specified point marker size.
name (str) – Name of the layer.
metadata (dict) – Layer metadata.
scale (tuple of float) – Scale factors for the layer.
translate (tuple of float) – Translation values for the layer.
rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.
shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.
affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a lenght N translation vector and a 1 or a napari AffineTransform object. If provided then translate, scale, rotate, and shear values are ignored.
opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.
blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.
visible (bool) – Whether the layer visual is currently being displayed.
-
data
¶ Coordinates for N points in D dimensions.
- Type
array (N, D)
-
properties
¶ Annotations for each point. Each property should be an array of length N, where N is the number of points.
- Type
dict {str: array (N,)}
-
text
¶ Text to be displayed with the points. If text is set to a key in properties, the value of that property will be displayed. Multiple properties can be composed using f-string-like syntax (e.g., ‘{property_1}, {float_property:.2f}). For example usage, see /napari/examples/add_points_with_text.py.
- Type
-
size
¶ Array of sizes for each point in each dimension. Must have the same shape as the layer data.
- Type
array (N, D)
-
edge_color
¶ Array of edge color RGBA values, one for each point.
- Type
Nx4 numpy array
-
edge_color_cycle
¶ Cycle of colors (provided as string name, RGB, or RGBA) to map to edge_color if a categorical attribute is used color the vectors.
- Type
np.ndarray, list
-
edge_colormap
¶ Colormap to set edge_color if a continuous attribute is used to set face_color.
- Type
-
edge_contrast_limits
¶ clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())
-
face_color
¶ Array of face color RGBA values, one for each point.
- Type
Nx4 numpy array
-
face_color_cycle
¶ Cycle of colors (provided as string name, RGB, or RGBA) to map to face_color if a categorical attribute is used color the vectors.
- Type
np.ndarray, list
-
face_colormap
¶ Colormap to set face_color if a continuous attribute is used to set face_color.
- Type
-
face_contrast_limits
¶ clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())
-
current_size
¶ Size of the marker for the next point to be added or the currently selected point.
- Type
-
current_edge_color
¶ Size of the marker edge for the next point to be added or the currently selected point.
- Type
-
current_face_color
¶ Size of the marker edge for the next point to be added or the currently selected point.
- Type
-
n_dimensional
¶ If True, renders points not just in central plane but also in all n-dimensions according to specified point marker size.
- Type
-
mode
¶ Interactive mode. The normal, default mode is PAN_ZOOM, which allows for normal interactivity with the canvas.
In ADD mode clicks of the cursor add points at the clicked location.
In SELECT mode the cursor can select points by clicking on them or by dragging a box around them. Once selected points can be moved, have their properties edited, or be deleted.
- Type
-
face_color_mode
¶ Face color setting mode.
DIRECT (default mode) allows each point to be set arbitrarily
CYCLE allows the color to be set via a color cycle over an attribute
COLORMAP allows color to be set via a color map over an attribute
- Type
-
edge_color_mode
¶ Edge color setting mode.
DIRECT (default mode) allows each point to be set arbitrarily
CYCLE allows the color to be set via a color cycle over an attribute
COLORMAP allows color to be set via a color map over an attribute
- Type
-
Extended Summary
-
----------
-
_property_choices
¶ Possible values for the properties in Points.properties. If properties is not provided, it will be {} (empty dictionary).
- Type
dict {str: array (N,)}
-
_view_data
¶ 2D coordinates of points in the currently viewed slice.
- Type
array (M, 2)
-
_view_size
¶ Size of the point markers in the currently viewed slice.
- Type
array (M, )
-
_indices_view
¶ Integer indices of the points in the currently viewed slice.
- Type
array (M, )
-
_selected_view
¶ Integer indices of selected points in the currently viewed slice within the _view_data array.
-
_selected_box
¶ Four corners of any box either around currently selected points or being created during a drag action. Starting in the top left and going clockwise.
- Type
array (4, 2) or None
-
_drag_start
¶ Coordinates of first cursor click during a drag action. Gets reset to None after dragging is done.
- Returns
layer – The newly-created points layer.
- Return type
-
add_shapes
(data=None, *, ndim=None, properties=None, text=None, shape_type='rectangle', edge_width=1, edge_color='black', edge_color_cycle=None, edge_colormap='viridis', edge_contrast_limits=None, face_color='white', face_color_cycle=None, face_colormap='viridis', face_contrast_limits=None, z_index=0, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', visible=True)¶ Add a Shapes layer to the layer list.
- Parameters
data (list or array) – List of shape data, where each element is an (N, D) array of the N vertices of a shape in D dimensions. Can be an 3-dimensional array if each shape has the same number of vertices.
ndim (int) – Number of dimensions for shapes. When data is not None, ndim must be D. An empty shapes layer can be instantiated with arbitrary ndim.
properties (dict {str: array (N,)}, DataFrame) – Properties for each shape. Each property should be an array of length N, where N is the number of shapes.
text (str, dict) – Text to be displayed with the shapes. If text is set to a key in properties, the value of that property will be displayed. Multiple properties can be composed using f-string-like syntax (e.g., ‘{property_1}, {float_property:.2f}). A dictionary can be provided with keyword arguments to set the text values and display properties. See TextManager.__init__() for the valid keyword arguments. For example usage, see /napari/examples/add_shapes_with_text.py.
shape_type (string or list) – String of shape shape_type, must be one of “{‘line’, ‘rectangle’, ‘ellipse’, ‘path’, ‘polygon’}”. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.
edge_width (float or list) – Thickness of lines and edges. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.
edge_color (str, array-like) – If string can be any color name recognized by vispy or hex value if starting with #. If array-like must be 1-dimensional array with 3 or 4 elements. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.
edge_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to edge_color if a categorical attribute is used color the vectors.
edge_colormap (str, napari.utils.Colormap) – Colormap to set edge_color if a continuous attribute is used to set face_color.
edge_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())
face_color (str, array-like) – If string can be any color name recognized by vispy or hex value if starting with #. If array-like must be 1-dimensional array with 3 or 4 elements. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.
face_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to face_color if a categorical attribute is used color the vectors.
face_colormap (str, napari.utils.Colormap) – Colormap to set face_color if a continuous attribute is used to set face_color.
face_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())
z_index (int or list) – Specifier of z order priority. Shapes with higher z order are displayed ontop of others. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.
name (str) – Name of the layer.
metadata (dict) – Layer metadata.
scale (tuple of float) – Scale factors for the layer.
translate (tuple of float) – Translation values for the layer.
rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.
shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.
affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a lenght N translation vector and a 1 or a napari AffineTransform object. If provided then translate, scale, rotate, and shear values are ignored.
opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.
blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.
visible (bool) – Whether the layer visual is currently being displayed.
-
data
¶ List of shape data, where each element is an (N, D) array of the N vertices of a shape in D dimensions.
- Type
(N, ) list of array
-
properties
¶ Properties for each shape. Each property should be an array of length N, where N is the number of shapes.
- Type
dict {str: array (N,)}, DataFrame
-
text
¶ Text to be displayed with the shapes. If text is set to a key in properties, the value of that property will be displayed. Multiple properties can be composed using f-string-like syntax (e.g., ‘{property_1}, {float_property:.2f}). For example usage, see /napari/examples/add_shapes_with_text.py.
-
shape_type
¶ Name of shape type for each shape.
- Type
(N, ) list of str
-
edge_width
¶ Edge width for each shape.
- Type
(N, ) list of float
-
z_index
¶ z-index for each shape.
- Type
(N, ) list of int
-
current_edge_width
¶ Thickness of lines and edges of the next shape to be added or the currently selected shape.
- Type
-
current_edge_color
¶ Color of the edge of the next shape to be added or the currently selected shape.
- Type
-
current_face_color
¶ Color of the face of the next shape to be added or the currently selected shape.
- Type
-
mode
¶ Interactive mode. The normal, default mode is PAN_ZOOM, which allows for normal interactivity with the canvas.
The SELECT mode allows for entire shapes to be selected, moved and resized.
The DIRECT mode allows for shapes to be selected and their individual vertices to be moved.
The VERTEX_INSERT and VERTEX_REMOVE modes allow for individual vertices either to be added to or removed from shapes that are already selected. Note that shapes cannot be selected in this mode.
The ADD_RECTANGLE, ADD_ELLIPSE, ADD_LINE, ADD_PATH, and ADD_POLYGON modes all allow for their corresponding shape type to be added.
- Type
Mode
-
Extended Summary
-
----------
-
_data_dict
¶ Dictionary containing all the shape data indexed by slice tuple
- Type
Dict of ShapeList
-
_data_view
¶ Object containing the currently viewed shape data.
- Type
ShapeList
-
_mode_history
¶ Interactive mode captured on press of <space>.
- Type
Mode
-
_selected_data_stored
¶ Set of selected previously displayed. Used to prevent rerendering the same highlighted shapes when no data has changed.
- Type
-
_selected_box
¶ None if no shapes are selected, otherwise a 10x2 array of vertices of the interaction box. The first 8 points are the corners and midpoints of the box. The 9th point is the center of the box, and the last point is the location of the rotation handle that can be used to rotate the box.
- Type
None | np.ndarray
-
_drag_start
¶ If a drag has been started and is in progress then a length 2 array of the initial coordinates of the drag. None otherwise.
- Type
None | np.ndarray
-
_drag_box
¶ If a drag box is being created to select shapes then this is a 2x2 array of the two extreme corners of the drag. None otherwise.
- Type
None | np.ndarray
-
_drag_box_stored
¶ If a drag box is being created to select shapes then this is a 2x2 array of the two extreme corners of the drag that have previously been rendered. None otherwise. Used to prevent rerendering the same drag box when no data has changed.
- Type
None | np.ndarray
-
_is_selecting
¶ Bool indicating if a drag box is currently being created in order to select shapes.
- Type
-
_fixed_vertex
¶ If a scaling or rotation is in progress then a length 2 array of the coordinates that are remaining fixed during the move. None otherwise.
- Type
None | np.ndarray
-
_fixed_index
¶ If a scaling or rotation is in progress then the index of the vertex of the boudning box that is remaining fixed during the move. None otherwise.
- Type
-
_update_properties
¶ Bool indicating if properties are to allowed to update the selected shapes when they are changed. Blocking this prevents circular loops when shapes are selected and the properties are changed based on that selection
- Type
-
_allow_thumnail_update
¶ Flag set to true to allow the thumbnail to be updated. Blocking the thumbnail can be advantageous where responsiveness is critical.
- Type
-
_rotation_handle_length
¶ Length of the rotation handle of the boudning box in Canvas coordinates.
- Type
-
_thumbnail_update_thresh
¶ If there are more than this number of shapes, the thumnail won’t update during interactive events
- Type
- Returns
layer – The newly-created shapes layer.
- Return type
-
add_surface
(data, *, colormap='gray', contrast_limits=None, gamma=1, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=1, blending='translucent', visible=True)¶ Add a Surface layer to the layer list.
- Parameters
data (3-tuple of array) – The first element of the tuple is an (N, D) array of vertices of mesh triangles. The second is an (M, 3) array of int of indices of the mesh triangles. The third element is the (K0, …, KL, N) array of values used to color vertices where the additional L dimensions are used to color the same mesh with different values.
colormap (str, napari.utils.Colormap, tuple, dict) – Colormap to use for luminance images. If a string must be the name of a supported colormap from vispy or matplotlib. If a tuple the first value must be a string to assign as a name to a colormap and the second item must be a Colormap. If a dict the key must be a string to assign as a name to a colormap and the value must be a Colormap.
contrast_limits (list (2,)) – Color limits to be used for determining the colormap bounds for luminance images. If not passed is calculated as the min and max of the image.
gamma (float) – Gamma correction for determining colormap linearity. Defaults to 1.
name (str) – Name of the layer.
metadata (dict) – Layer metadata.
scale (tuple of float) – Scale factors for the layer.
translate (tuple of float) – Translation values for the layer.
rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.
shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.
affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a lenght N translation vector and a 1 or a napari AffineTransform object. If provided then translate, scale, rotate, and shear values are ignored.
opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.
blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.
visible (bool) – Whether the layer visual is currently being displayed.
-
data
¶ The first element of the tuple is an (N, D) array of vertices of mesh triangles. The second is an (M, 3) array of int of indices of the mesh triangles. The third element is the (K0, …, KL, N) array of values used to color vertices where the additional L dimensions are used to color the same mesh with different values.
- Type
3-tuple of array
-
vertices
¶ Vertices of mesh triangles.
- Type
(N, D) array
-
faces
¶ Indices of mesh triangles.
- Type
(M, 3) array of int
-
vertex_values
¶ Values used to color vertices.
- Type
(K0, .., KL, N) array
-
colormap
¶ Colormap to use for luminance images. If a string must be the name of a supported colormap from vispy or matplotlib. If a tuple the first value must be a string to assign as a name to a colormap and the second item must be a Colormap. If a dict the key must be a string to assign as a name to a colormap and the value must be a Colormap.
- Type
-
contrast_limits
¶ Color limits to be used for determining the colormap bounds for luminance images. If not passed is calculated as the min and max of the image.
- Type
list (2,)
-
Extended Summary
-
----------
-
_data_view
¶ The coordinates of the vertices given the viewed dimensions.
- Type
(M, 2) or (M, 3) array
-
_view_faces
¶ The integer indices of the vertices that form the triangles in the currently viewed slice.
- Type
(P, 3) array
-
_colorbar
¶ Colorbar for current colormap.
- Type
array
- Returns
layer – The newly-created surface layer.
- Return type
-
add_tracks
(data, *, properties=None, graph=None, tail_width=2, tail_length=30, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=1, blending='additive', visible=True, colormap='turbo', color_by='track_id', colormaps_dict=None)¶ Add a Tracks layer to the layer list.
- Parameters
data (array (N, D+1)) – Coordinates for N points in D+1 dimensions. ID,T,(Z),Y,X. The first axis is the integer ID of the track. D is either 3 or 4 for planar or volumetric timeseries respectively.
properties (dict {str: array (N,)}, DataFrame) – Properties for each point. Each property should be an array of length N, where N is the number of points.
graph (dict {int: list}) – Graph representing associations between tracks. Dictionary defines the mapping between a track ID and the parents of the track. This can be one (the track has one parent, and the parent has >=1 child) in the case of track splitting, or more than one (the track has multiple parents, but only one child) in the case of track merging. See examples/tracks_3d_with_graph.py
color_by (str) – Track property (from property keys) by which to color vertices.
tail_width (float) – Width of the track tails in pixels.
tail_length (float) – Length of the track tails in units of time.
colormap (str) – Default colormap to use to set vertex colors. Specialized colormaps, relating to specified properties can be passed to the layer via colormaps_dict.
colormaps_dict (dict {str: napari.utils.Colormap}) – Optional dictionary mapping each property to a colormap for that property. This allows each property to be assigned a specific colormap, rather than having a global colormap for everything.
name (str) – Name of the layer.
metadata (dict) – Layer metadata.
scale (tuple of float) – Scale factors for the layer.
translate (tuple of float) – Translation values for the layer.
rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.
shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.
affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a lenght N translation vector and a 1 or a napari AffineTransform object. If provided then translate, scale, rotate, and shear values are ignored.
opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.
blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.
visible (bool) – Whether the layer visual is currently being displayed.
- Returns
layer – The newly-created tracks layer.
- Return type
-
add_vectors
(data, *, properties=None, edge_width=1, edge_color='red', edge_color_cycle=None, edge_colormap='viridis', edge_contrast_limits=None, length=1, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', visible=True)¶ Add a Vectors layer to the layer list.
- Parameters
data ((N, 2, D) or (N1, N2, .., ND, D) array) – An (N, 2, D) array is interpreted as “coordinate-like” data and a list of N vectors with start point and projections of the vector in D dimensions. An (N1, N2, …, ND, D) array is interpreted as “image-like” data where there is a length D vector of the projections at each pixel.
properties (dict {str: array (N,)}, DataFrame) – Properties for each vector. Each property should be an array of length N, where N is the number of vectors.
edge_width (float) – Width for all vectors in pixels.
length (float) – Multiplicative factor on projections for length of all vectors.
edge_color (str) – Color of all of the vectors.
edge_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to edge_color if a categorical attribute is used color the vectors.
edge_colormap (str, napari.utils.Colormap) – Colormap to set vector color if a continuous attribute is used to set edge_color.
edge_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())
name (str) – Name of the layer.
metadata (dict) – Layer metadata.
scale (tuple of float) – Scale factors for the layer.
translate (tuple of float) – Translation values for the layer.
rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.
shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.
affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a lenght N translation vector and a 1 or a napari AffineTransform object. If provided then translate, scale, rotate, and shear values are ignored.
opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.
blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.
visible (bool) – Whether the layer visual is currently being displayed.
-
data
¶ The start point and projections of N vectors in D dimensions.
- Type
(N, 2, D) array
-
properties
¶ Properties for each vector. Each property should be an array of length N, where N is the number of vectors.
- Type
dict {str: array (N,)}, DataFrame
-
edge_color_cycle
¶ Cycle of colors (provided as string name, RGB, or RGBA) to map to edge_color if a categorical attribute is used color the vectors.
- Type
np.ndarray, list
-
edge_colormap
¶ Colormap to set vector color if a continuous attribute is used to set edge_color.
- Type
-
edge_contrast_limits
¶ clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())
-
Extended Summary
-
----------
-
_view_data
¶ The start point and projections of N vectors in 2D for vectors whose start point is in the currently viewed slice.
- Type
(M, 2, 2) array
-
_view_face_color
¶ colors for the M in view vectors
- Type
(M, 4) np.ndarray
-
_view_indices
¶ indices for the M in view vectors
- Type
(1, M) array
-
_view_vertices
¶ the corner points for the M in view faces. Shape is (4M, 2) for 2D and (8M, 2) for 3D.
- Type
(4M, 2) or (8M, 2) np.ndarray
-
_view_faces
¶ indices of the _mesh_vertices that form the faces of the M in view vectors. Shape is (2M, 2) for 2D and (4M, 2) for 3D.
- Type
(2M, 3) or (4M, 3) np.ndarray
-
_property_choices
¶ Possible values for the properties in Vectors.properties. If properties is not provided, it will be {} (empty dictionary).
- Type
dict {str: array (N,)}
-
_mesh_vertices
¶ The four corner points for the mesh representation of each vector as as rectangle in the slice that it starts in.
- Type
(4N, 2) array
-
_mesh_triangles
¶ The integer indices of the _mesh_vertices that form the two triangles for the mesh representation of the vectors.
- Type
(2N, 3) array
-
_max_vectors_thumbnail
¶ The maximum number of vectors that will ever be used to render the thumbnail. If more vectors are present then they are randomly subsampled.
- Type
- Returns
layer – The newly-created vectors layer.
- Return type
-
asdict
()¶ Convert a model to a dictionary.
-
bind_key
(key, func=<object object>, *, overwrite=False)¶ Bind a key combination to a keymap.
- Parameters
keymap (dict of str: callable) – Keymap to modify.
key (str or ..) – Key combination.
...
acts as a wildcard if no key combinations can be matched in the keymap (this will overwrite all key combinations further down the lookup chain).func (callable, None, or ..) – Callable to bind to the key combination. If
None
is passed, unbind instead....
acts as a blocker, effectively unbinding the key combination for all keymaps further down the lookup chain.overwrite (bool, keyword-only, optional) – Whether to overwrite the key combination if it already exists.
- Returns
unbound – Callable unbound by this operation, if any.
- Return type
callable or None
Notes
Key combinations are represented in the form
[modifier-]key
, e.g.a
,Control-c
, orControl-Alt-Delete
. Valid modifiers are Control, Alt, Shift, and Meta.Letters will always be read as upper-case. Due to the native implementation of the key system, Shift pressed in certain key combinations may yield inconsistent or unexpected results. Therefore, it is not recommended to use Shift with non-letter keys. On OSX, Control is swapped with Meta such that pressing Command reads as Control.
Special keys include Shift, Control, Alt, Meta, Up, Down, Left, Right, PageUp, PageDown, Insert, Delete, Home, End, Escape, Backspace, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, Space, Enter, and Tab
Functions take in only one argument: the parent that the function was bound to.
By default, all functions are assumed to work on key presses only, but can be denoted to work on release too by separating the function into two statements with the yield keyword:
@viewer.bind_key('h') def hello_world(viewer): # on key press viewer.status = 'hello world!' yield # on key release viewer.status = 'goodbye world :('
To create a keymap that will block others,
bind_key(..., ...)`
.
-
classmethod
construct
(_fields_set=None, **values)¶ Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
- Return type
Model
-
copy
(*, include=None, exclude=None, update=None, deep=False)¶ Duplicate a model, optionally choose which fields to include, exclude and change.
- Parameters
include (
Union
[ForwardRef
,ForwardRef
]) – fields to include in new modelexclude (
Union
[ForwardRef
,ForwardRef
]) – fields to exclude from new model, as with values this takes precedence over includeupdate (DictStrAny) – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
deep (
bool
) – set to True to make a deep copy of the model
- Return type
Model
- Returns
new model instance
-
property
experimental
¶ Experimental commands for IPython console.
For example run “viewer.experimental.cmds.loader.help”.
-
open
(path, *, stack=False, plugin=None, layer_type=None, **kwargs)[source]¶ Open a path or list of paths with plugins, and add layers to viewer.
A list of paths will be handed one-by-one to the napari_get_reader hook if stack is False, otherwise the full list is passed to each plugin hook.
- Parameters
path (str or list of str) – A filepath, directory, or URL (or a list of any) to open.
stack (bool, optional) – If a list of strings is passed and
stack
isTrue
, then the entire list will be passed to plugins. It is then up to individual plugins to know how to handle a list of paths. Ifstack
isFalse
, then thepath
list is broken up and passed to plugin readers one by one. by default False.plugin (str, optional) – Name of a plugin to use. If provided, will force
path
to be read with the specifiedplugin
. If the requested plugin cannot readpath
, an exception will be raised.layer_type (str, optional) – If provided, will force data read from
path
to be passed to the correspondingadd_<layer_type>
method (along with any additional)kwargs
provided to this function. This may result in exceptions if the data returned from the path is not compatible with the layer_type.**kwargs – All other keyword arguments will be passed on to the respective
add_layer
method.
- Returns
layers – A list of any layers that were added to the viewer.
- Return type