How to use the cellprofiler.pipeline.Pipeline function in CellProfiler

To help you get started, we’ve selected a few CellProfiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CellProfiler / CellProfiler / tests / modules / test_loadimages.py View on Github external
cellprofiler.modules.loadimages.FF_AVI_MOVIES
        not in cellprofiler.modules.loadimages.FF
    ):
        sys.stderr.write("WARNING: AVI movies not supported\n")
        return
    file_name = "DrosophilaEmbryo_GFPHistone.avi"
    avi_path = tests.modules.testimages_directory()
    tests.modules.maybe_download_tesst_image(file_name)
    module = cellprofiler.modules.loadimages.LoadImages()
    module.file_types.value = cellprofiler.modules.loadimages.FF_AVI_MOVIES
    module.images[0].common_text.value = file_name
    module.images[0].channels[0].image_name.value = "MyImage"
    module.location.dir_choice = cellprofiler.setting.ABSOLUTE_FOLDER_NAME
    module.location.custom_path = avi_path
    module.set_module_num(1)
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_module(module)
    pipeline.add_listener(error_callback)
    image_set_list = cellprofiler.image.ImageSetList()
    m = cellprofiler.measurement.Measurements()
    workspace = cellprofiler.workspace.Workspace(
        pipeline, module, None, None, m, image_set_list
    )
    module.prepare_run(workspace)
    assert m.image_set_count == 65
    module.prepare_group(workspace, (), [1, 2, 3])
    image_set = image_set_list.get_image_set(0)
    workspace = cellprofiler.workspace.Workspace(
        pipeline, module, image_set, cellprofiler.object.ObjectSet(), m, image_set_list
    )
    module.run(workspace)
    assert "MyImage" in image_set.names
github CellProfiler / CellProfiler / tests / modules / test_measureobjectsizeshape.py View on Github external
def test_measurements_zernike():
    module = cellprofiler.modules.measureobjectsizeshape.MeasureObjectAreaShape()
    settings = ["SomeObjects", "OtherObjects", "Yes"]
    module.set_settings_from_values(settings, 1, module.module_class())
    pipeline = cellprofiler.pipeline.Pipeline()
    for object_name in settings[:-1]:
        measurements = module.get_measurements(pipeline, object_name, "AreaShape")
        for measurement in (
            cellprofiler.modules.measureobjectsizeshape.F_STANDARD
            + cellprofiler.modules.measureobjectsizeshape.F_STD_2D
        ):
            assert measurement in measurements
        assert "Zernike_3_1" in measurements
github CellProfiler / CellProfiler / tests / modules / test_namesandtypes.py View on Github external
def test_get_categories():
    p = cellprofiler.pipeline.Pipeline()
    p.clear()
    nts = [
        m
        for m in p.modules()
        if isinstance(m, cellprofiler.modules.namesandtypes.NamesAndTypes)
    ]
    assert len(nts) == 1
    m = nts[0]
    m.assignment_method.value = cellprofiler.modules.namesandtypes.ASSIGN_RULES
    m.assignments[0].image_name.value = IMAGE_NAME
    categories = m.get_categories(p, cellprofiler.measurement.IMAGE)
    assert not (cellprofiler.measurement.C_OBJECTS_FILE_NAME in categories)
    assert not (cellprofiler.measurement.C_OBJECTS_PATH_NAME in categories)
    assert not (cellprofiler.measurement.C_OBJECTS_URL in categories)
    assert cellprofiler.measurement.C_FILE_NAME in categories
    assert cellprofiler.measurement.C_PATH_NAME in categories
github CellProfiler / CellProfiler / tests / modules / test_loadimages.py View on Github external
def convtester(pipeline_text, directory, fn_filter=(lambda x: True)):
    """Test whether a converted pipeline yields the same output

    pipeline_text - the pipeline as a text file

    directory - the default input directory

    fn_filter - a function that returns True if a file should be included
                in the workspace file list.
    """
    cellprofiler.preferences.set_default_image_directory(directory)
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.load(io.StringIO(pipeline_text))

    def callback(caller, event):
        assert not isinstance(event, cellprofiler.pipeline.RunExceptionEvent)

    pipeline.add_listener(callback)
    m = [
        m
        for m in pipeline.modules()
        if isinstance(m, cellprofiler.modules.loadimages.LoadImages)
    ][0]
    m1 = cellprofiler.measurement.Measurements()
    w1 = cellprofiler.workspace.Workspace(pipeline, m, m1, None, m1, None)
    pipeline.prepare_run(w1)

    m2 = cellprofiler.measurement.Measurements()
github CellProfiler / CellProfiler / tests / modules / test_align.py View on Github external
def test_load_v3():
    with open("./tests/resources/modules/align/v3.pipeline", "r") as fd:
        data = fd.read()

    pipeline = cellprofiler.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)

    pipeline.add_listener(callback)
    pipeline.load(six.moves.StringIO(data))
    assert len(pipeline.modules()) == 3
    for module, crop_method in zip(
        pipeline.modules(),
        (
            cellprofiler.modules.align.C_SAME_SIZE,
            cellprofiler.modules.align.C_CROP,
            cellprofiler.modules.align.C_PAD,
        ),
    ):
        assert isinstance(module, cellprofiler.modules.align.Align)
github CellProfiler / CellProfiler / tests / modules / test_identifysecondaryobjects.py View on Github external
def test_two_objects_propagation_distance():
    p = cellprofiler.pipeline.Pipeline()
    o_s = cellprofiler.object.ObjectSet()
    i_l = cellprofiler.image.ImageSetList()
    img = numpy.zeros((10, 20))
    img[2:7, 2:7] = 0.3
    img[2:7, 7:17] = 0.5
    image = cellprofiler.image.Image(img)
    objects = cellprofiler.object.Objects()
    labels = numpy.zeros((10, 20), int)
    labels[3:6, 3:6] = 1
    labels[3:6, 13:16] = 2
    objects.unedited_segmented = labels
    objects.small_removed_segmented = labels
    objects.segmented = labels
    o_s.add_objects(objects, INPUT_OBJECTS_NAME)
    i_s = i_l.get_image_set(0)
    i_s.add(IMAGE_NAME, image)
github CellProfiler / CellProfiler / tests / modules / test_loadimages.py View on Github external
image = module.images[0]
    image.common_text.value = file_name
    image.wants_movie_frame_grouping.value = True
    image.interleaving.value = cellprofiler.modules.loadimages.I_SEPARATED
    image.channels_per_group.value = 5
    channel = image.channels[0]
    channel.image_name.value = "Channel01"
    channel.channel_number.value = "1"
    module.add_channel(image)
    channel = module.images[0].channels[1]
    channel.channel_number.value = "3"
    channel.image_name.value = "Channel03"
    module.location.dir_choice = cellprofiler.setting.ABSOLUTE_FOLDER_NAME
    module.location.custom_path = avi_path
    module.set_module_num(1)
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_module(module)
    pipeline.add_listener(error_callback)
    image_set_list = cellprofiler.image.ImageSetList()
    m = cellprofiler.measurement.Measurements()
    workspace = cellprofiler.workspace.Workspace(
        pipeline, module, None, None, m, image_set_list
    )
    module.prepare_run(workspace)
    assert m.image_set_count == 13
    module.prepare_group(workspace, (), numpy.arange(1, 16))
    image_set = image_set_list.get_image_set(0)
    workspace = cellprofiler.workspace.Workspace(
        pipeline, module, image_set, cellprofiler.object.ObjectSet(), m, image_set_list
    )
    module.run(workspace)
    assert "Channel01" in image_set.names
github CellProfiler / CellProfiler / tests / modules / test_measuretexture.py View on Github external
Hidden:2
Hidden:2
Hidden:2
Select an image to measure:rawDNA
Select an image to measure:rawGFP
Select objects to measure:Cells
Select objects to measure:Nuclei
Texture scale to measure:3
Angles to measure:Horizontal,Vertical
Texture scale to measure:5
Angles to measure:Diagonal,Anti-diagonal
Measure Gabor features?:No
Number of angles to compute for Gabor:6
Measure images or objects?:Both
"""
    pipeline = cellprofiler.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)

    pipeline.add_listener(callback)
    pipeline.load(io.StringIO(data))
    assert len(pipeline.modules()) == 3
    for i, (wants_gabor, io_choice) in enumerate(
        (
            (True, cellprofiler.modules.measuretexture.IO_IMAGES),
            (False, cellprofiler.modules.measuretexture.IO_OBJECTS),
            (False, cellprofiler.modules.measuretexture.IO_BOTH),
        )
    ):
        module = pipeline.modules()[i]
        assert isinstance(module, cellprofiler.modules.measuretexture.MeasureTexture)
github CellProfiler / CellProfiler / tests / test_pipeline.py View on Github external
def test_17_00_get_dependency_graph_empty(self):
        for module in (
            ATestModule(),
            ATestModule([cellprofiler.setting.Choice("foo", ["Hello", "World"])]),
            ATestModule([cellprofiler.setting.ImageNameProvider("foo", IMAGE_NAME)]),
            ATestModule([cellprofiler.setting.ImageNameSubscriber("foo", IMAGE_NAME)]),
        ):
            pipeline = cellprofiler.pipeline.Pipeline()
            module.set_module_num(1)
            pipeline.add_module(module)
            result = pipeline.get_dependency_graph()
            self.assertEqual(len(result), 0)