napari#
Classes
Napari ndarray viewer. |
Functions
- napari.imshow(data, *, channel_axis=None, affine=None, axis_labels=None, attenuation=0.05, blending=None, cache=True, colormap=None, contrast_limits=None, custom_interpolation_kernel_2d=None, depiction='volume', experimental_clipping_planes=None, gamma=1.0, interpolation2d='nearest', interpolation3d='linear', iso_threshold=None, metadata=None, multiscale=None, name=None, opacity=1.0, plane=None, projection_mode='mean', rendering='mip', rgb=None, rotate=None, scale=None, shear=None, translate=None, units=None, visible=True, viewer=None, title='napari', ndisplay=2, order=(), show=True) tuple[Viewer, list[Image]][source]#
Load data into an Image layer and return the Viewer and Layer.
- Parameters:
data (array or list of array) – Image data. Can be N >= 2 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. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.
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, other parameters MAY be provided as lists. The Nth value of the list will be applied to the Nth channel in the data. If a single value is provided, it will be broadcast to all Layers. All parameters except data, rgb, and multiscale can be provided as list of values. If a list is provided, it must be the 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 length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.
attenuation (float or list of float) – Attenuation rate for attenuated maximum intensity projection.
blending (str or list of 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 {‘translucent’, ‘translucent_no_depth’, ‘additive’, ‘minimum’, ‘opaque’}.
cache (bool or list of bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays.
colormap (str, napari.utils.Colormap, tuple, dict, list or list of these types) – Colormaps to use for luminance images. If a string, it can be the name of a supported colormap from vispy or matplotlib or the name of a vispy color or a hexadecimal RGB color representation. 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,)) – Intensity value limits to be used for determining the minimum and maximum colormap bounds for luminance images. If not passed, they will be calculated as the min and max intensity value of the image.
custom_interpolation_kernel_2d (np.ndarray) – Convolution kernel used with the ‘custom’ interpolation mode in 2D rendering.
depiction (str or list of str) – 3D Depiction mode. Must be one of {‘volume’, ‘plane’}. The default value is ‘volume’.
experimental_clipping_planes (list of dicts, list of ClippingPlane, or ClippingPlaneList) – Each dict defines a clipping plane in 3D in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, and ‘enabled’}. Values on the negative side of the normal are discarded if the plane is enabled.
gamma (float or list of float) – Gamma correction for determining colormap linearity; defaults to 1.
interpolation2d (str or list of str) – Interpolation mode used by vispy for rendering 2d data. Must be one of our supported modes. (for list of supported modes see Interpolation enum) ‘custom’ is a special mode for 2D interpolation in which a regular grid of samples is taken from the texture around a position using ‘linear’ interpolation before being multiplied with a custom interpolation kernel (provided with ‘custom_interpolation_kernel_2d’).
interpolation3d (str or list of str) – Same as ‘interpolation2d’ but for 3D rendering.
iso_threshold (float or list of float) – Threshold for isosurface.
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. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.
opacity (float or list) – Opacity of the layer visual, between 0.0 and 1.0.
plane (dict or SlicingPlane) – Properties defining plane rendering in 3D. Properties are defined in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, ‘thickness’, and ‘enabled’}.
projection_mode (str) – How data outside the viewed dimensions, but inside the thick Dims slice will be projected onto the viewed dimensions. Must fit to cls._projectionclass
rendering (str or list of str) – 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.
rgb (bool, optional) – Whether the image is RGB or RGBA if rgb. If not specified by user, but 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.
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.
scale (tuple of float or list of tuple of float) – Scale factors for the layer.
shear (1-D array or list.) – A vector of shear values for an upper triangular n-D shear matrix.
translate (tuple of float or list of tuple of float) – Translation values for the layer.
visible (bool or list of bool) – Whether the layer visual is currently being displayed.
viewer (Viewer object, optional, by default None.)
title (string, optional) – The title of the viewer window. By default ‘napari’.
ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.
order (tuple of int, optional) – 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. By default None
axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers
show (bool, optional) – Whether to show the viewer after instantiation. By default True.
- Returns:
viewer (napari.Viewer) – The created or passed viewer.
layer(s) (napari.layers.Image or List[napari.layers.Image]) – The added layer(s). (May be more than one if the
channel_axiskeyword argument is given.
- napari.run(*, force=False, gui_exceptions=False, max_loop_level=1, _func_name='run')[source]#
Start the Qt Event Loop
- Parameters:
force (bool, optional) – Force the application event_loop to start, even if there are no top level widgets to show.
gui_exceptions (bool, optional) – Whether to show uncaught exceptions in the GUI. By default they will be shown in the console that launched the event loop.
max_loop_level (int, optional) – The maximum allowable “loop level” for the execution thread. Every time QApplication.exec_() is called, Qt enters the event loop, increments app.thread().loopLevel(), and waits until exit() is called. This function will prevent calling exec_() if the application already has at least
max_loop_levelevent loops running. By default, 1._func_name (str, optional) – name of calling function, by default ‘run’. This is here to provide functions a way to inject their name into the warning message.
- Raises:
RuntimeError – (To avoid confusion) if no widgets would be shown upon starting the event loop.
- napari.save_layers(path: str, layers: list[Layer], *, plugin: str | None = None, _writer: WriterContribution | None = None) list[str][source]#
Write list of layers or individual layer to a path using writer plugins.
If
pluginis not provided and only one layer is passed, then we directly callplugin_manager.hook.napari_write_<layer>()which will loop through implementations and stop when the first one returns a non-None result. The order in which implementations are called can be changed with the hookbring_to_frontmethod, for instance:plugin_manager.hook.napari_write_points.bring_to_frontIf
pluginis not provided and multiple layers are passed, then we callplugin_manager.hook.napari_get_writer()which loops through plugins to find the first one that knows how to handle the combination of layers and is able to write the file. If no plugins offernapari_get_writerfor that combination of layers then the builtinnapari_get_writerimplementation will create a folder and callnapari_write_<layer>for each layer using thelayer.namevariable to modify the path such that the layers are written to unique files in the folder.If
pluginis provided and a single layer is passed, then we call thenapari_write_<layer_type>for that plugin, and if it fails we error.If a
pluginis provided and multiple layers are passed, then we call we callnapari_get_writerfor that plugin, and if it doesn`t return a WriterFunction we error, otherwise we call it and if that fails if it we error.- Parameters:
path (str) – A filepath, directory, or URL to open.
layers (List[layers.Layer]) – Non-empty List of layers to be saved. If only a single layer is passed then we use the hook specification corresponding to its layer type,
napari_write_<layer_type>. If multiple layers are passed then we use thenapari_get_writerhook specification. Warns when the list of layers is empty.plugin (str, optional) – Name of the plugin to use for saving. If None then all plugins corresponding to appropriate hook specification will be looped through to find the first one that can save the data.
- Returns:
File paths of any files that were written.
- Return type: