napari.types

Classes

ArrayBase

alias of numpy.ndarray

Path

PurePath subclass that can make system calls.

SampleDict

TracebackType

alias of traceback

TypedDict

A simple typed name space.

Functions

napari.types.ImageData(x)
napari.types.LabelsData(x)
napari.types.LayerDataTuple(x)
napari.types.NewType(name, tp)[source]

NewType creates simple unique types with almost zero runtime overhead. NewType(name, tp) is considered a subtype of tp by static type checkers. At runtime, NewType(name, tp) returns a dummy function that simply returns its argument. Usage:

UserId = NewType('UserId', int)

def name_by_id(user_id: UserId) -> str:
    ...

UserId('user')          # Fails type check

name_by_id(42)          # Fails type check
name_by_id(UserId(42))  # OK

num = UserId(5) + 1     # type: int
napari.types.PointsData(x)
napari.types.ShapesData(x)
napari.types.SurfaceData(x)
napari.types.TracksData(x)
napari.types.VectorsData(x)
napari.types.image_reader_to_layerdata_reader(func)[source]

Convert a PathLike -> ArrayLike function to a PathLike -> LayerData.

Parameters

func (Callable[[PathLike], ArrayLike]) – A function that accepts a string or list of strings, and returns an ArrayLike.

Returns

reader_function – A function that accepts a string or list of strings, and returns data as a list of LayerData: List[Tuple[ArrayLike]]

Return type

Callable[[PathLike], List[LayerData]]

napari.types.register_types_with_magicgui()[source]

Register napari types with magicgui.

Parameter Annotations -> Widgets:
napari.layers.Layer, will be rendered as a ComboBox.

if a parameter is annotated as a subclass Layer type, then the combobox options will be limited to that layer type.

napari.Viewer, will be rendered as a ComboBox, with the current viewer

as the only choice.

Return Annotations -> Widgets:
napari.layers.Layer will add a new layer to the Viewer.

if a return is annotated as a subclass of Layer, then the corresponding layer type will be added. As of 0.4.3, the user must return an actual layer instance see add_layer_to_viewer for detail

napari.types.<layer_type>Data will add a new layer to the Viewer.

using a bare data array (e.g. numpy array) as a return value.

napari.types.LayerDataTuple will add a new layer to the Viewer.

and expects the user to return a single layer data tuple

List[napari.types.LayerDataTuple] will add multiple new layer to the

Viewer. And expects the user to return a list of layer data tuples.

napari.types.wraps(wrapped, assigned=('__module__', '__name__', '__qualname__', '__doc__', '__annotations__'), updated=('__dict__'))[source]

Decorator factory to apply update_wrapper() to a wrapper function

Returns a decorator that invokes update_wrapper() with the decorated function as the wrapper argument and the arguments to wraps() as the remaining arguments. Default arguments are as for update_wrapper(). This is a convenience function to simplify applying partial() to update_wrapper().