code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def scale(self, scale, center=None): """Performs a scaling on the shape Parameters ---------- scale : float, list scalar or list specifying rescaling of shape. center : list length 2 list specifying coordinate of center of scaling. """ if ...
Performs a scaling on the shape Parameters ---------- scale : float, list scalar or list specifying rescaling of shape. center : list length 2 list specifying coordinate of center of scaling.
scale
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def rotate(self, angle, center=None): """Performs a rotation on the shape Parameters ---------- angle : float angle specifying rotation of shape in degrees. CCW is positive. center : list length 2 list specifying coordinate of fixed point of the rotation....
Performs a rotation on the shape Parameters ---------- angle : float angle specifying rotation of shape in degrees. CCW is positive. center : list length 2 list specifying coordinate of fixed point of the rotation.
rotate
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def flip(self, axis, center=None): """Performs a flip on the shape, either horizontal or vertical. Parameters ---------- axis : int integer specifying axis of flip. `0` flips horizontal, `1` flips vertical. center : list length 2 list specifyi...
Performs a flip on the shape, either horizontal or vertical. Parameters ---------- axis : int integer specifying axis of flip. `0` flips horizontal, `1` flips vertical. center : list length 2 list specifying coordinate of center of flip axes.
flip
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def to_mask(self, mask_shape=None, zoom_factor=1, offset=(0, 0)): """Convert the shape vertices to a boolean mask. Set points to `True` if they are lying inside the shape if the shape is filled, or if they are lying along the boundary of the shape if the shape is not filled. Negative po...
Convert the shape vertices to a boolean mask. Set points to `True` if they are lying inside the shape if the shape is filled, or if they are lying along the boundary of the shape if the shape is not filled. Negative points or points outside the mask_shape after the zoom and offset are c...
to_mask
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def triangulation_backend(request): """Fixture to switch between triangulation backends.""" settings = get_settings() prev = settings.experimental.triangulation_backend if BACKEND_TO_MODULE[request.param] not in sys.modules: pytest.importorskip(str(request.param)) settings.experimental.trian...
Fixture to switch between triangulation backends.
triangulation_backend
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_rectangle1(): """Test creating Rectangle by four corners.""" np.random.seed(0) data = np.array([(10, 10), (20, 10), (20, 20), (10, 20)], dtype=np.float32) shape = Rectangle(data) np.testing.assert_array_equal(shape.data, data) assert shape.data_displayed.shape == (4, 2) assert shape...
Test creating Rectangle by four corners.
test_rectangle1
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_rectangle2(): """Test creating Rectangle by upper left and bottom right.""" # If given two corners, representation will be expanded to four data = np.array([[-10, -10], [20, 20]], dtype=np.float32) shape = Rectangle(data) assert len(shape.data) == 4 assert shape.data_displayed.shape == ...
Test creating Rectangle by upper left and bottom right.
test_rectangle2
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_rectangle_bounding_box(): """Test that the bounding box is correctly updated based on edge width.""" data = [[10, 10], [20, 20]] shape = Rectangle(data) npt.assert_array_equal( shape.bounding_box, np.array([[9.5, 9.5], [20.5, 20.5]]) ) shape.edge_width = 2 npt.assert_array_e...
Test that the bounding box is correctly updated based on edge width.
test_rectangle_bounding_box
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_nD_rectangle(): """Test creating Shape with a single four corner planar 3D rectangle.""" data = np.array( [[0, -10, -10], [0, -10, 20], [0, 20, 20], [0, 20, -10]], dtype=np.float32, ) shape = Rectangle(data) np.testing.assert_array_equal(shape.data, data) assert shape.da...
Test creating Shape with a single four corner planar 3D rectangle.
test_nD_rectangle
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_polygon(triangulation_backend): """Test creating Shape with a random polygon.""" # Test a single non convex six vertex polygon data = np.array( [ [10.97627008, 14.30378733], [12.05526752, 10.89766366], [8.47309599, 12.91788226], [8.75174423, 1...
Test creating Shape with a random polygon.
test_polygon
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_nD_polygon(): """Test creating Shape with a random nD polygon.""" # Test a single six vertex planar 3D polygon np.random.seed(0) data = 20 * np.random.random((6, 3)).astype(np.float32) data[:, 0] = 0 shape = Polygon(data) np.testing.assert_array_equal(shape.data, data) assert sh...
Test creating Shape with a random nD polygon.
test_nD_polygon
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_path(): """Test creating Shape with a random path.""" # Test a single six vertex path np.random.seed(0) data = 20 * np.random.random((6, 2)).astype(np.float32) shape = Path(data) np.testing.assert_array_equal(shape.data, data) assert shape.data_displayed.shape == (6, 2) assert s...
Test creating Shape with a random path.
test_path
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_nD_path(): """Test creating Shape with a random nD path.""" # Test a single six vertex 3D path np.random.seed(0) data = 20 * np.random.random((6, 3)).astype(np.float32) shape = Path(data) np.testing.assert_array_equal(shape.data, data) assert shape.data_displayed.shape == (6, 2) ...
Test creating Shape with a random nD path.
test_nD_path
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_ellipse1(): """Test creating Ellipse by four corners.""" data = np.array([(10, 10), (20, 10), (20, 20), (10, 20)], dtype=np.float32) shape = Ellipse(data) np.testing.assert_array_equal(shape.data, data) assert shape.data_displayed.shape == (4, 2) assert shape.slice_key.shape == (2, 0)
Test creating Ellipse by four corners.
test_ellipse1
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_ellipse2(): """Test creating Ellipse by upper left and lower right corners.""" data = np.array([[10, 10], [20, 20]], dtype=np.float32) shape = Ellipse(data) assert len(shape.data) == 4 assert shape.data_displayed.shape == (4, 2) assert shape.slice_key.shape == (2, 0)
Test creating Ellipse by upper left and lower right corners.
test_ellipse2
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_nD_ellipse(): """Test creating Shape with a random nD ellipse.""" # Test a single four corner planar 3D ellipse data = np.array( [(0, -10, -10), (0, -10, 20), (0, 20, 20), (0, 20, -10)], dtype=np.float32, ) shape = Ellipse(data) np.testing.assert_array_equal(shape.data, ...
Test creating Shape with a random nD ellipse.
test_nD_ellipse
python
napari/napari
src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/_tests/test_shapes_models.py
BSD-3-Clause
def test_update_thumbnail_empty_shapes(): """Test updating the thumbnail with an empty shapes layer.""" layer = Shapes() layer._allow_thumbnail_update = True layer._update_thumbnail()
Test updating the thumbnail with an empty shapes layer.
test_update_thumbnail_empty_shapes
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_empty_shapes_with_features(): """See the following for the points issues this covers: https://github.com/napari/napari/issues/5632 https://github.com/napari/napari/issues/5634 """ shapes = Shapes( features={'a': np.empty(0, int)}, feature_defaults={'a': 0}, face_colo...
See the following for the points issues this covers: https://github.com/napari/napari/issues/5632 https://github.com/napari/napari/issues/5634
test_empty_shapes_with_features
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_data_setter_with_properties(): """Test layer data on a layer with properties via the data setter""" shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) properties = {'shape_type': _make_cycled_properties(['A', 'B'], shape[0])} layer = Shapes(data, properties=propert...
Test layer data on a layer with properties via the data setter
test_data_setter_with_properties
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_nd_text(prepend): """Test slicing of text coords with nD shapes We can prepend as many dimensions as we want it should not change the result """ shapes_data = [ [ prepend + (0, 10, 10, 10), prepend + (0, 10, 20, 20), prepend + (0, 10, 10, 20), ...
Test slicing of text coords with nD shapes We can prepend as many dimensions as we want it should not change the result
test_nd_text
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_data_setter_with_text(properties): """Test layer data on a layer with text via the data setter""" shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer = Shapes(data, properties=copy(properties), text='shape_type') # test setting to data with fewer shapes n...
Test layer data on a layer with text via the data setter
test_data_setter_with_text
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_rectangles(two_and_four_corners): """Test instantiating Shapes layer with a random 2D rectangles.""" # Test instantiating with data layer = Shapes(two_and_four_corners) assert layer.nshapes == len(two_and_four_corners) # 4 corner rectangle(s) passed, assert vertices the same if two_and_...
Test instantiating Shapes layer with a random 2D rectangles.
test_rectangles
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_rectangle_with_shape_type(single_four_corner: list[np.ndarray]): """Test instantiating rectangles with shape_type in data""" # Test (rectangle, shape_type) tuple data = (single_four_corner, 'rectangle') layer = Shapes(data) assert layer.nshapes == 1 assert np.array_equiv(layer.data[0], ...
Test instantiating rectangles with shape_type in data
test_rectangle_with_shape_type
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_rectangles_roundtrip(): """Test a full roundtrip with rectangles data.""" shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer = Shapes(data) new_layer = Shapes(layer.data) assert np.all( [nd == d for nd, d in zip(new_layer.data, layer.data, strict=...
Test a full roundtrip with rectangles data.
test_rectangles_roundtrip
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_integer_rectangle(): """Test instantiating rectangles with integer data.""" shape = (10, 2, 2) np.random.seed(1) data = np.random.randint(20, size=shape) layer = Shapes(data) assert layer.nshapes == shape[0] assert np.all([len(ld) == 4 for ld in layer.data]) assert layer.ndim ==...
Test instantiating rectangles with integer data.
test_integer_rectangle
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_negative_rectangle(ten_four_corner): """Test instantiating rectangles with negative data.""" data = [x - 10 for x in ten_four_corner] layer = Shapes(data) assert layer.nshapes == len(data) assert np.all( [ np.array_equal(ld, d) for ld, d in zip(layer.data, da...
Test instantiating rectangles with negative data.
test_negative_rectangle
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_empty_rectangle(): """Test instantiating rectangles with empty data.""" shape = (0, 0, 2) data = np.empty(shape) layer = Shapes(data) assert layer.nshapes == 0 assert len(layer.data) == 0 assert layer.ndim == 2
Test instantiating rectangles with empty data.
test_empty_rectangle
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_3D_rectangles(): """Test instantiating Shapes layer with 3D planar rectangles.""" # Test a single four corner rectangle np.random.seed(0) planes = np.tile(np.arange(10).reshape((10, 1, 1)), (1, 4, 1)) corners = np.random.uniform(0, 10, size=(10, 4, 2)) data = np.concatenate((planes, cor...
Test instantiating Shapes layer with 3D planar rectangles.
test_3D_rectangles
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_ellipses(two_and_four_corners): """Test instantiating Shapes layer with 2D ellipses.""" # Test instantiating with data layer = Shapes(two_and_four_corners, shape_type='ellipse') assert layer.nshapes == len(two_and_four_corners) # 4 corner bounding box passed, assert vertices the same if...
Test instantiating Shapes layer with 2D ellipses.
test_ellipses
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_single_ellipses_with_shape_type(single_four_corner): """Test instantiating ellipses with shape_type in data""" # Test single four corner (vertices, shape_type) tuple data = (single_four_corner, 'ellipse') layer = Shapes(data) assert layer.nshapes == len(single_four_corner) assert np.arr...
Test instantiating ellipses with shape_type in data
test_single_ellipses_with_shape_type
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_4D_ellispse(): """Test instantiating Shapes layer with 4D planar ellipse.""" # Test a single 4D ellipse np.random.seed(0) data = [ [ [3, 5, 108, 108], [3, 5, 108, 148], [3, 5, 148, 148], [3, 5, 148, 108], ] ] layer = Shapes...
Test instantiating Shapes layer with 4D planar ellipse.
test_4D_ellispse
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_ellipses_roundtrip(): """Test a full roundtrip with ellipss data.""" shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer = Shapes(data, shape_type='ellipse') new_layer = Shapes(layer.data, shape_type='ellipse') assert np.all( [nd == d for nd, d in ...
Test a full roundtrip with ellipss data.
test_ellipses_roundtrip
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_lines(two_corners): """Test instantiating Shapes layer with a random 2D lines.""" # Test instantiating with data layer = Shapes(two_corners, shape_type='line') assert layer.nshapes == len(two_corners) assert np.all( [ np.array_equal(ld, d) for ld, d in zip(la...
Test instantiating Shapes layer with a random 2D lines.
test_lines
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_add_lines_raises_error(): """Test adding lines with incorrect vertices raise error""" # single line shape = (1, 3, 2) data = 20 * np.random.random(shape) layer = Shapes() with pytest.raises(ValueError, match='invalid number of vertices'): layer.add_lines(data) # multiple l...
Test adding lines with incorrect vertices raise error
test_add_lines_raises_error
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_lines_roundtrip(): """Test a full roundtrip with line data.""" shape = (10, 2, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer = Shapes(data, shape_type='line') new_layer = Shapes(layer.data, shape_type='line') assert np.all( [nd == d for nd, d in zip(new_laye...
Test a full roundtrip with line data.
test_lines_roundtrip
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_paths(shape): """Test instantiating Shapes layer with random 2D paths.""" # Test instantiating with data data = [20 * np.random.random(shape).astype(np.float32)] layer = Shapes(data, shape_type='path') assert layer.nshapes == len(data) assert np.all( [ np.array_equa...
Test instantiating Shapes layer with random 2D paths.
test_paths
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_add_paths_raises_error(): """Test adding paths with incorrect vertices raise error""" # single path shape = (1, 1, 2) data = 20 * np.random.random(shape) layer = Shapes() with pytest.raises(ValueError, match='invalid number of vertices'): layer.add_paths(data) # multiple p...
Test adding paths with incorrect vertices raise error
test_add_paths_raises_error
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_paths_with_shape_type(): """Test instantiating paths with shape_type in data""" # Test (single path, shape_type) tuple shape = (1, 6, 2) np.random.seed(0) path_points = 20 * np.random.random(shape).astype(np.float32) data = (path_points, 'path') layer = Shapes(data) assert layer...
Test instantiating paths with shape_type in data
test_paths_with_shape_type
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_paths_roundtrip(): """Test a full roundtrip with path data.""" np.random.seed(0) data = [ 20 * np.random.random((np.random.randint(2, 12), 2)) for i in range(10) ] layer = Shapes(data, shape_type='path') new_layer = Shapes(layer.data, shape_type='path') assert np.all( ...
Test a full roundtrip with path data.
test_paths_roundtrip
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_polygons(shape): """Test instantiating Shapes layer with a random 2D polygons.""" # Test instantiating with data data = [20 * np.random.random(shape).astype(np.float32)] layer = Shapes(data, shape_type='polygon') assert layer.nshapes == len(data) assert np.all( [ np...
Test instantiating Shapes layer with a random 2D polygons.
test_polygons
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_polygon_roundtrip(): """Test a full roundtrip with polygon data.""" np.random.seed(0) data = [ 20 * np.random.random((np.random.randint(2, 12), 2)) for i in range(10) ] layer = Shapes(data, shape_type='polygon') new_layer = Shapes(layer.data, shape_type='polygon') assert np....
Test a full roundtrip with polygon data.
test_polygon_roundtrip
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_mixed_shapes(): """Test instantiating Shapes layer with a mix of random 2D shapes.""" # Test multiple polygons with different numbers of points np.random.seed(0) shape_vertices = [ 20 * np.random.random((np.random.randint(2, 12), 2)).astype(np.float32) for i in range(5) ] + ...
Test instantiating Shapes layer with a mix of random 2D shapes.
test_mixed_shapes
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_mixed_shapes_with_shape_type(): """Test adding mixed shapes with shape_type in data""" np.random.seed(0) shape_vertices = [ 20 * np.random.random((np.random.randint(2, 12), 2)).astype(np.float32) for i in range(5) ] + list(np.random.random((5, 4, 2)).astype(np.float32)) shap...
Test adding mixed shapes with shape_type in data
test_mixed_shapes_with_shape_type
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_data_shape_type_overwrites_meta(): """Test shape type passed through data property overwrites metadata shape type""" shape = (10, 4, 2) np.random.seed(0) vertices = 20 * np.random.random(shape) data = (vertices, 'ellipse') layer = Shapes(data, shape_type='rectangle') assert np.all([...
Test shape type passed through data property overwrites metadata shape type
test_data_shape_type_overwrites_meta
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_removing_all_shapes_empty_list(): """Test removing all shapes with an empty list.""" data = 20 * np.random.random((10, 4, 2)) np.random.seed(0) layer = Shapes(data) layer.events.data = Mock() old_data = layer.data assert layer.nshapes == 10 layer.data = [] assert layer.nsha...
Test removing all shapes with an empty list.
test_removing_all_shapes_empty_list
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_color_direct(attribute: str): """Test setting face/edge color directly.""" shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer_kwargs = {f'{attribute}_color': 'black'} layer = Shapes(data, **layer_kwargs) color_array = transform_color(['black'] * shape[0])...
Test setting face/edge color directly.
test_color_direct
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_single_shape_properties(attribute): """Test creating single shape with properties""" shape = (4, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer_kwargs = {f'{attribute}_color': 'red'} layer = Shapes(data, **layer_kwargs) layer_color = getattr(layer, f'{attribute}_colo...
Test creating single shape with properties
test_single_shape_properties
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_color_cycle(attribute, color_cycle): """Test setting edge/face color with a color cycle list""" # create Shapes using list color cycle shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) properties = {'shape_type': _make_cycled_properties(['A', 'B'], shape[0])} ...
Test setting edge/face color with a color cycle list
test_color_cycle
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_add_color_cycle_to_empty_layer(attribute): """Test adding a shape to an empty layer when edge/face color is a color cycle See: https://github.com/napari/napari/pull/1069 """ default_properties = {'shape_type': np.array(['A'])} color_cycle = ['red', 'blue'] shapes_kwargs = { 'pr...
Test adding a shape to an empty layer when edge/face color is a color cycle See: https://github.com/napari/napari/pull/1069
test_add_color_cycle_to_empty_layer
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_adding_value_color_cycle(attribute): """Test that adding values to properties used to set a color cycle and then calling Shapes.refresh_colors() performs the update and adds the new value to the face/edge_color_cycle_map. """ shape = (10, 4, 2) np.random.seed(0) data = 20 * np.rando...
Test that adding values to properties used to set a color cycle and then calling Shapes.refresh_colors() performs the update and adds the new value to the face/edge_color_cycle_map.
test_adding_value_color_cycle
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_color_colormap(attribute): """Test setting edge/face color with a colormap""" # create Shapes using with a colormap shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) properties = {'shape_type': _make_cycled_properties([0, 1.5], shape[0])} shapes_kwargs = { ...
Test setting edge/face color with a colormap
test_color_colormap
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_interaction_box(): """Test the creation of the interaction box.""" shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer = Shapes(data) assert layer._selected_box is None layer.selected_data = {0} assert len(layer._selected_box) == 10 layer.selecte...
Test the creation of the interaction box.
test_interaction_box
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_copy_and_paste(): """Test copying and pasting selected shapes.""" shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer = Shapes(data) # Clipboard starts empty assert layer._clipboard == {} # Pasting empty clipboard doesn't change data layer._paste_...
Test copying and pasting selected shapes.
test_copy_and_paste
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_message(): """Test converting values and coords to message.""" shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer = Shapes(data) msg = layer.get_status((0,) * 2) assert isinstance(msg, dict)
Test converting values and coords to message.
test_message
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_to_masks_default_shape(): """Test that labels data generation preserves origin at (0, 0). See https://github.com/napari/napari/issues/3401 """ shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) + [50, 100] layer = Shapes(data) masks = layer.to_masks() ...
Test that labels data generation preserves origin at (0, 0). See https://github.com/napari/napari/issues/3401
test_to_masks_default_shape
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_add_single_shape_consistent_properties(): """Test adding a single shape ensures correct number of added properties""" data = [ np.array([[100, 200], [200, 300]]), np.array([[300, 400], [400, 500]]), ] properties = {'index': [1, 2]} layer = Shapes( np.array(data), sha...
Test adding a single shape ensures correct number of added properties
test_add_single_shape_consistent_properties
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_add_shapes_consistent_properties(): """Test adding multiple shapes ensures correct number of added properties""" data = [ np.array([[100, 200], [200, 300]]), np.array([[300, 400], [400, 500]]), ] properties = {'index': [1, 2]} layer = Shapes( np.array(data), shape_ty...
Test adding multiple shapes ensures correct number of added properties
test_add_shapes_consistent_properties
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def test_set_data_3d(): """Test to reproduce https://github.com/napari/napari/issues/4527""" lines = [ np.array([[0, 0, 0], [500, 0, 0]]), np.array([[0, 0, 0], [0, 300, 0]]), np.array([[0, 0, 0], [0, 0, 200]]), ] shapes = Shapes(lines, shape_type='line') shapes._slice_dims(Di...
Test to reproduce https://github.com/napari/napari/issues/4527
test_set_data_3d
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes.py
BSD-3-Clause
def create_known_shapes_layer(): """Create shapes layer with known coordinates Returns ------- layer : napari.layers.Shapes Shapes layer. n_shapes : int Number of shapes in the shapes layer known_non_shape : list Data coordinates that are known to contain no shapes. Usef...
Create shapes layer with known coordinates Returns ------- layer : napari.layers.Shapes Shapes layer. n_shapes : int Number of shapes in the shapes layer known_non_shape : list Data coordinates that are known to contain no shapes. Useful during testing when needing t...
create_known_shapes_layer
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_not_adding_or_selecting_shape(create_known_shapes_layer): """Don't add or select a shape by clicking on one in pan_zoom mode.""" layer, n_shapes, _ = create_known_shapes_layer layer.mode = 'pan_zoom' # Simulate click event = read_only_mouse_event( type='mouse_press', ) mous...
Don't add or select a shape by clicking on one in pan_zoom mode.
test_not_adding_or_selecting_shape
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_add_simple_shape(shape_type, create_known_shapes_layer): """Add simple shape by clicking in add mode.""" layer, n_shapes, known_non_shape = create_known_shapes_layer # Add shape at location where non exists layer.mode = 'add_' + shape_type # Simulate click event = read_only_mouse_even...
Add simple shape by clicking in add mode.
test_add_simple_shape
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_polygon_lasso_tablet(create_known_shapes_layer): """Draw polygon with tablet simulated by mouse drag event.""" layer, n_shapes, known_non_shape = create_known_shapes_layer desired_shape = np.array([[20, 30], [10, 50], [60, 40], [80, 20]]) get_settings().experimental.rdp_epsilon = 0 layer.m...
Draw polygon with tablet simulated by mouse drag event.
test_polygon_lasso_tablet
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_polygon_lasso_mouse(create_known_shapes_layer): """Draw polygon with mouse. Events in sequence are mouse press, release, move, press, release""" layer, n_shapes, known_non_shape = create_known_shapes_layer desired_shape = np.array([[20, 30], [10, 50], [60, 40], [80, 20]]) get_settings().experi...
Draw polygon with mouse. Events in sequence are mouse press, release, move, press, release
test_polygon_lasso_mouse
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_distance_polygon_creating(create_known_shapes_layer): """Test that distance threshold in polygon creating works as intended""" layer, n_shapes, known_non_shape = create_known_shapes_layer # While drawing only 2 of the vertices should be added to shape data because distance threshold is 10 vert...
Test that distance threshold in polygon creating works as intended
test_distance_polygon_creating
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_add_invalid_shape(shape_type_vertices, create_known_shapes_layer): """Check invalid shape clicking behavior in add polygon mode.""" layer, n_shapes, known_non_shape = create_known_shapes_layer # Add shape at location where non exists shape_type, shape_vertices = shape_type_vertices layer.m...
Check invalid shape clicking behavior in add polygon mode.
test_add_invalid_shape
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_select_shape(mode, create_known_shapes_layer): """Select a shape by clicking on one in select mode.""" layer, n_shapes, _ = create_known_shapes_layer layer.mode = mode position = tuple(layer.data[0][0]) # Simulate click event = read_only_mouse_event( type='mouse_press', ...
Select a shape by clicking on one in select mode.
test_select_shape
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_rotate_shape(create_known_shapes_layer): """Select and drag handle to rotate shape.""" layer, n_shapes, _ = create_known_shapes_layer layer.mode = 'select' layer.selected_data = {1} # get the position of the rotation handle position = tuple(layer._selected_box[9]) # get the vertexe...
Select and drag handle to rotate shape.
test_rotate_shape
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_not_selecting_shape(mode, create_known_shapes_layer): """Don't select a shape by not clicking on one in select mode.""" layer, n_shapes, known_non_shape = create_known_shapes_layer layer.mode = mode # Simulate click event = read_only_mouse_event( type='mouse_press', positi...
Don't select a shape by not clicking on one in select mode.
test_not_selecting_shape
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_unselecting_shapes(mode, create_known_shapes_layer): """Unselect shapes by not clicking on one in select mode.""" layer, n_shapes, known_non_shape = create_known_shapes_layer layer.mode = mode layer.selected_data = {0, 1} assert len(layer.selected_data) == 2 # Simulate click event...
Unselect shapes by not clicking on one in select mode.
test_unselecting_shapes
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_selecting_shapes_with_drag(mode, create_known_shapes_layer): """Select all shapes when drag box includes all of them.""" layer, n_shapes, known_non_shape = create_known_shapes_layer layer.mode = mode # Simulate click event = read_only_mouse_event( type='mouse_press', posit...
Select all shapes when drag box includes all of them.
test_selecting_shapes_with_drag
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def test_all_modes_covered(attr): """ Test that all dictionaries modes have all the keys, this simplify the handling logic As we do not need to test whether a key is in a dict or not. """ mode_dict = getattr(Shapes, attr) assert {k.value for k in mode_dict} == set(Mode.keys())
Test that all dictionaries modes have all the keys, this simplify the handling logic As we do not need to test whether a key is in a dict or not.
test_all_modes_covered
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
BSD-3-Clause
def _regen_testcases(): """ In case the below test cases need to be update here is a simple function you can run to regenerate the `cases` variable below. """ exec( """ from napari.layers.shapes._tests.test_shapes_utils import ( generate_2D_edge_meshes, W_DATA, ) mesh_cases = [ ...
In case the below test cases need to be update here is a simple function you can run to regenerate the `cases` variable below.
_regen_testcases
python
napari/napari
src/napari/layers/shapes/_tests/test_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shapes_utils.py
BSD-3-Clause
def test_reset_bounding_box_rotation(): """Test if rotating shape resets bounding box.""" shape = Rectangle(np.array([[0, 0], [10, 10]])) shape_list = ShapeList() shape_list.add(shape) npt.assert_array_almost_equal( shape_list._bounding_boxes, np.array([[[-0.5, -0.5]], [[10.5, 10.5]]]) )...
Test if rotating shape resets bounding box.
test_reset_bounding_box_rotation
python
napari/napari
src/napari/layers/shapes/_tests/test_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shape_list.py
BSD-3-Clause
def test_reset_bounding_box_shift(): """Test if shifting shape resets bounding box.""" shape = Rectangle(np.array([[0, 0], [10, 10]])) shape_list = ShapeList() shape_list.add(shape) npt.assert_array_almost_equal( shape_list._bounding_boxes, shape.bounding_box[:, np.newaxis, :] ) shap...
Test if shifting shape resets bounding box.
test_reset_bounding_box_shift
python
napari/napari
src/napari/layers/shapes/_tests/test_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shape_list.py
BSD-3-Clause
def test_reset_bounding_box_scale(): """Test if scaling shape resets the bounding box.""" shape = Rectangle(np.array([[0, 0], [10, 10]])) shape_list = ShapeList() shape_list.add(shape) npt.assert_array_almost_equal( shape_list._bounding_boxes, shape.bounding_box[:, np.newaxis, :] ) s...
Test if scaling shape resets the bounding box.
test_reset_bounding_box_scale
python
napari/napari
src/napari/layers/shapes/_tests/test_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shape_list.py
BSD-3-Clause
def test_visible_shapes_4d(): """Test _visible_shapes with 4D data like those from OME-Zarr/OMERO.""" shape1 = Polygon( np.array( [ [0, 0, 10, 10], [0, 0, 10, 50], [0, 0, 50, 50], [0, 0, 50, 10], ] ) ) ...
Test _visible_shapes with 4D data like those from OME-Zarr/OMERO.
test_visible_shapes_4d
python
napari/napari
src/napari/layers/shapes/_tests/test_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_shape_list.py
BSD-3-Clause
def _disable_jit(request): """Fixture to temporarily disable numba JIT during testing. This helps to measure coverage and in debugging. *However*, reloading a module can cause issues with object instance / class relationships, so the `_accelerated_cmap` module should be as small as possible and contain...
Fixture to temporarily disable numba JIT during testing. This helps to measure coverage and in debugging. *However*, reloading a module can cause issues with object instance / class relationships, so the `_accelerated_cmap` module should be as small as possible and contain no class definitions, only fu...
_disable_jit
python
napari/napari
src/napari/layers/shapes/_tests/test_triangulation.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_tests/test_triangulation.py
BSD-3-Clause
def vertices(self, vertices): """Array of vertices of mesh triangles.""" self._vertices = vertices self._update_dims() self.events.data(value=self.data) self._reset_editable()
Array of vertices of mesh triangles.
vertices
python
napari/napari
src/napari/layers/surface/surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/surface.py
BSD-3-Clause
def vertex_values(self, vertex_values: np.ndarray) -> None: """Array of values (n, 1) used to color vertices with a colormap.""" if vertex_values is None: vertex_values = np.ones(len(self._vertices)) self._vertex_values = vertex_values self._update_dims() self.event...
Array of values (n, 1) used to color vertices with a colormap.
vertex_values
python
napari/napari
src/napari/layers/surface/surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/surface.py
BSD-3-Clause
def vertex_colors(self, vertex_colors: np.ndarray | None) -> None: """Values used to directly color vertices. Note that dims sliders for this layer are based on vertex_values, so make sure the shape of vertex_colors matches the shape of vertex_values for proper slicing. That is: vertex_...
Values used to directly color vertices. Note that dims sliders for this layer are based on vertex_values, so make sure the shape of vertex_colors matches the shape of vertex_values for proper slicing. That is: vertex_colors should be None, one set (N, C), or completely match the dimensi...
vertex_colors
python
napari/napari
src/napari/layers/surface/surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/surface.py
BSD-3-Clause
def faces(self, faces: np.ndarray) -> None: """Array of indices of mesh triangles.""" self.faces = faces self.refresh(extent=False) self.events.data(value=self.data) self._reset_editable()
Array of indices of mesh triangles.
faces
python
napari/napari
src/napari/layers/surface/surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/surface.py
BSD-3-Clause
def _has_texture(self) -> bool: """Whether the layer has sufficient data for texturing""" return bool( self.texture is not None and self.texcoords is not None and len(self.texcoords) )
Whether the layer has sufficient data for texturing
_has_texture
python
napari/napari
src/napari/layers/surface/surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/surface.py
BSD-3-Clause
def _slice_associated_data( self, data: np.ndarray, vertex_ndim: int, dims: int = 1, ) -> list[Any] | np.ndarray: """Return associated layer data (e.g. vertex values, colors) within the current slice. """ if data is None: return [] ...
Return associated layer data (e.g. vertex values, colors) within the current slice.
_slice_associated_data
python
napari/napari
src/napari/layers/surface/surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/surface.py
BSD-3-Clause
def _get_value_3d( self, start_point: np.ndarray | None, end_point: np.ndarray | None, dims_displayed: list[int], ) -> tuple[None | float | int, int | None]: """Get the layer data value along a ray Parameters ---------- start_point : np.ndarray ...
Get the layer data value along a ray Parameters ---------- start_point : np.ndarray The start position of the ray used to interrogate the data. end_point : np.ndarray The end position of the ray used to interrogate the data. dims_displayed : List[int] ...
_get_value_3d
python
napari/napari
src/napari/layers/surface/surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/surface.py
BSD-3-Clause
def calculate_barycentric_coordinates( point: np.ndarray, triangle_vertices: np.ndarray ) -> np.ndarray: """Calculate the barycentric coordinates for a point in a triangle. http://gamedev.stackexchange.com/questions/23743/whats-the-most-efficient-way-to-find-barycentric-coordinates Parameters ----...
Calculate the barycentric coordinates for a point in a triangle. http://gamedev.stackexchange.com/questions/23743/whats-the-most-efficient-way-to-find-barycentric-coordinates Parameters ---------- point : np.ndarray The coordinates of the point for which to calculate the barycentric coordinate...
calculate_barycentric_coordinates
python
napari/napari
src/napari/layers/surface/_surface_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_surface_utils.py
BSD-3-Clause
def test_random_surface(): """Test instantiating Surface layer with random 2D data.""" np.random.seed(0) vertices = np.random.random((10, 2)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random(10) data = (vertices, faces, values) layer = Surface(data) assert layer.ndim ...
Test instantiating Surface layer with random 2D data.
test_random_surface
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def test_random_surface_features(): """Test instantiating surface layer with features.""" np.random.seed(0) vertices = np.random.random((10, 3)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random(10) features = pd.DataFrame({'feature': np.random.random(10)}) data = (vertic...
Test instantiating surface layer with features.
test_random_surface_features
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def test_random_surface_no_values(): """Test instantiating Surface layer with random 2D data but no vertex values.""" np.random.seed(0) vertices = np.random.random((10, 2)) faces = np.random.randint(10, size=(6, 3)) data = (vertices, faces) layer = Surface(data) assert layer.ndim == 2 as...
Test instantiating Surface layer with random 2D data but no vertex values.
test_random_surface_no_values
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def test_random_surface_clearing_vertex_values(): """Test setting `vertex_values=None` resets values to uniform ones.""" np.random.seed(0) vertices = np.random.random((10, 2)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random(10) data = (vertices, faces, values) layer = Su...
Test setting `vertex_values=None` resets values to uniform ones.
test_random_surface_clearing_vertex_values
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def test_random_3D_surface(): """Test instantiating Surface layer with random 3D data.""" np.random.seed(0) vertices = np.random.random((10, 3)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random(10) data = (vertices, faces, values) layer = Surface(data) assert layer.nd...
Test instantiating Surface layer with random 3D data.
test_random_3D_surface
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def test_random_4D_surface(): """Test instantiating Surface layer with random 4D data.""" np.random.seed(0) vertices = np.random.random((10, 4)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random(10) data = (vertices, faces, values) layer = Surface(data) assert layer.nd...
Test instantiating Surface layer with random 4D data.
test_random_4D_surface
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def test_random_3D_timeseries_surface(): """Test instantiating Surface layer with random 3D timeseries data.""" np.random.seed(0) vertices = np.random.random((10, 3)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random((22, 10)) data = (vertices, faces, values) layer = Surfa...
Test instantiating Surface layer with random 3D timeseries data.
test_random_3D_timeseries_surface
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def test_random_3D_multitimeseries_surface(): """Test instantiating Surface layer with random 3D multitimeseries data.""" np.random.seed(0) vertices = np.random.random((10, 3)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random((16, 22, 10)) data = (vertices, faces, values) ...
Test instantiating Surface layer with random 3D multitimeseries data.
test_random_3D_multitimeseries_surface
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def test_surface_normals(): """Ensure that normals can be set both with dict and SurfaceNormals. The model should internally always use SurfaceNormals. """ vertices = np.array( [ [3, 0, 0], [3, 0, 3], [3, 3, 0], [5, 0, 0], [5, 0, 3], ...
Ensure that normals can be set both with dict and SurfaceNormals. The model should internally always use SurfaceNormals.
test_surface_normals
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def test_surface_wireframe(): """Ensure that wireframe can be set both with dict and SurfaceWireframe. The model should internally always use SurfaceWireframe. """ vertices = np.array( [ [3, 0, 0], [3, 0, 3], [3, 3, 0], [5, 0, 0], [5, ...
Ensure that wireframe can be set both with dict and SurfaceWireframe. The model should internally always use SurfaceWireframe.
test_surface_wireframe
python
napari/napari
src/napari/layers/surface/_tests/test_surface.py
https://github.com/napari/napari/blob/master/src/napari/layers/surface/_tests/test_surface.py
BSD-3-Clause
def _get_value(self, position) -> int | None: """Value of the data at a position in data coordinates. Use a kd-tree to lookup the ID of the nearest tree. Parameters ---------- position : tuple Position in data coordinates. Returns ------- va...
Value of the data at a position in data coordinates. Use a kd-tree to lookup the ID of the nearest tree. Parameters ---------- position : tuple Position in data coordinates. Returns ------- value : int or None Index of track that is at t...
_get_value
python
napari/napari
src/napari/layers/tracks/tracks.py
https://github.com/napari/napari/blob/master/src/napari/layers/tracks/tracks.py
BSD-3-Clause
def _pad_display_data(self, vertices): """pad display data when moving between 2d and 3d""" if vertices is None: return None data = vertices[:, self._slice_input.displayed] # if we're only displaying two dimensions, then pad the display dim # with zeros if se...
pad display data when moving between 2d and 3d
_pad_display_data
python
napari/napari
src/napari/layers/tracks/tracks.py
https://github.com/napari/napari/blob/master/src/napari/layers/tracks/tracks.py
BSD-3-Clause
def current_time(self) -> int | None: """current time according to the first dimension""" # TODO(arl): get the correct index here time_step = self._data_slice.point[0] if isinstance(time_step, slice): # if we are visualizing all time, then just set to the maximum ...
current time according to the first dimension
current_time
python
napari/napari
src/napari/layers/tracks/tracks.py
https://github.com/napari/napari/blob/master/src/napari/layers/tracks/tracks.py
BSD-3-Clause
def data(self, data: np.ndarray) -> None: """set the data and build the vispy arrays for display""" # set the data and build the tracks self._manager.data = data self._manager.build_tracks() # reset the properties and recolor the tracks self.features = {} self._r...
set the data and build the vispy arrays for display
data
python
napari/napari
src/napari/layers/tracks/tracks.py
https://github.com/napari/napari/blob/master/src/napari/layers/tracks/tracks.py
BSD-3-Clause
def color_by(self, color_by: str) -> None: """set the property to color vertices by""" if color_by not in self.properties_to_color_by: raise ValueError( trans._( '{color_by} is not a valid property key', deferred=True, ...
set the property to color vertices by
color_by
python
napari/napari
src/napari/layers/tracks/tracks.py
https://github.com/napari/napari/blob/master/src/napari/layers/tracks/tracks.py
BSD-3-Clause