Beispiel #1
0
def test_02_get_zernike_columns():
    module = (cellprofiler.modules.measureobjectintensitydistribution.
              MeasureObjectIntensityDistribution())
    for wants_zernikes, ftrs in (
        (
            cellprofiler.modules.measureobjectintensitydistribution.
            Z_MAGNITUDES,
            (cellprofiler.modules.measureobjectintensitydistribution.
             FF_ZERNIKE_MAGNITUDE, ),
        ),
        (
            cellprofiler.modules.measureobjectintensitydistribution.
            Z_MAGNITUDES_AND_PHASE,
            (
                cellprofiler.modules.measureobjectintensitydistribution.
                FF_ZERNIKE_MAGNITUDE,
                cellprofiler.modules.measureobjectintensitydistribution.
                FF_ZERNIKE_PHASE,
            ),
        ),
    ):
        module.wants_zernikes.value = wants_zernikes
        module.zernike_degree.value = 2
        for i, image_name in ((0, "DNA"), (1, "Cytoplasm"), (2, "Actin")):
            if i:
                module.add_image()
            module.images[i].image_name.value = image_name
        for i, object_name, center_name in (
            (0, "Nucleii", None),
            (1, "Cells", "Nucleii"),
            (2, "Cytoplasm", "Nucleii"),
        ):
            if i:
                module.add_object()
            module.objects[i].object_name.value = object_name
        columns = module.get_measurement_columns(None)
        for image_name in "DNA", "Cytoplasm", "Actin":
            for object_name in "Nucleii", "Cells", "Cytoplasm":
                for n, m in ((0, 0), (1, 1), (2, 0), (2, 2)):
                    for ftr in ftrs:
                        name = "_".join((
                            cellprofiler.modules.
                            measureobjectintensitydistribution.M_CATEGORY,
                            ftr,
                            image_name,
                            str(n),
                            str(m),
                        ))
                        col = (
                            object_name,
                            name,
                            cellprofiler_core.measurement.COLTYPE_FLOAT,
                        )
                        assert col in columns
Beispiel #2
0
def test_01_get_measurement_columns():
    module = (cellprofiler.modules.measureobjectintensitydistribution.
              MeasureObjectIntensityDistribution())
    for i, image_name in ((0, "DNA"), (1, "Cytoplasm"), (2, "Actin")):
        if i:
            module.add_image()
        module.images[i].image_name.value = image_name
    for i, object_name, center_name in (
        (0, "Nucleii", None),
        (1, "Cells", "Nucleii"),
        (2, "Cytoplasm", "Nucleii"),
    ):
        if i:
            module.add_object()
        module.objects[i].object_name.value = object_name
        if center_name is None:
            module.objects[i].center_choice.value = (
                cellprofiler.modules.measureobjectintensitydistribution.C_SELF)
        else:
            module.objects[i].center_choice.value = (
                cellprofiler.modules.measureobjectintensitydistribution.
                C_CENTERS_OF_OTHER)
            module.objects[i].center_object_name.value = center_name
    for i, bin_count in enumerate((4, 5, 6)):
        if i:
            module.add_bin_count()
        module.bin_counts[i].bin_count.value = bin_count
    module.bin_counts[2].wants_scaled.value = False

    columns = module.get_measurement_columns(None)
    column_dictionary = {}
    for object_name, feature, coltype in columns:
        key = (object_name, feature)
        assert not (key in column_dictionary)
        assert coltype == cellprofiler_core.measurement.COLTYPE_FLOAT
        column_dictionary[key] = (object_name, feature, coltype)

    for object_name in [x.object_name.value for x in module.objects]:
        for image_name in [x.image_name.value for x in module.images]:
            for bin_count, wants_scaled in [(x.bin_count.value,
                                             x.wants_scaled.value)
                                            for x in module.bin_counts]:
                for bin in range(1, bin_count + (1 if wants_scaled else 2)):
                    for feature_fn in (
                            feature_frac_at_d,
                            feature_mean_frac,
                            feature_radial_cv,
                    ):
                        measurement = feature_fn(bin, bin_count, image_name)
                        key = (object_name, measurement)
                        assert key in column_dictionary
                        del column_dictionary[key]
    assert len(column_dictionary) == 0
Beispiel #3
0
def run_imagemath(images, modify_module_fn=None, measurement=None):
    """Run the ImageMath module, returning the image created

    images - a list of dictionaries. The dictionary has keys:
             pixel_data - image pixel data
             mask - mask for image
             cropping - cropping mask for image
    modify_module_fn - a function of the signature, fn(module)
             that allows the test to modify the module.
    measurement - an image measurement value
    """
    image_set_list = cellprofiler_core.image.ImageSetList()
    image_set = image_set_list.get_image_set(0)
    module = cellprofiler.modules.imagemath.ImageMath()
    module.set_module_num(1)
    for i, image in enumerate(images):
        pixel_data = image["pixel_data"]
        mask = image.get("mask", None)
        cropping = image.get("cropping", None)
        if i >= 2:
            module.add_image()
        name = "inputimage%s" % i
        module.images[i].image_name.value = name
        img = cellprofiler_core.image.Image(pixel_data,
                                            mask=mask,
                                            crop_mask=cropping)
        image_set.add(name, img)
    module.output_image_name.value = "outputimage"
    if modify_module_fn is not None:
        modify_module_fn(module)
    pipeline = cellprofiler_core.pipeline.Pipeline()
    pipeline.add_module(module)
    measurements = cellprofiler_core.measurement.Measurements()
    if measurement is not None:
        measurements.add_image_measurement(MEASUREMENT_NAME, str(measurement))
    workspace = cellprofiler_core.workspace.Workspace(
        pipeline,
        module,
        image_set,
        cellprofiler_core.object.ObjectSet(),
        measurements,
        image_set_list,
    )
    module.run(workspace)
    return image_set.get_image("outputimage")
Beispiel #4
0
def test_default_heatmap_values():
    module = (cellprofiler.modules.measureobjectintensitydistribution.
              MeasureObjectIntensityDistribution())
    module.add_heatmap()
    module.heatmaps[0].image_name.value = IMAGE_NAME
    module.heatmaps[0].object_name.value = OBJECT_NAME
    module.heatmaps[0].bin_count.value = 10
    module.images[0].image_name.value = "Bar"
    module.objects[0].object_name.value = "Foo"
    module.bin_counts[0].bin_count.value = 2
    assert module.heatmaps[0].image_name.get_image_name() == "Bar"
    assert not module.heatmaps[0].image_name.is_visible()
    assert module.heatmaps[0].object_name.get_objects_name() == "Foo"
    assert not module.heatmaps[0].object_name.is_visible()
    assert module.heatmaps[0].get_number_of_bins() == 2
    module.add_image()
    assert module.heatmaps[0].image_name.is_visible()
    assert module.heatmaps[0].image_name.get_image_name() == IMAGE_NAME
    module.add_object()
    assert module.heatmaps[0].object_name.is_visible()
    assert module.heatmaps[0].object_name.get_objects_name() == OBJECT_NAME
    module.add_bin_count()
    assert module.heatmaps[0].get_number_of_bins() == 10
Beispiel #5
0
def test_02_get_zernike_measurements():
    module = (cellprofiler.modules.measureobjectintensitydistribution.
              MeasureObjectIntensityDistribution())
    for wants_zernikes, ftrs in (
        (
            cellprofiler.modules.measureobjectintensitydistribution.
            Z_MAGNITUDES,
            (cellprofiler.modules.measureobjectintensitydistribution.
             FF_ZERNIKE_MAGNITUDE, ),
        ),
        (
            cellprofiler.modules.measureobjectintensitydistribution.
            Z_MAGNITUDES_AND_PHASE,
            (
                cellprofiler.modules.measureobjectintensitydistribution.
                FF_ZERNIKE_MAGNITUDE,
                cellprofiler.modules.measureobjectintensitydistribution.
                FF_ZERNIKE_PHASE,
            ),
        ),
    ):
        module.wants_zernikes.value = wants_zernikes
        module.zernike_degree.value = 2

        for i, image_name in ((0, "DNA"), (1, "Cytoplasm"), (2, "Actin")):
            if i:
                module.add_image()
            module.images[i].image_name.value = image_name
        for i, object_name, center_name in (
            (0, "Nucleii", None),
            (1, "Cells", "Nucleii"),
            (2, "Cytoplasm", "Nucleii"),
        ):
            if i:
                module.add_object()
            module.objects[i].object_name.value = object_name
            if center_name is None:
                module.objects[i].center_choice.value = (
                    cellprofiler.modules.measureobjectintensitydistribution.
                    C_SELF)
            else:
                module.objects[i].center_choice.value = (
                    cellprofiler.modules.measureobjectintensitydistribution.
                    C_CENTERS_OF_OTHER)
                module.objects[i].center_object_name.value = center_name

        for object_name in "Nucleii", "Cells", "Cytoplasm":
            result = module.get_measurements(
                None,
                object_name,
                cellprofiler.modules.measureobjectintensitydistribution.
                M_CATEGORY,
            )
            for ftr in ftrs:
                assert ftr in result
                iresult = module.get_measurement_images(
                    None,
                    object_name,
                    cellprofiler.modules.measureobjectintensitydistribution.
                    M_CATEGORY,
                    ftr,
                )
                for image in "DNA", "Cytoplasm", "Actin":
                    assert image in iresult
                    sresult = module.get_measurement_scales(
                        None,
                        object_name,
                        cellprofiler.modules.
                        measureobjectintensitydistribution.M_CATEGORY,
                        ftr,
                        image,
                    )
                    for n, m in ((0, 0), (1, 1), (2, 0), (2, 2)):
                        assert "%d_%d" % (n, m) in sresult
Beispiel #6
0
def test_01_get_measurements():
    module = (cellprofiler.modules.measureobjectintensitydistribution.
              MeasureObjectIntensityDistribution())
    for i, image_name in ((0, "DNA"), (1, "Cytoplasm"), (2, "Actin")):
        if i:
            module.add_image()
        module.images[i].image_name.value = image_name
    for i, object_name, center_name in (
        (0, "Nucleii", None),
        (1, "Cells", "Nucleii"),
        (2, "Cytoplasm", "Nucleii"),
    ):
        if i:
            module.add_object()
        module.objects[i].object_name.value = object_name
        if center_name is None:
            module.objects[i].center_choice.value = (
                cellprofiler.modules.measureobjectintensitydistribution.C_SELF)
        else:
            module.objects[i].center_choice.value = (
                cellprofiler.modules.measureobjectintensitydistribution.
                C_CENTERS_OF_OTHER)
            module.objects[i].center_object_name.value = center_name
    for i, bin_count in ((0, 4), (0, 5), (0, 6)):
        if i:
            module.add_bin_count()
        module.bin_counts[i].bin_count.value = bin_count

    for object_name in [x.object_name.value for x in module.objects]:
        assert tuple(module.get_categories(None, object_name)) == (
            cellprofiler.modules.measureobjectintensitydistribution.M_CATEGORY,
        )
        for feature in cellprofiler.modules.measureobjectintensitydistribution.F_ALL:
            assert feature in module.get_measurements(
                None,
                object_name,
                cellprofiler.modules.measureobjectintensitydistribution.
                M_CATEGORY,
            )
        for image_name in [x.image_name.value for x in module.images]:
            for (
                    feature
            ) in cellprofiler.modules.measureobjectintensitydistribution.F_ALL:
                assert image_name in module.get_measurement_images(
                    None,
                    object_name,
                    cellprofiler.modules.measureobjectintensitydistribution.
                    M_CATEGORY,
                    feature,
                )
            for bin_count in [x.bin_count.value for x in module.bin_counts]:
                for bin in range(1, bin_count + 1):
                    for (
                            feature
                    ) in cellprofiler.modules.measureobjectintensitydistribution.F_ALL:
                        assert "%dof%d" % (
                            bin,
                            bin_count,
                        ) in module.get_measurement_scales(
                            None,
                            object_name,
                            cellprofiler.modules.
                            measureobjectintensitydistribution.M_CATEGORY,
                            feature,
                            image_name,
                        )