magicclass.ext.vispy package

Subpackages

Submodules

magicclass.ext.vispy.camera module

class magicclass.ext.vispy.camera.Camera(viewbox: vispy.scene.widgets.viewbox.ViewBox)[source]

Bases: magicclass.fields._group.HasFields

The camera interface for vispy canvas.

fov

The field of view of the camera in degree.

Type

float

scale

The scale factor of the camera.

Type

float

center

The rotation center of the camera, in x, y, z order.

Type

tuple of float

angles

The Euler angles of the camera in degree, in x, y, z order.

Type

tuple of float

angles

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

center

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

fov

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

scale

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

class magicclass.ext.vispy.camera.EulerAngleEdit(value: tuple[float, float, float] = (0.0, 0.0, 0.0), layout: str = 'horizontal', nullable: bool = False, **kwargs)[source]

Bases: magicgui.widgets.Container

The TupleEdit for Euler angles.

property value: tuple[float, float, float]
class magicclass.ext.vispy.camera.VispyCamera(fov=45.0, distance=None, translate_speed=1.0, **kwargs)[source]

Bases: vispy.scene.cameras.arcball.ArcballCamera

The camera for the 3D view.

changed

Declares a signal emitter on a class.

This is class implements the [descriptor protocol](https://docs.python.org/3/howto/descriptor.html#descriptorhowto) and is designed to be used as a class attribute, with the supported signature types provided in the contructor:

```python from psygnal import Signal

class MyEmitter:

changed = Signal(int)

def receiver(arg: int):

print("new value:", arg)

emitter = MyEmitter() emitter.changed.connect(receiver) emitter.changed.emit(1) # prints 'new value: 1' ```

!!! note

in the example above, MyEmitter.changed is an instance of Signal, and emitter.changed is an instance of SignalInstance. See the documentation on [SignalInstance][psygnal.SignalInstance] for details on how to connect to and/or emit a signal on an instance of an object that has a Signal.

Parameters
  • *types (Union[Type[Any], Signature]) -- A sequence of individual types, or a single [inspect.Signature][] object.

  • description (str) -- Optional descriptive text for the signal. (not used internally).

  • name (Optional[str]) -- Optional name of the signal. If it is not specified then the name of the class attribute that is bound to the signal will be used. default None

  • check_nargs_on_connect (bool) -- Whether to check the number of positional args against signature when connecting a new callback. This can also be provided at connection time using .connect(..., check_nargs=True). By default, True.

  • check_types_on_connect (bool) -- Whether to check the callback parameter types against signature when connecting a new callback. This can also be provided at connection time using .connect(..., check_types=True). By default, False.

view_changed()[source]

Called when this camera is changes its view. Also called when its associated with a viewbox.

viewbox_key_event(event)[source]

The ViewBox key event handler

Parameters

event (instance of Event) -- The event.

magicclass.ext.vispy.camera.quaternion2euler(quaternion, degrees=False) tuple[float, float, float][source]

Converts VisPy quaternion into euler angle representation.

Euler angles have degeneracies, so the output might different from the Euler angles that might have been used to generate the input quaternion.

Euler angles representation also has a singularity near pitch = Pi/2 ; to avoid this, we set to Pi/2 pitch angles that are closer than the chosen epsilon from it.

Parameters
  • quaternion (vispy.util.Quaternion) -- Quaternion for conversion.

  • degrees (bool) -- If output is returned in degrees or radians.

Returns

angles -- Euler angles in (rx, ry, rz) order.

Return type

3-tuple

magicclass.ext.vispy.layer2d module

class magicclass.ext.vispy.layer2d.Curve(viewbox: ViewBox, x: ArrayLike, y: ArrayLike = None, face_color=None, edge_color=None, size: float = 7, name: str | None = None, lw: float = 1, ls: str = '-', symbol=None)[source]

Bases: magicclass.ext.vispy.layer2d.PlotDataLayer

class magicclass.ext.vispy.layer2d.Histogram(viewbox: ViewBox, data: np.ndarray, bins: int = 10, face_color=None, edge_color=None, name: str | None = None)[source]

Bases: magicclass.ext.vispy._base.LayerItem

property name
class magicclass.ext.vispy.layer2d.PlotDataLayer[source]

Bases: magicclass.ext.vispy._base.LayerItem

add(points: np.ndarray | Sequence)[source]

Add new points to the plot data item.

property color
property edge_color: numpy.ndarray

Edge color of the data.

property face_color: numpy.ndarray

Face color of the data.

property name: str
property ndata: int
remove(i: int | Sequence[int])[source]

Remove the i-th data.

property xdata: numpy.ndarray
property ydata: numpy.ndarray
class magicclass.ext.vispy.layer2d.Scatter(viewbox: ViewBox, x: ArrayLike, y: ArrayLike = None, face_color=None, edge_color=None, size: float = 7, name: str | None = None, symbol='o')[source]

Bases: magicclass.ext.vispy.layer2d.PlotDataLayer

magicclass.ext.vispy.layer3d module

class magicclass.ext.vispy.layer3d.Arrows3D(data: np.ndarray, viewbox: ViewBox, color: Color | None = None, width: float = 0.0, arrow_type: str = 'stealth', arrow_size: float = 1.0, blending: str = 'translucent', name: str | None = None)[source]

Bases: magicclass.ext.vispy._base.LayerItem, magicclass.fields._group.HasFields

arrow_size

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

arrow_type

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

blending

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

color

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

property data: numpy.ndarray
width

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

class magicclass.ext.vispy.layer3d.Curve3D(data, viewbox: ViewBox, color: Color = None, width: float = 1.0, blending: str = 'translucent', name: str | None = None)[source]

Bases: magicclass.ext.vispy._base.LayerItem, magicclass.fields._group.HasFields

blending

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

color

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

property data: numpy.ndarray
width

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

class magicclass.ext.vispy.layer3d.Image(data, viewbox: ViewBox, contrast_limits: tuple[float, float] | None = None, rendering: str = 'mip', iso_threshold: float | None = None, name: str = '', attenuation: float = 1.0, cmap: str = 'grays', gamma: str = 1.0, interpolation: str = 'linear')[source]

Bases: magicclass.ext.vispy._base.LayerItem, magicclass.fields._group.HasFields

INTERPOLATIONS = ['nearest', 'linear']
RENDERINGS = ['translucent', 'mip', 'minip', 'attenuated_mip', 'additive', 'iso', 'average']
attenuation

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

contrast_limits

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

property data: numpy.ndarray

Image data.

gamma

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

interpolation

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

iso_threshold

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

rendering

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

class magicclass.ext.vispy.layer3d.IsoSurface(data, viewbox: ViewBox, contrast_limits=None, iso_threshold=None, face_color=None, edge_color=None, shading='smooth', name: str | None = None)[source]

Bases: magicclass.ext.vispy.layer3d._SurfaceBase, magicclass.fields._group.HasFields

contrast_limits

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

property data: numpy.ndarray
edge_color

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

edge_width

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

face_color

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

iso_threshold

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

shading

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

class magicclass.ext.vispy.layer3d.Points3D(data, viewbox: ViewBox, face_color: Color | None = None, edge_color: Color | None = None, edge_width: float = 0.0, size: float = 1.0, blending: str = 'translucent', spherical: bool = True, name: str | None = None)[source]

Bases: magicclass.ext.vispy._base.LayerItem, magicclass.fields._group.HasFields

blending

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

property data: numpy.ndarray
edge_color

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

edge_width

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

face_color

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

size

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

spherical

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

class magicclass.ext.vispy.layer3d.Surface(data, viewbox: ViewBox, face_color=None, edge_color=None, shading='none', name: str | None = None)[source]

Bases: magicclass.ext.vispy.layer3d._SurfaceBase, magicclass.fields._group.HasFields

property data
edge_color

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

edge_width

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

face_color

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

shading

Field class for magicgui construction. Unlike MagicField, object of this class always returns value itself.

class magicclass.ext.vispy.layer3d.SurfaceData(verts: np.ndarray, faces: np.ndarray, values: np.ndarray)[source]

Bases: NamedTuple

Dataset that defines a surface data.

faces: numpy.ndarray

Alias for field number 1

values: numpy.ndarray

Alias for field number 2

verts: numpy.ndarray

Alias for field number 0

magicclass.ext.vispy.layerlist module

class magicclass.ext.vispy.layerlist.LayerList(data=())[source]

Bases: psygnal.containers._evented_list.EventedList[magicclass.ext.vispy._base.LayerItem]

events: ListEvents

magicclass.ext.vispy.plot_api module

magicclass.ext.vispy.plot_api.figure()[source]
magicclass.ext.vispy.plot_api.gca()[source]
magicclass.ext.vispy.plot_api.gcf()[source]
magicclass.ext.vispy.plot_api.imshow(image, cmap=None, vmin=None, vmax=None)[source]
magicclass.ext.vispy.plot_api.plot(x=None, y=None, face_color=None, edge_color=None, color=None, size: float = 7, name: str | None = None, lw: float = 1, ls: str = '-', symbol=None) VispyPlotCanvas[source]
magicclass.ext.vispy.plot_api.scatter(x=None, y=None, face_color=None, edge_color=None, color=None, size: float = 7, name: str | None = None, symbol=None) VispyPlotCanvas[source]
magicclass.ext.vispy.plot_api.show()[source]
magicclass.ext.vispy.plot_api.subplot(pos: int)[source]
magicclass.ext.vispy.plot_api.subplot(row: int, col: int, idx: int)

magicclass.ext.vispy.widgets2d module

class magicclass.ext.vispy.widgets2d.Has2DViewBox(viewbox: vispy.scene.widgets.viewbox.ViewBox)[source]

Bases: magicclass.ext.vispy._base.HasViewBox

add_curve(x=None, y=None, face_color=None, edge_color=None, color=None, size: float = 7, name: str | None = None, lw: float = 1, ls: str = '-', symbol=None)[source]

Add a line plot like plt.plot(x, y).

Parameters
  • x (array-like) --

    X data.

    y : array-like

    Y data.

    face_color: str or array-like, optional

    Face color of plot. Graphic object will be filled with this color.

    edge_color: str or array-like, optional

    Edge color of plot.

    color: str or array-like, optional

    Set face color and edge color at the same time.

  • size (float, default is 7) -- Symbol size.

  • name (str, optional) --

    Object name of the plot item.

    lw: float, default is 1.0

    Line width of edge.

    ls: str, default is "-"

    Line style of edge. One of "-", "--", ":" or "-.".

    symbol: str, optional

    Symbol style. Currently supports circle ("o"), cross ("+", "x"), star ("*"), square ("s", "D") triangle ("^", "<", "v", ">") and others that pyqtgraph supports.

Returns

A plot item of a curve.

Return type

Curve

add_hist(data, bins: int = 10, face_color=None, edge_color=None, color=None, name: str | None = None) Histogram[source]
add_scatter(x=None, y=None, face_color=None, edge_color=None, color=None, size: float = 7, name: str | None = None, symbol=None)[source]

Add a line plot like plt.plot(x, y).

Parameters
  • x (array-like) --

    X data.

    y : array-like

    Y data.

    face_color: str or array-like, optional

    Face color of plot. Graphic object will be filled with this color.

    edge_color: str or array-like, optional

    Edge color of plot.

    color: str or array-like, optional

    Set face color and edge color at the same time.

  • size (float, default is 7) -- Symbol size.

  • name (str, optional) --

    Object name of the plot item.

    symbol: str, optional

    Symbol style. Currently supports circle ("o"), cross ("+", "x"), star ("*"), square ("s", "D") triangle ("^", "<", "v", ">") and others that pyqtgraph supports.

Returns

A plot item of a curve.

Return type

Curve

property xrange: tuple[float, float]

Range of X dimension.

property yrange: tuple[float, float]

Range of Y dimension.

class magicclass.ext.vispy.widgets2d.ImageItem(viewbox: ViewBox | None = None, lock_contrast_limits: bool = False)[source]

Bases: magicclass.ext.vispy.widgets2d.Has2DViewBox

property cmap
property contrast_limits: tuple[float, float]

Contrast limits of the image.

property image
property title: str

The title string.

property xlabel: str

The x-label string.

property ylabel: str

The x-label string.

class magicclass.ext.vispy.widgets2d.PlotItem(viewbox: vispy.scene.widgets.viewbox.ViewBox)[source]

Bases: magicclass.ext.vispy.widgets2d.Has2DViewBox

property title: str

The title string.

property xlabel: str

The x-label string.

property ylabel: str

The x-label string.

class magicclass.ext.vispy.widgets2d.VispyImageCanvas(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget, magicclass.ext.vispy.widgets2d.ImageItem

A Vispy based 2-D plot canvas for images.

class magicclass.ext.vispy.widgets2d.VispyMultiImageCanvas(nrows: int = 1, ncols: int = 1)[source]

Bases: magicclass.ext.vispy._base.MultiPlot

A multiple Vispy based 2-D plot canvas for images.

class magicclass.ext.vispy.widgets2d.VispyMultiPlotCanvas(nrows: int = 1, ncols: int = 1)[source]

Bases: magicclass.ext.vispy._base.MultiPlot

A multiple Vispy based 2-D plot canvas.

class magicclass.ext.vispy.widgets2d.VispyPlotCanvas(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget, magicclass.ext.vispy.widgets2d.PlotItem

A Vispy based 2-D plot canvas for curve, histogram, bar plot etc.

magicclass.ext.vispy.widgets3d module

class magicclass.ext.vispy.widgets3d.Has3DViewBox(viewbox: vispy.scene.widgets.viewbox.ViewBox)[source]

Bases: magicclass.ext.vispy._base.HasViewBox

A Vispy canvas for 3-D object visualization.

Very similar to napari. This widget can be used independent of napari, or as a mini-viewer of napari.

add_arrows(data: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], arrow_type: str = 'stealth', arrow_size: float = 5.0, color: Union[Iterable[float], str] = 'white', width: float = 1.0, blending: str = 'translucent') magicclass.ext.vispy.layer3d.Arrows3D[source]

Add a (N, P, 3) array as a set of arrows.

P is the number of points in each arrow. If you want to draw simple arrows with lines, the shape of the input array will be (N, 2, 3) and data[:, 0] is the start points and data[:, 1] is the end points.

Parameters
  • data (ArrayLike) -- Arrow coordinates.

  • arrow_type (str, default is "stealth") -- Shape of the arrow.

  • arrow_size (float, default is 5.0) -- Size of the arrows.

  • color (str, default is "white") -- Color of the arrow and the bodies.

  • width (float, default is 1.0) -- Width of the arrow bodies.

  • blending (str, default is "translucent") -- Blending mode of the layer.

Returns

A new Arrow3D layer.

Return type

Arrow3D

add_curve(data: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], color: Union[Iterable[float], str] = 'white', width: float = 1, blending: str = 'translucent') magicclass.ext.vispy.layer3d.Curve3D[source]

Add a (N, 3) array as a curve.

Parameters
  • data (ArrayLike) -- Coordinates of the curve.

  • color (Color, default is "white") -- Color of the curve.

  • width (float, default is 1.) -- Width of the curve line.

  • blending (str, default is "translucent") -- Blending mode of the layer.

Returns

_description_

Return type

_type_

add_image(data: ArrayLike, *, contrast_limits: tuple[float, float] = None, rendering: str = 'mip', iso_threshold: float | None = None, attenuation: float = 1.0, cmap: str = 'grays', gamma: float = 1.0, interpolation: str = 'linear') layer3d.Image[source]

Add a 3D array as a volumic image.

Parameters
  • data (ArrayLike) -- Image data.

  • contrast_limits (tuple[float, float], optional) -- Contrast limits of the image.

  • rendering (str, optional) -- Rendering method.

  • iso_threshold (float, optional) -- Threshold of iso-surface rendering.

  • attenuation (float, optional) -- Attenuation of attenuated rendering method.

  • cmap (str, optional) -- Colormap of image.

  • gamma (float, optional) -- Gamma value of contrast.

  • interpolation (str, optional) -- Interpolation method.

Returns

A new Image layer.

Return type

Image

add_isosurface(data: ArrayLike, *, contrast_limits: tuple[float, float] | None = None, iso_threshold: float | None = None, face_color: Color | None = None, edge_color: Color | None = None, shading: str = 'smooth') layer3d.IsoSurface[source]

Add a 3D array as a iso-surface.

The difference between this method and the iso-surface rendering of add_image is that the layer created by this method can be a mesh.

Parameters
  • data (ArrayLike) -- Image data.

  • contrast_limits (tuple[float, float], optional) -- Contrast limits of the image.

  • iso_threshold (float, optional) -- Threshold of iso-surface.

  • face_color (Color, optional) -- Face color of the surface.

  • edge_color (Color, optional) -- Edge color of the surface.

  • shading (str, optional) -- Shading mode of the surface.

Returns

A new Isosurface layer.

Return type

Isosurface

add_layer(layer: magicclass.ext.vispy._base.LayerItem)[source]

Add a layer item to the canvas.

add_points(data: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], face_color: Union[Iterable[float], str] = 'white', edge_color: Union[Iterable[float], str] = 'white', edge_width: float = 0.0, size: float = 5.0, blending: str = 'translucent', spherical: bool = True) magicclass.ext.vispy.layer3d.Points3D[source]

Add a (N, 3) array as a point cloud.

Parameters
  • data (ArrayLike) -- Z, Y, X coordinates of the points.

  • face_color (Color, optional) -- Face color of the points.

  • edge_color (Color, optional) -- Edge color of the points.

  • edge_width (float, default is 0.0) -- Edge width of the points.

  • size (float, default is 1.0) -- Size of the points.

  • blending (str, default is "translucent") -- Blending mode of the layer.

  • spherical (bool, default is True) -- Whether the points are rendered as spherical objects.

Returns

A new Points3D layer.

Return type

Points3D

add_surface(data: tuple[ArrayLike, ArrayLike] | tuple[ArrayLike, ArrayLike, ArrayLike], *, face_color: Color | None = None, edge_color: Color | None = None, shading: str = 'smooth') layer3d.Surface[source]

Add vertices, faces and optional values as a surface.

Parameters
  • data (two or three arrays) -- Data that defines a surface.

  • face_color (Color | None, optional) -- Face color of the surface.

  • edge_color (Color | None, optional) -- Edge color of the surface.

  • shading (str, optional) -- Shading mode of the surface.

Returns

A new Surface layer.

Return type

Surface

property camera: magicclass.ext.vispy.camera.Camera

Return the native camera.

property layers

Return the layer list.

class magicclass.ext.vispy.widgets3d.Vispy3DCanvas[source]

Bases: magicclass.widgets.utils.FreeWidget, magicclass.ext.vispy.widgets3d.Has3DViewBox

A Vispy based 3-D canvas.

class magicclass.ext.vispy.widgets3d.VispyMulti3DCanvas(nrows: int = 1, ncols: int = 1)[source]

Bases: magicclass.ext.vispy._base.MultiPlot

A multiple Vispy based 3-D canvas.

Module contents

class magicclass.ext.vispy.Vispy3DCanvas[source]

Bases: magicclass.widgets.utils.FreeWidget, magicclass.ext.vispy.widgets3d.Has3DViewBox

A Vispy based 3-D canvas.

class magicclass.ext.vispy.VispyImageCanvas(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget, magicclass.ext.vispy.widgets2d.ImageItem

A Vispy based 2-D plot canvas for images.

class magicclass.ext.vispy.VispyMulti3DCanvas(nrows: int = 1, ncols: int = 1)[source]

Bases: magicclass.ext.vispy._base.MultiPlot

A multiple Vispy based 3-D canvas.

class magicclass.ext.vispy.VispyMultiImageCanvas(nrows: int = 1, ncols: int = 1)[source]

Bases: magicclass.ext.vispy._base.MultiPlot

A multiple Vispy based 2-D plot canvas for images.

class magicclass.ext.vispy.VispyMultiPlotCanvas(nrows: int = 1, ncols: int = 1)[source]

Bases: magicclass.ext.vispy._base.MultiPlot

A multiple Vispy based 2-D plot canvas.

class magicclass.ext.vispy.VispyPlotCanvas(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget, magicclass.ext.vispy.widgets2d.PlotItem

A Vispy based 2-D plot canvas for curve, histogram, bar plot etc.