Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from ...layers import Image, Labels, Points, Shapes, Surface, Vectors
from .qt_image_layer import QtImageControls
from .qt_points_layer import QtPointsControls
from .qt_shapes_layer import QtShapesControls
from .qt_labels_layer import QtLabelsControls
from .qt_surface_layer import QtSurfaceControls
from .qt_vectors_layer import QtVectorsControls
layer_to_controls = {
Image: QtImageControls,
Labels: QtLabelsControls,
Points: QtPointsControls,
Shapes: QtShapesControls,
Surface: QtSurfaceControls,
Vectors: QtVectorsControls,
}
def create_qt_controls(layer):
"""
Create a qt controls widget for a layer based on its layer type.
Parameters
----------
layer : napari.layers._base_layer.Layer
Layer that needs its controls widget created.
Path or list of paths to image data. Paths can be passed as strings
or `pathlib.Path` instances.
Returns
-------
layer : :class:`napari.layers.Labels`
The newly-created labels layer.
"""
if data is None and path is None:
raise ValueError("One of either data or path must be provided")
elif data is not None and path is not None:
raise ValueError("Only one of data or path can be provided")
elif data is None:
data = io.magic_imread(path)
layer = layers.Labels(
data,
is_pyramid=is_pyramid,
num_colors=num_colors,
seed=seed,
name=name,
metadata=metadata,
scale=scale,
translate=translate,
opacity=opacity,
blending=blending,
visible=visible,
)
self.add_layer(layer)
return layer
Translation values for the layer.
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 : :class:`napari.layers.Labels`
The newly-created labels layer.
"""
layer = layers.Labels(
data,
is_pyramid=is_pyramid,
num_colors=num_colors,
seed=seed,
n_dimensional=n_dimensional,
name=name,
metadata=metadata,
scale=scale,
translate=translate,
opacity=opacity,
blending=blending,
visible=visible,
)
self.add_layer(layer)
return layer
def time_create_layer(self, n):
"""Time to create layer."""
Labels(self.data)
def setup(self, n):
np.random.seed(0)
self.data = np.random.randint(20, size=(n, n, n))
self.layer = Labels(self.data)