Beispiel #1
0
def test_annotate():

    correct_result = """

(Circle1   ; MUK_ANNOTATION
    (Color Blue)   ; MUK_ANNOTATION
    (Name "narrow start")   ; MUK_ANNOTATION
    (      0.00       0.00       2.00 0.50)   ; MUK_ANNOTATION
)   ; MUK_ANNOTATION
"""

    checkers = {has_no_narrow_start: {"name": "narrow start",
                                      "label": "Circle1",
                                      "color": "Blue"}}

    neuron = load_neuron(SWC_PATH / 'narrow_start.swc')
    results = [checker(neuron) for checker in checkers.keys()]
    assert annotate(results, checkers.values()) == correct_result
Beispiel #2
0
def test_annotate():

    correct_result = """

(Circle1   ; MUK_ANNOTATION
    (Color Blue)   ; MUK_ANNOTATION
    (Name "narrow start")   ; MUK_ANNOTATION
    (0.0 0.0 0.0 0.50)   ; MUK_ANNOTATION
    (0.0 0.0 0.0 0.50)   ; MUK_ANNOTATION
)   ; MUK_ANNOTATION
"""

    checkers = {
        has_no_narrow_start: {
            "name": "narrow start",
            "label": "Circle1",
            "color": "Blue"
        }
    }

    neuron = load_neuron('test_data/swc/Neuron_zero_radius.swc')
    results = [checker(neuron) for checker in checkers.keys()]
    nt.assert_equal(annotate(results, checkers.values()), correct_result)
Beispiel #3
0
def annotate_neurolucida(morph_path, checkers=None):
    """Annotate errors on a morphology in neurolucida format.

    Args:
        morph_path (str): absolute path to an ascii morphology
        checkers (dict): dict of checker functons from neurom with function as keys
            and marker data in a dict as values, if None, default checkers are used

    Default checkers include:
        - fat ends
        - z-jumps
        - narrow start
        - dangling branch
        - multifurcation

    Returns:
        annotations to append to .asc file
        dict of error summary
        dict of error markers
    """
    if checkers is None:
        checkers = {
            nc.has_no_fat_ends: {
                "name": "fat end",
                "label": "Circle3",
                "color": "Blue"
            },
            partial(nc.has_no_jumps, axis="z"): {
                "name": "zjump",
                "label": "Circle2",
                "color": "Green",
            },
            nc.has_no_narrow_start: {
                "name": "narrow start",
                "label": "Circle1",
                "color": "Blue"
            },
            nc.has_no_dangling_branch: {
                "name": "dangling",
                "label": "Circle6",
                "color": "Magenta"
            },
            nc.has_multifurcation: {
                "name": "Multifurcation",
                "label": "Circle8",
                "color": "Yellow",
            },
        }

    def _try(checker, neuron):
        """Try to apply a checker, returns True if exception raised, so the checker is bypassed."""
        try:
            return checker(neuron)
        except Exception as e:  # pylint: disable=broad-except
            L.exception("%s failed on %s", checker, morph_path)
            L.exception(e, exc_info=True)
            return CheckResult(True)

    neuron = load_neuron(morph_path)
    results = [_try(checker, neuron) for checker in checkers]
    markers = [
        dict(setting, data=result.info)
        for result, setting in zip(results, checkers.values())
        if not result.status
    ]
    summary = {
        setting["name"]: len(result.info)
        for result, setting in zip(results, checkers.values()) if result.info
    }
    return annotate(results, checkers.values()), summary, markers