Beispiel #1
0
def test_angle_3points_half_pi():
    orig = (0.0, 0.0, 0.0)
    vec1 = (1.0, 0.0, 0.0)
    vec2 = (0.0, 2.0, 0.0)
    nt.eq_(mm.angle_3points(orig, vec1, vec2), pi / 2.0)

    vec2 = (0.0, 0.0, 3.0)
    nt.eq_(mm.angle_3points(orig, vec1, vec2), pi / 2.0)

    vec2 = (0.0, 0.0, -3.0)
    nt.eq_(mm.angle_3points(orig, vec1, vec2), pi / 2.0)

    vec1 = (0.0, 4.0, 0.0)
    nt.eq_(mm.angle_3points(orig, vec1, vec2), pi / 2.0)
Beispiel #2
0
def test_angle_3points_half_pi():
    orig = (0.0, 0.0, 0.0)
    vec1 = (1.0, 0.0, 0.0)
    vec2 = (0.0, 2.0, 0.0)
    assert mm.angle_3points(orig, vec1, vec2) == pi / 2.0

    vec2 = (0.0, 0.0, 3.0)
    assert mm.angle_3points(orig, vec1, vec2) == pi / 2.0

    vec2 = (0.0, 0.0, -3.0)
    assert mm.angle_3points(orig, vec1, vec2) == pi / 2.0

    vec1 = (0.0, 4.0, 0.0)
    assert mm.angle_3points(orig, vec1, vec2) == pi / 2.0
Beispiel #3
0
def local_bifurcation_angle(bif_point):
    """Return the opening angle between two out-going sections in a bifurcation point.

    We first ensure that the input point has only two children.

    The bifurcation angle is defined as the angle between the first non-zero
    length segments of a bifurcation point.
    """
    def skip_0_length(sec):
        """Return the first point with non-zero distance to first point."""
        p0 = sec[0]
        cur = sec[1]
        for i, p in enumerate(sec[1:]):
            if not np.all(p[:COLS.R] == p0[:COLS.R]):
                cur = sec[i + 1]
                break

        return cur

    _raise_if_not_bifurcation(bif_point)

    ch0, ch1 = (skip_0_length(bif_point.children[0].points),
                skip_0_length(bif_point.children[1].points))

    return morphmath.angle_3points(bif_point.points[-1], ch0, ch1)
Beispiel #4
0
def test_angle_3points_three_quarter_pi():
    orig = (0.0, 0.0, 0.0)
    vec1 = (1.0, 0.0, 0.0)
    vec2 = (-2.0, 2.0, 0.0)
    nt.assert_equal(mm.angle_3points(orig, vec1, vec2), 3 * pi / 4.0)

    vec2 = (-3.0, 3.0, 0.0)
    nt.assert_equal(mm.angle_3points(orig, vec1, vec2), 3* pi / 4.0)

    vec2 = (-3.0, -3.0, 0.0)
    nt.assert_equal(mm.angle_3points(orig, vec1, vec2), 3 * pi / 4.0)

    vec2 = (-3.0, 0.0, 3.0)
    nt.assert_equal(mm.angle_3points(orig, vec1, vec2), 3 * pi / 4.0)

    vec2 = (-3.0, 0.0, -3.0)
    nt.assert_equal(mm.angle_3points(orig, vec1, vec2), 3 * pi / 4.0)
Beispiel #5
0
def test_angle_3points_three_quarter_pi():
    orig = (0.0, 0.0, 0.0)
    vec1 = (1.0, 0.0, 0.0)
    vec2 = (-2.0, 2.0, 0.0)
    assert mm.angle_3points(orig, vec1, vec2) == 3 * pi / 4.0

    vec2 = (-3.0, 3.0, 0.0)
    assert mm.angle_3points(orig, vec1, vec2) == 3 * pi / 4.0

    vec2 = (-3.0, -3.0, 0.0)
    assert mm.angle_3points(orig, vec1, vec2) == 3 * pi / 4.0

    vec2 = (-3.0, 0.0, 3.0)
    assert mm.angle_3points(orig, vec1, vec2) == 3 * pi / 4.0

    vec2 = (-3.0, 0.0, -3.0)
    assert mm.angle_3points(orig, vec1, vec2) == 3 * pi / 4.0
Beispiel #6
0
def remote_bifurcation_angle(bif_point):
    '''Return the opening angle between two out-going sections
    in a bifurcation point

    The angle is defined as between the bifurcation point and the
    last points in the out-going sections.
    '''
    return morphmath.angle_3points(bif_point.points[-1],
                                   bif_point.children[0].points[-1],
                                   bif_point.children[1].points[-1])
Beispiel #7
0
def remote_bifurcation_angle(bif_point):
    '''Return the opening angle between two out-going sections
    in a bifurcation point

    The angle is defined as between the bifurcation point and the
    last points in the out-going sections.
    '''
    return morphmath.angle_3points(bif_point.points[-1],
                                   bif_point.children[0].points[-1],
                                   bif_point.children[1].points[-1])
Beispiel #8
0
def remote_bifurcation_angle(bif_point):
    """Return the opening angle between two out-going sections in a bifurcation point.

    We first ensure that the input point has only two children.

    The angle is defined as between the bifurcation point and the
    last points in the out-going sections.
    """
    _raise_if_not_bifurcation(bif_point)

    return morphmath.angle_3points(bif_point.points[-1],
                                   bif_point.children[0].points[-1],
                                   bif_point.children[1].points[-1])
Beispiel #9
0
def remote_bifurcation_angle(bif_point):
    '''Return the opening angle between two out-going sections
    in a bifurcation point

    We first ensure that the input point has only two children.

    The angle is defined as between the bifurcation point and the
    last points in the out-going sections.
    '''
    assert len(bif_point.children) == 2, 'A bifurcation point must have exactly 2 children'

    return morphmath.angle_3points(bif_point.points[-1],
                                   bif_point.children[0].points[-1],
                                   bif_point.children[1].points[-1])
Beispiel #10
0
def local_bifurcation_angle(bifurcation_point):
    '''Return the opening angle between two out-going segments
    in a bifurcation point

    The bifurcation angle is defined as the angle between the first non-zero
    length segments of a bifurcation point.
    '''
    def _skip_0_length(p, c):
        '''Return the first child c with non-zero distance to parent p'''
        while np.all(p.value[:COLS.R] == c.value[:COLS.R])\
                and not tr.is_leaf(c) and not tr.is_forking_point(c):
            c = c.children[0]
        return c

    ch = (_skip_0_length(bifurcation_point, bifurcation_point.children[0]),
          _skip_0_length(bifurcation_point, bifurcation_point.children[1]))

    return mm.angle_3points(bifurcation_point.value,
                            ch[0].value, ch[1].value)
Beispiel #11
0
def local_bifurcation_angle(bif_point):
    '''Return the opening angle between two out-going sections
    in a bifurcation point

    The bifurcation angle is defined as the angle between the first non-zero
    length segments of a bifurcation point.
    '''
    def skip_0_length(sec):
        '''Return the first point with non-zero distance to first point'''
        p0 = sec[0]
        cur = sec[1]
        for i, p in enumerate(sec[1:]):
            if not np.all(p[:COLS.R] == p0[:COLS.R]):
                cur = sec[i + 1]
                break

        return cur

    ch = (skip_0_length(bif_point.children[0].points),
          skip_0_length(bif_point.children[1].points))

    return mm.angle_3points(bif_point.points[-1], ch[0], ch[1])
Beispiel #12
0
def local_bifurcation_angle(bif_point):
    '''Return the opening angle between two out-going sections
    in a bifurcation point

    The bifurcation angle is defined as the angle between the first non-zero
    length segments of a bifurcation point.
    '''
    def skip_0_length(sec):
        '''Return the first point with non-zero distance to first point'''
        p0 = sec[0]
        cur = sec[1]
        for i, p in enumerate(sec[1:]):
            if not np.all(p[:COLS.R] == p0[:COLS.R]):
                cur = sec[i + 1]
                break

        return cur

    ch0, ch1 = (skip_0_length(bif_point.children[0].points),
                skip_0_length(bif_point.children[1].points))

    return morphmath.angle_3points(bif_point.points[-1], ch0, ch1)
Beispiel #13
0
def meander_angle(triplet):
    '''Return the angle between a triplet of consecutive points'''
    return mm.angle_3points(triplet[1], triplet[0], triplet[2])
Beispiel #14
0
def test_angle_3points_opposing_returns_pi():
    orig = (0.0, 0.0, 0.0)
    vec1 = (1.0, 1.0, 1.0)
    vec2 = (-2.0, -2.0, -2.0)
    angle = mm.angle_3points(orig, vec1, vec2)
    assert angle == pi
Beispiel #15
0
def test_angle_3points_equal_points_returns_zero():
    orig = (0.0, 1.0, 0.0)
    vec1 = (1.0, 0.0, 0.0)
    vec2 = (0.0, 1.0, 0.0)
    a = mm.angle_3points(orig, vec1, vec2)
    nt.assert_equal(a, 0.0)
Beispiel #16
0
def test_angle_3points_equal_points_returns_zero():
    orig = (0.0, 1.0, 0.0)
    vec1 = (1.0, 0.0, 0.0)
    vec2 = (0.0, 1.0, 0.0)
    a = mm.angle_3points(orig, vec1, vec2)
    assert a == 0.0
Beispiel #17
0
def test_angle_3points_opposing_returns_pi():
    orig = (0.0, 0.0, 0.0)
    vec1 = (1.0, 1.0, 1.0)
    vec2 = (-2.0, -2.0, -2.0)
    angle=mm.angle_3points(orig, vec1, vec2)
    nt.assert_equal(angle, pi)
Beispiel #18
0
def test_angle_3points_collinear_returns_zero():
    orig = (0.0, 0.0, 0.0)
    vec1 = (1.0, 1.0, 1.0)
    vec2 = (2.0, 2.0, 2.0)
    angle = mm.angle_3points(orig, vec1, vec2)
    assert angle == 0.0
Beispiel #19
0
def test_angle_3points_collinear_returns_zero():
    orig = (0.0, 0.0, 0.0)
    vec1 = (1.0, 1.0, 1.0)
    vec2 = (2.0, 2.0, 2.0)
    angle=mm.angle_3points(orig, vec1, vec2)
    nt.assert_equal(angle, 0.0)
Beispiel #20
0
def section_meander_angles(section):
    '''Inter-segment opening angles in a section'''
    p = section.points
    return [
        mm.angle_3points(p[i - 1], p[i - 2], p[i]) for i in range(2, len(p))
    ]
Beispiel #21
0
def section_meander_angles(section):
    '''Inter-segment opening angles in a section'''
    p = section.points
    return [mm.angle_3points(p[i - 1], p[i - 2], p[i])
            for i in range(2, len(p))]