zarpaint 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
zarpaint/__init__.py ADDED
@@ -0,0 +1,22 @@
1
+ try:
2
+ from ._version import version as __version__
3
+ except ImportError:
4
+ __version__ = "unknown"
5
+
6
+ from ._zarpaint import create_labels, open_zarr
7
+ from ._dims_chooser import DimsSorter, set_axis_labels
8
+ from ._watershed import watershed_split
9
+ from ._add_3d_points import add_points_3d_with_alt_click
10
+ from .reader import zarr_tensorstore
11
+ from ._copy_data import copy_data
12
+
13
+ __all__ = [
14
+ 'create_labels',
15
+ 'open_zarr',
16
+ 'DimsSorter',
17
+ 'set_axis_labels',
18
+ 'watershed_split',
19
+ 'add_points_3d_with_alt_click',
20
+ 'zarr_tensorstore'
21
+ 'copy_data',
22
+ ]
@@ -0,0 +1,104 @@
1
+ import magicgui
2
+ import napari
3
+ import numpy as np
4
+
5
+
6
+ def get_ray_coordinates(shape, start_point, end_point):
7
+ length = np.linalg.norm(end_point - start_point)
8
+ length_int = np.round(length).astype(int)
9
+ coords = np.linspace(start_point, end_point, length_int + 1, endpoint=True)
10
+ clipped_coords = np.clip(np.round(coords), 0,
11
+ np.asarray(shape) - 1).astype(int)
12
+ return clipped_coords
13
+
14
+
15
+ def get_data_ray(data, start_point, end_point):
16
+ """Coordinate of the first nonzero element between start and end points.
17
+
18
+ Parameters
19
+ ----------
20
+ data : nD array, shape (N1, N2, ..., ND)
21
+ A data volume.
22
+ start_point : array, shape (D,)
23
+ The start coordinate to check.
24
+ end_point : array, shape (D,)
25
+ The end coordinate to check.
26
+
27
+ Returns
28
+ -------
29
+ coords : array, shape (M, D), where M = norm(end_point - start_point)
30
+ The integer coordinates of each point of the ray.
31
+ ray : array, shape (M,),
32
+ The data at ``coords``.
33
+ """
34
+ clipped_coords = get_ray_coordinates(data.shape, start_point, end_point)
35
+ ray = data[tuple(clipped_coords.T)]
36
+ return clipped_coords, ray
37
+
38
+
39
+ def find_midpoint_of_first_segment(layer, dims, event):
40
+ """Return the world coordinate of a Labels layer mouse event in 2D or 3D.
41
+
42
+ In 2D, this is just the event's position.
43
+
44
+ In 3D, a ray is cast in data coordinates, and the midpoint coordinate of
45
+ the first nonzero blob along that ray is returned, after being transformed
46
+ back to world coordinates. If the ray only contains zeros, None is
47
+ returned.
48
+
49
+ Parameters
50
+ ----------
51
+ layer : napari.layers.Labels
52
+ The Labels layer.
53
+ event : vispy MouseEvent
54
+ The mouse event, containing position and view direction attributes.
55
+
56
+ Returns
57
+ -------
58
+ coordinates : array of int
59
+ The world coordinates for the mouse event.
60
+ """
61
+ ndim = len(dims.displayed)
62
+ if ndim == 2:
63
+ coordinates = event.position
64
+ else: # 3d
65
+ start, end = layer.get_ray_intersections(
66
+ position=event.position,
67
+ view_direction=event.view_direction,
68
+ dims_displayed=list(dims.displayed),
69
+ world=True,
70
+ )
71
+ coordinates, ray = get_data_ray(layer.data, start, end)
72
+ ray_padded = np.pad(
73
+ ray, pad_width=1, mode='constant', constant_values=0
74
+ )
75
+ diff_coords = np.flatnonzero(np.diff(ray_padded))
76
+ if len(diff_coords) > 1:
77
+ blob_start_end = coordinates[diff_coords[:2]]
78
+ blob_mid = np.mean(blob_start_end, axis=0)
79
+ data2world = layer._transforms[1:3].simplified
80
+ coordinates = data2world(blob_mid)
81
+ else:
82
+ coordinates = None
83
+ return coordinates
84
+
85
+
86
+ @magicgui.magic_factory
87
+ def add_points_3d_with_alt_click(
88
+ viewer: napari.Viewer,
89
+ labels: napari.layers.Labels,
90
+ points: napari.layers.Points,
91
+ ):
92
+ pts_world2data = points._transforms[1:3].simplified.inverse
93
+
94
+ @labels.mouse_drag_callbacks.append
95
+ def click_callback(layer, event):
96
+ if not (len(event.modifiers) == 1
97
+ and event.modifiers[0].name == 'Alt'):
98
+ return
99
+ world_click_coordinates = find_midpoint_of_first_segment(
100
+ layer, viewer.dims, event
101
+ )
102
+ if world_click_coordinates is not None:
103
+ pts_coordinates = pts_world2data(world_click_coordinates)
104
+ points.add(pts_coordinates)
zarpaint/_copy_data.py ADDED
@@ -0,0 +1,19 @@
1
+ from magicgui import magic_factory
2
+ from ._normalize import normalize_dtype
3
+
4
+
5
+ @magic_factory
6
+ def copy_data(
7
+ napari_viewer: 'napari.viewer.Viewer',
8
+ source_layer: 'napari.layers.Labels',
9
+ target_layer: 'napari.layers.Labels',
10
+ ):
11
+ src_data = source_layer.data
12
+ dst_data = target_layer.data
13
+
14
+ ndim_src = src_data.ndim
15
+ ndim_dst = dst_data.ndim
16
+ slice_ = napari_viewer.dims.current_step
17
+ slicing = slice_[:ndim_dst - ndim_src]
18
+ dst_data[slicing] = src_data.astype(normalize_dtype(target_layer.dtype))
19
+ target_layer.refresh()
@@ -0,0 +1,125 @@
1
+ from __future__ import annotations
2
+
3
+ from magicgui import magic_factory
4
+ import numpy as np
5
+ import napari
6
+ from qtpy.QtWidgets import QStyledItemDelegate
7
+ from qtpy.QtGui import QBrush
8
+ from napari.utils.events import SelectableEventedList
9
+ from qtpy.QtWidgets import QWidget, QHBoxLayout
10
+
11
+
12
+ class AxisModel:
13
+ """View of an axis within a dims model keeping track of axis names."""
14
+ def __init__(self, dims: napari.components.Dims, axis: int):
15
+ self.dims = dims
16
+ self.axis = axis
17
+
18
+ def __hash__(self):
19
+ return id(self)
20
+
21
+ def __str__(self) -> str:
22
+ return repr(self)
23
+
24
+ def __repr__(self) -> str:
25
+ return self.dims.axis_labels[self.axis]
26
+
27
+ def __eq__(self, other: int | str):
28
+ if isinstance(other, int):
29
+ return self.axis == other
30
+ else:
31
+ return repr(self) == other
32
+
33
+
34
+ # this class is currently unused — needed to paint visible dims differently
35
+ class DimsDelegate(QStyledItemDelegate):
36
+ def paint(self, painter, option, index):
37
+ if index.row() > 3:
38
+ brush = QBrush()
39
+ brush.setColor('red')
40
+ option.backgroundBrush = brush
41
+ super().paint(painter, option, index)
42
+
43
+
44
+ def set_dims_order(dims, order):
45
+ if type(order[0]) == AxisModel:
46
+ order = [a.axis for a in order]
47
+ dims.order = order
48
+
49
+
50
+ def _array_in_range(arr, low, high):
51
+ return (arr >= low) & (arr < high)
52
+
53
+
54
+ def move_indices(axes_list, order):
55
+ with axes_list.events.blocker_all():
56
+ axes = [a.axis for a in axes_list]
57
+ if tuple(axes_list) == tuple(order):
58
+ return
59
+ ax_to_existing_position = {a: ix for ix, a in enumerate(axes)}
60
+ move_list = np.asarray([(ax_to_existing_position[order[i]], i)
61
+ for i in range(len(order))])
62
+ for src, dst in move_list:
63
+ axes_list.move(src, dst)
64
+ move_list[_array_in_range(move_list[:, 0], dst, src)] += 1
65
+ # remove the elements from the back if order has changed length
66
+ while len(axes_list) > len(order):
67
+ axes_list.pop()
68
+
69
+
70
+ class DimsSorter(QWidget):
71
+ def __init__(self, napari_viewer: 'napari.viewer.Viewer', parent=None):
72
+ super().__init__(parent=parent)
73
+ from napari._qt.containers import QtListView
74
+ dims = napari_viewer.dims
75
+ root = SelectableEventedList([
76
+ AxisModel(dims, i) for i in range(dims.ndim)
77
+ ])
78
+ root.events.reordered.connect(
79
+ lambda event, dims=dims: set_dims_order(dims, event.value)
80
+ )
81
+ dims.events.order.connect(
82
+ lambda event, axes_list=root:
83
+ move_indices(axes_list, event.value)
84
+ )
85
+ view = QtListView(root)
86
+ self.axes_list = root
87
+ self.setLayout(QHBoxLayout())
88
+ self.layout().addWidget(view)
89
+
90
+
91
+ @magic_factory(
92
+ call_button='set axis labels',
93
+ viewer={'visible': False},
94
+ )
95
+ def set_axis_labels(viewer: napari.Viewer, axes=''):
96
+ if type(axes) == str and len(axes) == viewer.dims.ndim:
97
+ viewer.dims.axis_labels = list(axes)
98
+
99
+
100
+ if __name__ == '__main__':
101
+ from napari._qt.containers import QtListView
102
+ from napari.components import Dims
103
+
104
+ dims = Dims(ndim=5, ndisplay=2, last_used=0, axis_labels=list('tzcyx'))
105
+ # create a python model
106
+ root = SelectableEventedList([AxisModel(dims, i) for i in range(5)])
107
+ root.events.reordered.connect(
108
+ lambda event, dims=dims: set_dims_order(dims, event.value)
109
+ )
110
+ # note: we don't yet handle expanding the order
111
+ dims.events.order.connect(
112
+ lambda event, axes_list=root: move_indices(axes_list, event.value)
113
+ )
114
+
115
+ # create Qt views onto the python models
116
+ view = QtListView(root)
117
+
118
+ w = QWidget()
119
+ w.setLayout(QHBoxLayout())
120
+ w.layout().addWidget(view)
121
+ w.show()
122
+
123
+ dims.order = (4, 3, 1, 0, 2) # xyztc
124
+
125
+ napari.run()
zarpaint/_main.py ADDED
@@ -0,0 +1,39 @@
1
+ import argparse
2
+ import ast
3
+ import sys
4
+
5
+ from ._zarpaint import correct_labels
6
+
7
+ parser = argparse.ArgumentParser(
8
+ 'zarpaint',
9
+ description='Paint segmentations directly to '
10
+ 'on-disk/remote zarr arrays',
11
+ )
12
+ parser.add_argument('image', help='The input image file.')
13
+ parser.add_argument('labels', help='The labels file (read/write).')
14
+ parser.add_argument('--frame', type=int, help='Load only this frame.')
15
+ parser.add_argument(
16
+ '-s',
17
+ '--scale',
18
+ type=ast.literal_eval,
19
+ default=(4, 1, 1),
20
+ help='Scale factors.',
21
+ )
22
+ parser.add_argument(
23
+ '-c',
24
+ '--channel',
25
+ type=int,
26
+ default=2,
27
+ help='Which channel to load.',
28
+ )
29
+
30
+
31
+ def main():
32
+ args = parser.parse_args(sys.argv[1:])
33
+ correct_labels(
34
+ args.image,
35
+ args.labels,
36
+ time_index=args.frame,
37
+ scale=args.scale,
38
+ c=args.channel,
39
+ )
zarpaint/_normalize.py ADDED
@@ -0,0 +1,80 @@
1
+ import numpy as np
2
+
3
+ _np_uints = {
4
+ 8: np.uint8,
5
+ 16: np.uint16,
6
+ 32: np.uint32,
7
+ 64: np.uint64,
8
+ }
9
+
10
+ _np_ints = {
11
+ 8: np.int8,
12
+ 16: np.int16,
13
+ 32: np.int32,
14
+ 64: np.int64,
15
+ }
16
+
17
+ _np_floats = {
18
+ 16: np.float16,
19
+ 32: np.float32,
20
+ 64: np.float64,
21
+ }
22
+
23
+ _np_complex = {
24
+ 64: np.complex64,
25
+ 128: np.complex128,
26
+ }
27
+
28
+ _np_kinds = {
29
+ 'uint': _np_uints,
30
+ 'int': _np_ints,
31
+ 'float': _np_floats,
32
+ 'complex': _np_complex,
33
+ }
34
+
35
+ def _normalize_str_by_bit_depth(dtype_str, kind):
36
+ if not any(str.isdigit(c) for c in dtype_str): # Python 'int' or 'float'
37
+ return np.dtype(kind).type
38
+ bit_dict = _np_kinds[kind]
39
+ if '128' in dtype_str:
40
+ return bit_dict[128]
41
+ if '8' in dtype_str:
42
+ return bit_dict[8]
43
+ if '16' in dtype_str:
44
+ return bit_dict[16]
45
+ if '32' in dtype_str:
46
+ return bit_dict[32]
47
+ if '64' in dtype_str:
48
+ return bit_dict[64]
49
+
50
+ def normalize_dtype(dtype_spec):
51
+ """Return a proper NumPy type given ~any duck array dtype.
52
+ Parameters
53
+ ----------
54
+ dtype_spec : numpy dtype, numpy type, torch dtype, tensorstore dtype, etc
55
+ A type that can be interpreted as a NumPy numeric data type, e.g.
56
+ 'uint32', np.uint8, torch.float32, etc.
57
+ Returns
58
+ -------
59
+ dtype : numpy.dtype
60
+ The corresponding dtype.
61
+ Notes
62
+ -----
63
+ half-precision floats are not supported.
64
+ """
65
+ dtype_str = str(dtype_spec)
66
+ if 'uint' in dtype_str:
67
+ return _normalize_str_by_bit_depth(dtype_str, 'uint')
68
+ if 'int' in dtype_str:
69
+ return _normalize_str_by_bit_depth(dtype_str, 'int')
70
+ if 'float' in dtype_str:
71
+ return _normalize_str_by_bit_depth(dtype_str, 'float')
72
+ if 'complex' in dtype_str:
73
+ return _normalize_str_by_bit_depth(dtype_str, 'complex')
74
+ if 'bool' in dtype_str:
75
+ return np.bool_
76
+ # If we don't find one of the named dtypes, return the dtype_spec
77
+ # unchanged. This allows NumPy big endian types to work. See
78
+ # https://github.com/napari/napari/issues/3421
79
+ else:
80
+ return dtype_spec
@@ -0,0 +1,13 @@
1
+ import numpy as np
2
+
3
+
4
+ def slice_points(points_layer, dims, ndim):
5
+ tf = points_layer._transforms[1:3].simplified.inverse
6
+ steps = tf.scale[:-ndim] * np.array(dims.range)[:-ndim, 2]
7
+ pt = tf(np.array(dims.point))[:-ndim]
8
+ data = points_layer.data
9
+ sel = np.ones(data.shape[0], dtype=bool)
10
+ for i, (p, st) in enumerate(zip(pt, steps)):
11
+ sel &= p - st/2 <= data[:, i]
12
+ sel &= data[:, i] < p + st/2
13
+ return data[sel]
File without changes
@@ -0,0 +1,44 @@
1
+ from zarpaint import copy_data
2
+ import numpy as np
3
+ from zarpaint import open_zarr
4
+ import zarr
5
+
6
+ def test_copy_data(make_napari_viewer):
7
+ viewer = make_napari_viewer()
8
+ labels_layer1 = viewer.add_labels(np.random.randint(0, 2**23, size=(10, 20, 30)))
9
+ labels_layer2 = viewer.add_labels(np.zeros((2, 10, 20, 30), dtype=int))
10
+ viewer.dims.set_point(axis=0, value=1)
11
+ widget = copy_data()
12
+ widget(viewer, labels_layer1, labels_layer2)
13
+ np.testing.assert_array_equal(labels_layer2.data[0], 0)
14
+ np.testing.assert_array_equal(labels_layer2.data[1], labels_layer1.data)
15
+
16
+
17
+ def test_copy_data_tensorstore(make_napari_viewer, tmp_path):
18
+ viewer = make_napari_viewer()
19
+ labels_layer1 = viewer.add_labels(np.random.randint(0, 2**23, size=(10, 20, 30)))
20
+ array2 = open_zarr(tmp_path / "example.zarr", shape=(2, 10, 20, 30), chunks=(1, 1, 20, 30))
21
+ labels_layer2 = viewer.add_labels(array2)
22
+ viewer.dims.set_point(axis=0, value=1)
23
+ widget = copy_data()
24
+ widget(viewer, labels_layer1, labels_layer2)
25
+ np.testing.assert_array_equal(labels_layer2.data[0], 0)
26
+ np.testing.assert_array_equal(labels_layer2.data[1], labels_layer1.data)
27
+
28
+
29
+ def test_copy_data_zarr(make_napari_viewer, tmp_path):
30
+ viewer = make_napari_viewer()
31
+ labels_layer1 = viewer.add_labels(np.random.randint(0, 2**23, size=(10, 20, 30)))
32
+ array2 = zarr.open(
33
+ str(tmp_path/"example.zarr"),
34
+ mode='w',
35
+ shape=(2, 10, 20, 30),
36
+ dtype=np.uint32,
37
+ chunks=(1, 1, 20, 30),
38
+ )
39
+ labels_layer2 = viewer.add_labels(array2)
40
+ viewer.dims.set_point(axis=0, value=1)
41
+ widget = copy_data()
42
+ widget(viewer, labels_layer1, labels_layer2)
43
+ np.testing.assert_array_equal(labels_layer2.data[0], 0)
44
+ np.testing.assert_array_equal(labels_layer2.data[1], labels_layer1.data)
@@ -0,0 +1,66 @@
1
+ import os
2
+ import tempfile
3
+ import napari
4
+ import numpy as np
5
+ from numpy.testing import assert_array_equal
6
+ from zarpaint import create_labels, DimsSorter
7
+ from zarpaint.reader import zarr_tensorstore
8
+
9
+
10
+ def test_create_labels():
11
+ image = napari.layers.Image(
12
+ np.random.random((10, 512, 512)),
13
+ name='img',
14
+ scale=[4, 1, 1],
15
+ translate=[1000, -1000, -2000],
16
+ )
17
+ create_labels_ = create_labels() # instance from magic_factory
18
+ with tempfile.TemporaryDirectory() as tmpdir:
19
+ pth = os.path.join(tmpdir, 'labels.zarr')
20
+ arr, meta, layer_type = create_labels_(image, pth, str((1, 128, 128)))
21
+ # note that arr.shape is an array if arr is tensorstore.Array
22
+ assert tuple(arr.shape) == image.data.shape
23
+ for key, val in meta.items():
24
+ assert_array_equal(getattr(image, key), val)
25
+ assert layer_type == 'labels'
26
+ assert os.path.exists(pth)
27
+ assert len(os.listdir(pth)) == 2 # .zarray, .naparimeta.yml
28
+ arr[4, :256, :256] = 1 # touch 4 chunks
29
+ assert len(os.listdir(pth)) == 6
30
+
31
+
32
+ def test_dims_sorter(make_napari_viewer):
33
+ viewer = make_napari_viewer(strict_qt=False)
34
+ ndim = 5
35
+ viewer.add_points(np.random.random((10, ndim)) * 512)
36
+ sorter = DimsSorter(viewer)
37
+ new_order = (1, 0, 2, 3, 4)
38
+ viewer.dims.order = new_order
39
+ assert [sorter.axes_list[i].axis for i in range(ndim)] == list(new_order)
40
+ assert sorter.axes_list[0].dims is viewer.dims
41
+ sorter.axes_list.move(4, 3)
42
+ assert viewer.dims.order == (1, 0, 2, 4, 3)
43
+
44
+
45
+ def test_open_tensorstore():
46
+ image = napari.layers.Image(
47
+ np.random.random((10, 512, 512)),
48
+ name='img',
49
+ scale=[4, 1, 1],
50
+ translate=[1000, -1000, -2000],
51
+ )
52
+ create_labels_ = create_labels() # instance from magic_factory
53
+ with tempfile.TemporaryDirectory() as tmpdir:
54
+ pth = os.path.join(tmpdir, 'labels.zarr')
55
+ _ = create_labels_(image, pth, str((1, 128, 128)))
56
+ # note that arr.shape is an array if arr is tensorstore.Array
57
+ reader = zarr_tensorstore(pth)
58
+ arr, meta, layer_type = reader(pth)[0] # 1st element of layer list
59
+ assert tuple(arr.shape) == image.data.shape
60
+ for key, val in meta.items():
61
+ assert_array_equal(getattr(image, key), val)
62
+ assert layer_type == 'labels'
63
+ assert os.path.exists(pth)
64
+ assert len(os.listdir(pth)) == 2 # .zarray, .naparimeta.yml
65
+ arr[4, :256, :256] = 2 # touch 4 chunks
66
+ assert len(os.listdir(pth)) == 6
@@ -0,0 +1,40 @@
1
+ from typing import List, Tuple
2
+ from zarpaint.reader import zarr_tensorstore
3
+ import zarr
4
+ import numpy as np
5
+
6
+ def test_reader_pass(tmp_path):
7
+ """
8
+ Test that the reader is able to open a test file
9
+ """
10
+ new_path = tmp_path / "example.test"
11
+ test_file = zarr_tensorstore(new_path)
12
+ assert test_file is None
13
+
14
+ def test_reader_return_callable(tmp_path):
15
+ """
16
+ Test the the reader returns a valid funciton when opening a file
17
+ """
18
+ example_zarr_folder = tmp_path / 'example.zarr'
19
+ z1 = zarr.open_array(example_zarr_folder, mode='w', shape=(10000, 10000), chunks=(1000, 1000), dtype='i4', fill_value=0)
20
+ res = zarr_tensorstore(example_zarr_folder)
21
+ assert callable(res)
22
+
23
+ def test_reader_can_read_and_write_to_file(tmp_path):
24
+ """
25
+ Creates a zarr file, writes random data to it, then saves the file. Once saved, the file is then
26
+ reopened and the data is compared.
27
+ """
28
+ example_zarr_folder = tmp_path / 'example.zarr'
29
+ z1 = zarr.open_array(example_zarr_folder, mode='w', shape=(100, 100), chunks=(100, 100))
30
+ z1[:] = np.random.rand(100, 100)
31
+
32
+ reader_func = zarr_tensorstore(example_zarr_folder)
33
+
34
+ layers = reader_func(example_zarr_folder)
35
+ assert isinstance(layers, List)
36
+ assert len(layers) == 1
37
+
38
+ layer_info = layers[0]
39
+ assert isinstance(layer_info, Tuple)
40
+ np.testing.assert_allclose(np.asarray(layer_info[0]), z1)
@@ -0,0 +1,89 @@
1
+ import napari
2
+ import numpy as np
3
+ from zarpaint import watershed_split
4
+ from skimage.data import binary_blobs
5
+
6
+
7
+ def test_watershed_split_2d(make_napari_viewer):
8
+ data = np.zeros(shape=(18, 18), dtype="uint8")
9
+ # create 2 squares with one corner overlapping
10
+ data[1:10, 1:10] = 1
11
+ data[8:17, 8:17] = 1
12
+ print(data)
13
+
14
+ # palce points in the centre of the 2 squares
15
+ points = np.asarray([[5, 5], [12, 12]])
16
+
17
+ expected = np.asarray([
18
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
19
+ [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0],
20
+ [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0],
21
+ [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0],
22
+ [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0],
23
+ [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0],
24
+ [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0],
25
+ [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0],
26
+ [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 0],
27
+ [0, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 0],
28
+ [0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
29
+ [0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
30
+ [0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
31
+ [0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
32
+ [0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
33
+ [0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
34
+ [0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
35
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
36
+ ],
37
+ dtype="uint8")
38
+
39
+ viewer = make_napari_viewer()
40
+ viewer.add_labels(data)
41
+ viewer.add_points(points)
42
+ watershed_widget = watershed_split()
43
+ watershed_widget(viewer, viewer.layers[0], viewer.layers[1])
44
+ np.testing.assert_allclose(viewer.layers[0].data, expected)
45
+
46
+
47
+ def test_watershed_split_3d(make_napari_viewer):
48
+ data = np.zeros(shape=(9, 9, 9), dtype="uint8")
49
+ data[4:, 4:, 4:] = 1
50
+ data[:5, :5, :5] = 1
51
+ viewer = make_napari_viewer()
52
+ viewer.add_labels(data)
53
+
54
+ points = np.asarray([[4, 2, 2], [4, 6, 6]])
55
+
56
+ viewer.add_points(points)
57
+
58
+ watershed_widget = watershed_split()
59
+ watershed_widget(viewer, viewer.layers[0], viewer.layers[1])
60
+
61
+ assert np.all(data[:5, :5, :5] == 2)
62
+ assert np.all(data[5:, 5:, 5:] == 3)
63
+
64
+
65
+ def test_watershed_split_3d_with_blobs(make_napari_viewer):
66
+ from scipy import ndimage as ndi
67
+ blobs = binary_blobs(
68
+ length=128,
69
+ blob_size_fraction=0.1,
70
+ n_dim=3,
71
+ volume_fraction=0.1,
72
+ seed=0
73
+ )
74
+ labeled_blobs = ndi.label(blobs)[0]
75
+ viewer = make_napari_viewer()
76
+ viewer.add_labels(labeled_blobs)
77
+
78
+ points = np.asarray([[27, 6, 57], [25, 5, 72]])
79
+
80
+ viewer.add_points(points)
81
+
82
+ assert labeled_blobs[27, 6, 57] == 84
83
+ assert labeled_blobs[25, 5, 72] == 84
84
+
85
+ watershed_widget = watershed_split()
86
+ watershed_widget(viewer, viewer.layers[0], viewer.layers[1])
87
+
88
+ assert labeled_blobs[27, 6, 57] == 349
89
+ assert labeled_blobs[25, 5, 72] == 350
@@ -0,0 +1,139 @@
1
+ from zarpaint._add_3d_points import get_ray_coordinates, get_data_ray, find_midpoint_of_first_segment, add_points_3d_with_alt_click
2
+ import numpy as np
3
+ from napari.layers import Labels
4
+
5
+ from vispy.util.keys import ALT
6
+
7
+
8
+ class MockMouseEvent():
9
+ def __init__(self, position, view_direction) -> None:
10
+ self.position = position
11
+ self.view_direction = view_direction
12
+
13
+
14
+ def test_get_data_ray():
15
+ shape = (3, 3, 3)
16
+ data = np.linspace(1, 27, 27).reshape(shape)
17
+
18
+ start = np.asarray((0, 0, 0))
19
+ end = np.asarray((2, 2, 2))
20
+ ray = get_data_ray(data, start, end)[1]
21
+
22
+ expected = np.asarray([1., 14., 14., 27.])
23
+ np.testing.assert_allclose(ray, expected)
24
+
25
+
26
+ def test_get_ray_coordinates():
27
+ shape = (3, 3, 3)
28
+ start = np.asarray((0, 0, 0))
29
+ end = np.asarray((2, 2, 2))
30
+ test_coords = np.asarray([[0, 0, 0], [1, 1, 1], [1, 1, 1], [2, 2, 2]])
31
+ coords = get_ray_coordinates(shape, start, end)
32
+ np.testing.assert_allclose(coords, test_coords)
33
+
34
+ end = np.asarray((0, 2, 0))
35
+ test_coords = np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0]])
36
+ coords = get_ray_coordinates(shape, start, end)
37
+ np.testing.assert_allclose(coords, test_coords)
38
+
39
+ # Testing when end point is "out of bounds"
40
+ end = np.asarray((4, 4, 4))
41
+ test_coords = np.array([[0, 0, 0], [1, 1, 1], [1, 1, 1], [2, 2, 2],
42
+ [2, 2, 2], [2, 2, 2], [2, 2, 2], [2, 2, 2]])
43
+ coords = get_ray_coordinates(shape, start, end)
44
+ np.testing.assert_allclose(coords, test_coords)
45
+
46
+
47
+ def test_midpoint_2d_empty_ray(make_napari_viewer):
48
+ viewer = make_napari_viewer()
49
+ dims = viewer.dims
50
+
51
+ mock_data = np.zeros(shape=(5, 5), dtype="uint8")
52
+ layer_data = Labels(mock_data)
53
+ viewer.add_layer(layer_data)
54
+
55
+ position = (0, 0)
56
+ view_direction = [1, 0]
57
+ mouse_event = MockMouseEvent(position, view_direction)
58
+
59
+ result = find_midpoint_of_first_segment(layer_data, dims, mouse_event)
60
+ assert result == (0, 0)
61
+
62
+
63
+ def test_midpoint_2d_nonempty_ray(make_napari_viewer):
64
+ viewer = make_napari_viewer()
65
+ dims = viewer.dims
66
+
67
+ mock_data = np.ones(shape=(5, 5), dtype="uint8")
68
+ layer_data = Labels(mock_data)
69
+ viewer.add_layer(layer_data)
70
+
71
+ position = (3, 0)
72
+ view_direction = [1, 0]
73
+ mouse_event = MockMouseEvent(position, view_direction)
74
+
75
+ result = find_midpoint_of_first_segment(layer_data, dims, mouse_event)
76
+ assert result == (3, 0)
77
+
78
+
79
+ def test_midpoint_3d_empty_ray(make_napari_viewer):
80
+ viewer = make_napari_viewer()
81
+ viewer.dims.ndisplay = 3
82
+ dims = viewer.dims
83
+
84
+ mock_data = np.zeros(shape=(5, 5, 5), dtype="uint8")
85
+ layer_data = Labels(mock_data)
86
+ mouse_event = MockMouseEvent((2, 2, 0), [1, 0, 0])
87
+
88
+ viewer.add_layer(layer_data)
89
+
90
+ result = find_midpoint_of_first_segment(layer_data, dims, mouse_event)
91
+ assert result is None
92
+
93
+ mock_data[1:4, 1:4, 1:4] = 1
94
+ layer_data = Labels(mock_data)
95
+ mouse_event = MockMouseEvent((2, 2, 0), [1, 0, 0])
96
+
97
+ viewer.add_layer(layer_data)
98
+
99
+ result = find_midpoint_of_first_segment(layer_data, dims, mouse_event)
100
+ assert result is None
101
+
102
+
103
+ def test_midpoint_3d_nonempty_ray(make_napari_viewer):
104
+ viewer = make_napari_viewer()
105
+ viewer.dims.ndisplay = 3
106
+ dims = viewer.dims
107
+
108
+ mock_data = np.zeros(shape=(5, 5, 5), dtype="uint8")
109
+ mock_data[1:4, 1:4, 1:4] = 1
110
+ layer_data = Labels(mock_data)
111
+ viewer.add_layer(layer_data)
112
+
113
+ mouse_event = MockMouseEvent((2, 2, 0), [0, 1, 1])
114
+ result = find_midpoint_of_first_segment(layer_data, dims, mouse_event)
115
+ np.testing.assert_allclose(result, [2., 3.5, 1.5])
116
+
117
+
118
+ def test_add_point_3d_alt_click(make_napari_viewer):
119
+ viewer = make_napari_viewer()
120
+ viewer.dims.ndisplay = 3
121
+
122
+ mock_data = np.zeros(shape=(5, 5, 5), dtype="uint8")
123
+ mock_data[1:4, 1:4, 1:4] = 1
124
+ label_layer = Labels(mock_data)
125
+ viewer.add_layer(label_layer)
126
+
127
+ points_layer = viewer.add_points([], ndim=3)
128
+ viewer.layers.selection.active = label_layer
129
+
130
+ point_widget = add_points_3d_with_alt_click()
131
+ point_widget(viewer, label_layer, points_layer)
132
+
133
+ view = viewer.window._qt_viewer
134
+ click_coordinates = (view.canvas.size[0] / 2, view.canvas.size[1] / 2, 0)
135
+ view.canvas.events.mouse_press(
136
+ pos=click_coordinates, modifiers=(ALT,), button=0
137
+ )
138
+
139
+ assert len(points_layer.data)
zarpaint/_version.py ADDED
@@ -0,0 +1,16 @@
1
+ # file generated by setuptools_scm
2
+ # don't change, don't track in version control
3
+ TYPE_CHECKING = False
4
+ if TYPE_CHECKING:
5
+ from typing import Tuple, Union
6
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
7
+ else:
8
+ VERSION_TUPLE = object
9
+
10
+ version: str
11
+ __version__: str
12
+ __version_tuple__: VERSION_TUPLE
13
+ version_tuple: VERSION_TUPLE
14
+
15
+ __version__ = version = '0.3.0'
16
+ __version_tuple__ = version_tuple = (0, 3, 0)
zarpaint/_watershed.py ADDED
@@ -0,0 +1,89 @@
1
+ import numpy as np
2
+ from scipy import ndimage as ndi
3
+ from magicgui import magic_factory
4
+ from skimage.morphology import octahedron
5
+ from skimage.segmentation import watershed
6
+ from ._points_util import slice_points
7
+ from skimage import util
8
+
9
+
10
+ @magic_factory(
11
+ call_button='Split',
12
+ viewer={'visible': False},
13
+ ndim={'min': 2, 'max': 3},
14
+ )
15
+ def watershed_split(
16
+ viewer: 'napari.viewer.Viewer',
17
+ labels: 'napari.layers.Labels',
18
+ points: 'napari.layers.Points',
19
+ ndim: int = 3,
20
+ ):
21
+ """Execute watershed to split labels based on provided points.
22
+
23
+ Only labels containing points will be modified. The operation will be
24
+ performed in-place on the input Labels layer.
25
+
26
+ Parameters
27
+ ----------
28
+ viewer : napari.Viewer
29
+ The current viewer displaying the data.
30
+ labels : napari Labels layer
31
+ The layer containing the segmentation. This will be used both for
32
+ input and output.
33
+ points : napari Points layer
34
+ The points marking the labels to be split.
35
+ ndim : int in {2, 3}
36
+ The number of dimensions for the watershed operation.
37
+ """
38
+ coord = viewer.dims.current_step
39
+ slice_idx = coord[:-ndim]
40
+
41
+ # find the labels corresponding to the current points in the points layer
42
+ labels_sliced = np.asarray(labels.data[slice_idx])
43
+ points_sliced = slice_points(points, viewer.dims, ndim)
44
+ points_data_to_world = points._transforms[1:3].simplified
45
+ labels_world_to_data = labels._transforms[1:3].simplified.inverse
46
+ points_transformed = labels_world_to_data(
47
+ points_data_to_world(points_sliced)
48
+ ).astype(int)[:, -ndim:]
49
+ image = np.ones_like(labels_sliced, dtype=np.uint8)
50
+ labels_split = _watershed_split(
51
+ image,
52
+ labels_sliced,
53
+ points_transformed,
54
+ compactness=200,
55
+ connectivity_octahedron=7,
56
+ )
57
+ labels.data[slice_idx] = labels_split
58
+ points.data = np.empty((0, viewer.dims.ndim), dtype=float)
59
+ labels.refresh()
60
+
61
+
62
+ def _watershed_split(
63
+ image, labels, points, compactness=200, connectivity_octahedron=7
64
+ ):
65
+ """
66
+ Split labels with using points as markers for watershed
67
+ """
68
+ points = np.round(points).astype(int)
69
+ coords = tuple([points[:, i] for i in range(points.shape[1])])
70
+ p_lab = labels[coords]
71
+ p_lab = np.unique(p_lab)
72
+ p_lab = p_lab[p_lab != 0]
73
+
74
+ # generate a mask corresponding to the labels that need to be split
75
+ mask = np.zeros(labels.shape, dtype=bool)
76
+ for lab in p_lab:
77
+ where = labels == lab
78
+ mask = mask + where
79
+
80
+ dt = ndi.distance_transform_edt(labels)
81
+ dt_inv = np.max(dt) - dt
82
+ watershed_seeds = util.label_points(points, labels.shape)
83
+
84
+ # the distance transform contains ridges at the touch points
85
+ separated_labels = watershed(
86
+ dt_inv, markers=watershed_seeds, mask=mask.astype(bool)
87
+ )
88
+ labels[mask] = separated_labels[mask] + labels.max()
89
+ return labels
zarpaint/_zarpaint.py ADDED
@@ -0,0 +1,166 @@
1
+ import ast
2
+ import os
3
+ import warnings
4
+ import yaml
5
+
6
+ from magicgui import magic_factory
7
+ import napari
8
+ import numpy as np
9
+ import pathlib
10
+ try:
11
+ import tensorstore as ts
12
+ tensorstore_available = True
13
+ except ModuleNotFoundError:
14
+ tensorstore_available = False
15
+ have_warned = False
16
+ import zarr
17
+ import toolz as tz
18
+
19
+
20
+ @tz.curry
21
+ def _set_default_labels_path(widget, source_image):
22
+ """Helper function to set the default output path next to source image.
23
+
24
+ When the widget to create a labels layer is instantiated, it asks for
25
+ a filename. This function sets the default to be next to the original
26
+ file.
27
+ """
28
+ if source_image.source.path is not None:
29
+ source_path = pathlib.Path(source_image.source.path)
30
+ labels_path = source_path.with_suffix('.labels.zarr')
31
+ widget.labels_file.value = labels_path
32
+
33
+
34
+ def _on_create_labels_init(widget):
35
+ """Ensure changes to the source image change the default labels path."""
36
+ widget.source_image.changed.connect(_set_default_labels_path(widget))
37
+
38
+
39
+ def create_ts_meta(labels_file: pathlib.Path, metadata):
40
+ """Create bespoke metadata yaml file within zarr array."""
41
+ fn = os.path.join(labels_file, '.naparimeta.yml')
42
+ with open(fn, 'w') as fout:
43
+ for key, val in metadata.items():
44
+ if type(val) == np.ndarray:
45
+ if np.issubdtype(val.dtype, np.floating):
46
+ metadata[key] = list(map(float, val))
47
+ else:
48
+ metadata[key] = list(map(int, val))
49
+ yaml.dump(metadata, fout)
50
+
51
+
52
+ def open_ts_meta(labels_file: pathlib.Path) -> dict:
53
+ """Open bespoke metadata yaml file within zarr array, if present."""
54
+ fn = os.path.join(labels_file, '.naparimeta.yml')
55
+ meta = {}
56
+ if os.path.exists(fn):
57
+ with open(fn, 'r') as fin:
58
+ meta = yaml.safe_load(fin)
59
+ return meta
60
+
61
+
62
+ def open_zarr(labels_file: pathlib.Path, *, shape=None, chunks=None):
63
+ """Open a zarr file, with tensorstore if available, with zarr otherwise.
64
+
65
+ If the file doesn't exist, it is created.
66
+
67
+ Parameters
68
+ ----------
69
+ labels_file : Path
70
+ The output file name.
71
+ shape : tuple of int
72
+ The shape of the array.
73
+ chunks : tuple of int
74
+ The chunk size of the array.
75
+
76
+ Returns
77
+ -------
78
+ data : ts.Array or zarr.Array
79
+ The array loaded from file.
80
+ """
81
+ if not os.path.exists(labels_file):
82
+ zarr.open(
83
+ str(labels_file),
84
+ mode='w',
85
+ shape=shape,
86
+ dtype=np.uint32,
87
+ chunks=chunks,
88
+ )
89
+ # read some of the metadata for tensorstore driver from file
90
+ labels_temp = zarr.open(str(labels_file), mode='a')
91
+ metadata = {
92
+ 'dtype': labels_temp.dtype.str,
93
+ 'order': labels_temp.order,
94
+ 'shape': labels_temp.shape,
95
+ }
96
+
97
+ dir, name = os.path.split(labels_file)
98
+ labels_ts_spec = {
99
+ 'driver': 'zarr',
100
+ 'kvstore': {'driver': 'file', 'path': dir},
101
+ 'path': name,
102
+ 'metadata': metadata,
103
+ }
104
+ if tensorstore_available:
105
+ data = ts.open(labels_ts_spec, create=False, open=True).result()
106
+ else:
107
+ global have_warned
108
+ if not have_warned:
109
+ warnings.warn(
110
+ 'tensorstore not available, falling back to zarr.\n'
111
+ 'Drawing with tensorstore is *much faster*. We recommend '
112
+ 'you install tensorstore with '
113
+ '`python -m pip install tensorstore`.'
114
+ )
115
+ have_warned = True
116
+ data = labels_temp
117
+ return data
118
+
119
+
120
+ @magic_factory(
121
+ labels_file={'mode': 'w'},
122
+ widget_init=_on_create_labels_init,
123
+ )
124
+ def create_labels(
125
+ source_image: napari.layers.Image,
126
+ labels_file: pathlib.Path,
127
+ chunks='',
128
+ ) -> napari.types.LayerDataTuple:
129
+ """Create/load a zarr array as a labels layer based on image layer.
130
+
131
+ Parameters
132
+ ----------
133
+ source_image : Image layer
134
+ The image that we are segmenting.
135
+ labels_file : pathlib.Path
136
+ The path to the zarr file to be created.
137
+ chunks : str, optional
138
+ A string that can be evaluated as a tuple of ints specifying the chunk
139
+ size for the zarr file. If empty, they will be (128, 128) along the
140
+ last dimensions and (1) along any remaining dimensions. This argument
141
+ has no effect if the file already exists.
142
+ """
143
+ if chunks:
144
+ chunks_str = chunks
145
+ chunks = ast.literal_eval(chunks)
146
+ if (type(chunks) is not tuple
147
+ or not all(isinstance(val, int) for val in chunks)):
148
+ raise ValueError(
149
+ 'chunks should be a tuple of ints, e.g. "(1, 1, 512, 512)", '
150
+ f'got {chunks_str}'
151
+ )
152
+ else: # use default
153
+ chunks = (1,) * (source_image.ndim - 2) + (128, 128)
154
+
155
+ layer_data = open_zarr(
156
+ labels_file,
157
+ shape=source_image.data.shape,
158
+ chunks=chunks,
159
+ )
160
+ layer_type = 'labels'
161
+ layer_metadata = {
162
+ 'scale': source_image.scale,
163
+ 'translate': source_image.translate,
164
+ }
165
+ create_ts_meta(labels_file, layer_metadata)
166
+ return layer_data, layer_metadata, layer_type
zarpaint/napari.yaml ADDED
@@ -0,0 +1,44 @@
1
+ name: zarpaint
2
+ schema_version: 0.1.0
3
+ contributions:
4
+ commands:
5
+ - id: zarpaint.add_points_3d_with_alt_click
6
+ title: Add Points With Alt-Click in 3D…
7
+ python_name: zarpaint:add_points_3d_with_alt_click
8
+ - id: zarpaint.set_axis_labels
9
+ title: Set Axis Labels…
10
+ python_name: zarpaint:set_axis_labels
11
+ - id: zarpaint.DimsSorter
12
+ title: Reorder Dimensions…
13
+ python_name: zarpaint:DimsSorter
14
+ - id: zarpaint.create_labels
15
+ title: Create Labels Layer…
16
+ python_name: zarpaint:create_labels
17
+ - id: zarpaint.watershed_split
18
+ title: Split With Watershed…
19
+ python_name: zarpaint:watershed_split
20
+ - id: zarpaint.get_reader
21
+ title: Get Reader
22
+ python_name: zarpaint:zarr_tensorstore
23
+ - id: zarpaint.copy_data
24
+ title: Copy Data…
25
+ python_name: zarpaint:copy_data
26
+
27
+ readers:
28
+ - command: zarpaint.get_reader
29
+ filename_patterns: ["*.zarr"]
30
+ accepts_directories: true
31
+
32
+ widgets:
33
+ - command: zarpaint.add_points_3d_with_alt_click
34
+ display_name: Add Points With Alt-Click in 3D
35
+ - command: zarpaint.set_axis_labels
36
+ display_name: Set Axis Labels
37
+ - command: zarpaint.DimsSorter
38
+ display_name: Reorder Dims
39
+ - command: zarpaint.create_labels
40
+ display_name: Create Labels Layer
41
+ - command: zarpaint.watershed_split
42
+ display_name: Split With Watershed
43
+ - command: zarpaint.copy_data
44
+ display_name: Copy Data
zarpaint/reader.py ADDED
@@ -0,0 +1,11 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import pathlib
5
+ from ._zarpaint import open_zarr, open_ts_meta
6
+
7
+
8
+ def zarr_tensorstore(path: str | pathlib.Path):
9
+ if (str(path).endswith('.zarr') and os.path.isdir(path)
10
+ and '.zarray' in os.listdir(path)):
11
+ return lambda p: [(open_zarr(p), open_ts_meta(path), 'labels')]
@@ -0,0 +1,28 @@
1
+
2
+ Copyright (c) 2021, Abigail McGovern and Juan Nunez-Iglesias
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ * Neither the name of zarpaint nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.1
2
+ Name: zarpaint
3
+ Version: 0.3.0
4
+ Summary: Paint segmentations directly to on-disk/remote zarr arrays
5
+ Home-page: https://github.com/jni/zarpaint
6
+ Author: Abigail McGovern and Juan Nunez-Iglesias
7
+ Author-email: juan.nunez-iglesias@monash.edu
8
+ License: BSD-3
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Framework :: napari
12
+ Classifier: Topic :: Software Development :: Testing
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.7
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: License :: OSI Approved :: BSD License
20
+ Requires-Python: >=3.7
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: magicgui
24
+ Requires-Dist: napari >=0.4.11.dev80
25
+ Requires-Dist: napari-plugin-engine >=0.1.4
26
+ Requires-Dist: numpy
27
+ Requires-Dist: pyyaml
28
+ Requires-Dist: qtpy
29
+ Requires-Dist: scipy
30
+ Requires-Dist: scikit-image
31
+ Requires-Dist: toolz
32
+ Requires-Dist: zarr
33
+ Provides-Extra: all
34
+ Requires-Dist: tensorstore ; extra == 'all'
35
+ Provides-Extra: testing
36
+ Requires-Dist: coverage ; extra == 'testing'
37
+ Requires-Dist: pytest ; extra == 'testing'
38
+ Requires-Dist: pytest-cov ; extra == 'testing'
39
+ Requires-Dist: pytest-qt ; extra == 'testing'
40
+ Requires-Dist: napari[pyqt5] ; extra == 'testing'
41
+
42
+ # zarpaint
43
+
44
+ [![License](https://img.shields.io/pypi/l/zarpaint.svg?color=green)](https://github.com/jni/zarpaint/raw/main/LICENSE)
45
+ [![PyPI](https://img.shields.io/pypi/v/zarpaint.svg?color=green)](https://pypi.org/project/zarpaint)
46
+ [![Python Version](https://img.shields.io/pypi/pyversions/zarpaint.svg?color=green)](https://python.org)
47
+ [![tests](https://github.com/jni/zarpaint/workflows/tests/badge.svg)](https://github.com/jni/zarpaint/actions)
48
+ [![codecov](https://codecov.io/gh/jni/zarpaint/branch/main/graph/badge.svg)](https://codecov.io/gh/jni/zarpaint)
49
+
50
+ Paint segmentations directly to on-disk/remote zarr arrays
51
+
52
+ ----------------------------------
53
+
54
+ This [napari] plugin was generated with [Cookiecutter] using with [@napari]'s [cookiecutter-napari-plugin] template.
55
+
56
+ <!--
57
+ Don't miss the full getting started guide to set up your new package:
58
+ https://github.com/napari/cookiecutter-napari-plugin#getting-started
59
+
60
+ and review the napari docs for plugin developers:
61
+ https://napari.org/docs/plugins/index.html
62
+ -->
63
+
64
+ ## Installation
65
+
66
+ You can install `zarpaint` via [pip]:
67
+
68
+ pip install zarpaint
69
+
70
+ ## Contributing
71
+
72
+ Contributions are very welcome. Tests can be run with [tox], please ensure
73
+ the coverage at least stays the same before you submit a pull request.
74
+
75
+ ## License
76
+
77
+ Distributed under the terms of the [BSD-3] license,
78
+ "zarpaint" is free and open source software
79
+
80
+ ## Issues
81
+
82
+ If you encounter any problems, please [file an issue] along with a detailed description.
83
+
84
+ [napari]: https://github.com/napari/napari
85
+ [Cookiecutter]: https://github.com/audreyr/cookiecutter
86
+ [@napari]: https://github.com/napari
87
+ [MIT]: http://opensource.org/licenses/MIT
88
+ [BSD-3]: http://opensource.org/licenses/BSD-3-Clause
89
+ [GNU GPL v3.0]: http://www.gnu.org/licenses/gpl-3.0.txt
90
+ [GNU LGPL v3.0]: http://www.gnu.org/licenses/lgpl-3.0.txt
91
+ [Apache Software License 2.0]: http://www.apache.org/licenses/LICENSE-2.0
92
+ [Mozilla Public License 2.0]: https://www.mozilla.org/media/MPL/2.0/index.txt
93
+ [cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin
94
+ [file an issue]: https://github.com/jni/zarpaint/issues
95
+ [napari]: https://github.com/napari/napari
96
+ [tox]: https://tox.readthedocs.io/en/latest/
97
+ [pip]: https://pypi.org/project/pip/
98
+ [PyPI]: https://pypi.org/
@@ -0,0 +1,24 @@
1
+ zarpaint/__init__.py,sha256=vNepZgZydgAwZpqeNndWeOy1wGcxDCCRTFgw1NQ5uK0,607
2
+ zarpaint/_add_3d_points.py,sha256=Z8OTI5ZVZvnZfAKg6d8OIOA4o9WL4E4pYMzBxoPQ_Zc,3532
3
+ zarpaint/_copy_data.py,sha256=b3NPxSFlXxC0wsjNdlpgtGTOi7gtGplQioCjaHv3EWE,574
4
+ zarpaint/_dims_chooser.py,sha256=auH4u5otV8_fI6ZtrLwNHYOMeBngoVkjbF4Q_1GqYio,3931
5
+ zarpaint/_main.py,sha256=2kJbYaWGnXWsOSsBKSuEJksX-gS-8VeoTCKD5o2OC9k,961
6
+ zarpaint/_normalize.py,sha256=9DHCy5E6aa71fk9RHXyifEqZ7rD15VSwyTIDptPVSU0,2071
7
+ zarpaint/_points_util.py,sha256=qdW1VctrjNwTPJpGcPXqRUcC7hzEcWLX750wbdy2IBQ,447
8
+ zarpaint/_version.py,sha256=Jk2iAU7m-7Vx9XV1TtdD9ZoJraIncDq_4_Wd-qtUotg,411
9
+ zarpaint/_watershed.py,sha256=BkTNpmBz5Da4U3FhYX8DFaH284VdrEEUG-55QAtbsu8,3024
10
+ zarpaint/_zarpaint.py,sha256=3trJogKtD7j2XxGXKbXcjochkCvUMyL0PTqkxp1Pp9k,5332
11
+ zarpaint/napari.yaml,sha256=al8kW97WP9i8eIzrSO1vEAYJ5-n5A0w_vvfQZS5o5Zk,1384
12
+ zarpaint/reader.py,sha256=jbxxUiNNICH3DJw7osGYgFN2MXsTrqTCxw8UkNGMjgM,342
13
+ zarpaint/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ zarpaint/_tests/test_copy_data.py,sha256=-7SJViirRi1TgJhihNY-lwKv5_Lz0_bh2NV5fi-X4RE,1866
15
+ zarpaint/_tests/test_dock_widget.py,sha256=gLyHOX1XTxGkk2in1-TR1qt-dXyEOjbBF3WhMDAM94A,2593
16
+ zarpaint/_tests/test_reader.py,sha256=0yCWkJmoIgn7MINZMjTP0KfX3wUjuALiV0CgFOrAO_A,1400
17
+ zarpaint/_tests/test_watershed.py,sha256=xs2bCNxLDsoOgJgi4MI1qQkfX2tjnSrpHoD3p2YNx48,3224
18
+ zarpaint/_tests/test_zarpaint.py,sha256=fMMB_UhsQ-Zt5dAhMqrMl2l-6KC253-vzJNeY0fy20A,4325
19
+ zarpaint-0.3.0.dist-info/LICENSE,sha256=ieWOHMyqInFIjHubwAEEuL12FSLZ1UDV6YAgzw6RS2o,1507
20
+ zarpaint-0.3.0.dist-info/METADATA,sha256=Tsb4nSL7fmsCCgHPGeeG_kdvwV8DpYuQEFclzkxCWG4,3708
21
+ zarpaint-0.3.0.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
22
+ zarpaint-0.3.0.dist-info/entry_points.txt,sha256=cmD2DBZtXB6-fLThFKjG4ADP6eTXanGH6Bcxp_Kk_C0,100
23
+ zarpaint-0.3.0.dist-info/top_level.txt,sha256=W_LMvUiJ9kf57eYItZu4rJjqZ_Fzsk6Or5gdqyNvygM,9
24
+ zarpaint-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.41.3)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,5 @@
1
+ [console_scripts]
2
+ zarpaint = zarpaint._main:main
3
+
4
+ [napari.manifest]
5
+ zarpaint = zarpaint:napari.yaml
@@ -0,0 +1 @@
1
+ zarpaint