def test_spot_detection_with_reference_image_exact_match(
    data_stack: ImageStack,
    spot_detector: FindSpotsAlgorithm,
    max_intensity: float,
):
    """This testing method uses a reference image to identify spot locations then builds traces
    using the exact_match strategy. This represents a workflow common in a multiplexed assays.
    Each method should detect 2 total spots in the max projected reference image then group them
    into 2 distinct spot traces across the ImageStack. """

    reference_image = data_stack.reduce((Axes.ROUND, Axes.CH),
                                        func=FunctionSource.np("max"))
    spots = spot_detector.run(image_stack=data_stack,
                              reference_image=reference_image)
    intensity_table = trace_builders.build_spot_traces_exact_match(spots)
    assert intensity_table.sizes[
        Features.AXIS] == 2, "wrong number of spots traces detected"
    expected = [max_intensity * 2, max_intensity * 2]
    assert np.allclose(intensity_table.sum((Axes.ROUND, Axes.CH)).values, expected), \
        "wrong spot intensities detected"

    # verify this execution strategy produces an empty intensitytable when called with a blank image
    reference_image = EMPTY_IMAGESTACK.reduce((Axes.ROUND, Axes.CH),
                                              func=FunctionSource.np("max"))
    spots = spot_detector.run(image_stack=EMPTY_IMAGESTACK,
                              reference_image=reference_image)
    empty_intensity_table = trace_builders.build_spot_traces_exact_match(spots)
    assert empty_intensity_table.sizes[Features.AXIS] == 0
def test_spot_finding_reference_image_sequential(
        data_stack: ImageStack,
        spot_detector: FindSpotsAlgorithm,
        max_intensity: float,
):
    """
    This testing method uses a reference image to identify spot locations then builds traces
    using the sequential strategy. It finds 2 spots in the max projected image, then measures the
    two spots on each tile totally 2*num_chs*num_rounds spots. When building spot traces it treats
    each spot as it's own trace totally 8 traces. This workflow doesn't really make sense but
    we're testing it anyway.
    """

    reference_image = data_stack.reduce((Axes.ROUND, Axes.CH), func="max", module=FunctionSource.np)
    spots = spot_detector.run(image_stack=data_stack, reference_image=reference_image)
    intensity_table = trace_builders.build_traces_sequential(spots)
    expected_num_traces = (2 * data_stack.num_chs * data_stack.num_rounds)
    assert intensity_table.sizes[Features.AXIS] == expected_num_traces, "wrong number of " \
                                                                        "spots traces detected"

    reference_image = EMPTY_IMAGESTACK.reduce((Axes.ROUND, Axes.CH), func="max",
                                              module=FunctionSource.np)
    spots = spot_detector.run(image_stack=EMPTY_IMAGESTACK, reference_image=reference_image)
    empty_intensity_table = trace_builders.build_traces_sequential(spots)
    assert empty_intensity_table.sizes[Features.AXIS] == 0
Beispiel #3
0
def test_spot_detection_with_reference_image(
    data_stack: ImageStack,
    spot_detector: FindSpotsAlgorithm,
):
    """This testing method uses a reference image to identify spot locations. Each method should
    find 2 spots in the reference image then measure the intensity of those locations in each
    r/ch pair. The final spot results should represent 2 spots for each r/ch totalling
    2*num_rounds*num_ch spots """

    reference_image = data_stack.reduce((Axes.ROUND, Axes.CH),
                                        func=FunctionSource.np("max"))
    spots_results = spot_detector.run(image_stack=data_stack,
                                      reference_image=reference_image)
    assert spots_results.count_total_spots() == (2 * data_stack.num_chs * data_stack.num_rounds), \
        "wrong number of spots detected"