Skip to content

Commit

Permalink
Refactor to newer CP5 API
Browse files Browse the repository at this point in the history
- update provider adding via new add_provider method
- activate readers manually
  • Loading branch information
gnodar01 committed Mar 20, 2024
1 parent b928c0b commit 9483a68
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Something in CellProfiler is importing wx before we can set
# headless mode. Setting headless here efore importing anything
# headless mode. Setting headless here before importing anything
# else from CellProfiler.
import cellprofiler_core.preferences

Expand All @@ -10,6 +10,7 @@
import cellprofiler_core.object
import cellprofiler_core.pipeline
import cellprofiler_core.workspace
import cellprofiler_core.reader
import numpy
import skimage.data
import skimage.color
Expand All @@ -18,6 +19,9 @@
import pytest


def pytest_sessionstart(session):
cellprofiler_core.reader.fill_readers(check_config=True)

@pytest.fixture(
scope="module",
params=[
Expand Down
4 changes: 4 additions & 0 deletions unmaintained_plugins/CellProfiler3/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cellprofiler.object
import cellprofiler.pipeline
import cellprofiler.workspace
import cellprofiler_core.reader
import numpy
import skimage.data
import skimage.color
Expand All @@ -18,6 +19,9 @@
import pytest


def pytest_sessionstart(session):
cellprofiler_core.reader.fill_readers(check_config=True)

@pytest.fixture(
scope="module",
params=[
Expand Down
36 changes: 18 additions & 18 deletions unmaintained_tests/test_identifyyeastcells.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_01_00_test_zero_objects(self):
image = cpi.Image(img, file_name="test_01_00_test_zero_objects")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_01_01_test_one_object(self):
image = cpi.Image(img, file_name="test_01_01_test_one_object")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_01_02_test_two_bright_objects(self):
image = cpi.Image(img, file_name="test_01_02_test_two_bright_objects")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_01_03_test_two_dark_objects(self):
image = cpi.Image(img, file_name="test_01_03_test_two_dark_objects")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_01_04_test_two_flu_bright_objects(self):
image = cpi.Image(img, file_name="test_01_04_test_two_flu_bright_objects")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -294,7 +294,7 @@ def test_01_05_test_two_flu_dark_objects(self):
image = cpi.Image(img, file_name="test_01_05_test_two_flu_dark_objects")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -336,7 +336,7 @@ def test_01_06_fill_holes(self):
image = cpi.Image(img, file_name="test_01_06_fill_holes")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand All @@ -359,7 +359,7 @@ def test_01_07_extreme_params(self):
image = cpi.Image(img, file_name="test_01_07_extreme_params")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -387,7 +387,7 @@ def test_02_01_discard_large(self):
image = cpi.Image(img, file_name="test_02_01_discard_large")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -418,7 +418,7 @@ def test_02_02_discard_small(self):
image = cpi.Image(img, file_name="test_02_02_discard_small")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -454,8 +454,8 @@ def test_02_03_use_background_image(self):

image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.providers.append(cpi.VanillaImageProvider(BACKGROUND_IMAGE_NAME, background))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(BACKGROUND_IMAGE_NAME, background))
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
Expand Down Expand Up @@ -487,8 +487,8 @@ def test_02_04_mask_input_image(self):
mask = cpi.Image(msk)
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.providers.append(cpi.VanillaImageProvider(MASK_IMAGE_NAME, mask))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(MASK_IMAGE_NAME, mask))

# first try without masking
object_set = cpo.ObjectSet()
Expand Down Expand Up @@ -548,7 +548,7 @@ def test_03_01_simple_fitting(self):
image = cpi.Image(img, file_name="test_03_01_simple_fitting")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))

old_params = ast.literal_eval(x.autoadapted_params.value)
input_processed, background_processed, ignore_mask_processed = x.preprocess_images(img, None, None)
Expand Down Expand Up @@ -629,9 +629,9 @@ def test_03_02_fitting_background_masked(self):

image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.providers.append(cpi.VanillaImageProvider(MASK_IMAGE_NAME, mask))
image_set.providers.append(cpi.VanillaImageProvider(BACKGROUND_IMAGE_NAME, background))
image_set.add_provider(cpi.VanillaImageProvider(IMAGE_NAME, image))
image_set.add_provider(cpi.VanillaImageProvider(MASK_IMAGE_NAME, mask))
image_set.add_provider(cpi.VanillaImageProvider(BACKGROUND_IMAGE_NAME, background))

old_params = ast.literal_eval(x.autoadapted_params.value)
input_processed, background_processed, ignore_mask_processed = x.preprocess_images(img, background_mask, ignore_mask)
Expand Down

0 comments on commit 9483a68

Please sign in to comment.