forked from CellProfiler/CellProfiler-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
157 lines (104 loc) · 3.88 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Something in CellProfiler is importing wx before we can set
# headless mode. Setting headless here efore importing anything
# else from CellProfiler.
import cellprofiler.preferences
cellprofiler.preferences.set_headless()
import cellprofiler.image
import cellprofiler.measurement
import cellprofiler.object
import cellprofiler.pipeline
import cellprofiler.workspace
import numpy
import skimage.data
import skimage.color
import skimage.filters
import skimage.measure
import pytest
@pytest.fixture(
scope="module",
params=[
(skimage.data.camera()[0:128, 0:128], 2),
(skimage.data.astronaut()[0:128, 0:128, :], 2),
(numpy.tile(skimage.data.camera()[0:32, 0:32], (2, 1)).reshape(2, 32, 32), 3)
],
ids=[
"grayscale_image",
"multichannel_image",
"grayscale_volume"
]
)
def image(request):
data, dimensions = request.param
return cellprofiler.image.Image(image=data, dimensions=dimensions)
@pytest.fixture(scope="function")
def image_empty():
image = cellprofiler.image.Image()
return image
@pytest.fixture(scope="function")
def image_set(image, image_set_list):
image_set = image_set_list.get_image_set(0)
image_set.add("example", image)
return image_set
@pytest.fixture(scope="function")
def image_set_empty(image_empty, image_set_list):
image_set = image_set_list.get_image_set(0)
image_set.add("example", image_empty)
return image_set
@pytest.fixture(scope="function")
def image_set_list():
return cellprofiler.image.ImageSetList()
@pytest.fixture(scope="function")
def measurements():
return cellprofiler.measurement.Measurements()
@pytest.fixture(scope="function")
def module(request):
instance = getattr(request.module, "instance")
return instance()
@pytest.fixture(scope="function")
def objects(image):
obj = cellprofiler.object.Objects()
obj.parent_image = image
return obj
@pytest.fixture(scope="function")
def objects_empty():
obj = cellprofiler.object.Objects()
return obj
@pytest.fixture(scope="function")
def object_set(objects):
objects_set = cellprofiler.object.ObjectSet()
objects_set.add_objects(objects, "InputObjects")
return objects_set
@pytest.fixture(scope="function")
def object_set_empty(objects_empty):
objects_set = cellprofiler.object.ObjectSet()
objects_set.add_objects(objects_empty, "InputObjects")
return objects_set
@pytest.fixture(scope="function")
def object_with_data(image):
data = image.pixel_data
if image.multichannel:
data = skimage.color.rgb2gray(data)
binary = data > skimage.filters.threshold_li(data)
labels = skimage.measure.label(binary)
objects = cellprofiler.object.Objects()
objects.segmented = labels
objects.parent_image = image
return objects
@pytest.fixture(scope="function")
def object_set_with_data(object_with_data):
objects_set = cellprofiler.object.ObjectSet()
objects_set.add_objects(object_with_data, "InputObjects")
return objects_set
@pytest.fixture(scope="function")
def pipeline():
return cellprofiler.pipeline.Pipeline()
@pytest.fixture(scope="function")
def workspace(pipeline, module, image_set, object_set, measurements, image_set_list):
return cellprofiler.workspace.Workspace(pipeline, module, image_set, object_set, measurements, image_set_list)
@pytest.fixture(scope="function")
def workspace_empty(pipeline, module, image_set_empty, object_set_empty, measurements, image_set_list):
return cellprofiler.workspace.Workspace(pipeline, module, image_set_empty, object_set_empty, measurements, image_set_list)
@pytest.fixture(scope="function")
def workspace_with_data(pipeline, module, image_set, object_set_with_data, measurements, image_set_list):
return cellprofiler.workspace.Workspace(pipeline, module, image_set, object_set_with_data,
measurements, image_set_list)