예제 #1
0
 def __init__(self, data_wrapper, name='Neuron'):
     self._data = data_wrapper
     neurites, sections = make_neurites(self._data)
     soma_check, soma_class = _SOMA_CONFIG[self._data.fmt]
     soma = make_soma(self._data.soma_points(), soma_check, soma_class)
     super(FstNeuron, self).__init__(soma, neurites, sections, name)
     self._points = None
예제 #2
0
def test_make_Soma_ThreePointCylinder():
    with warnings.catch_warnings(record=True):
        sm = _soma.make_soma(SOMA_THREEPOINTS_PTS,
                             soma_class=_soma.SOMA_CYLINDER)
    nt.ok_('SomaNeuromorphoThreePointCylinders' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaNeuromorphoThreePointCylinders))
    nt.eq_(list(sm.center), [0, 0, 0])
    nt.eq_(sm.radius, 44)
예제 #3
0
def test_invalid_soma_points_2_raises_SomaError():
    _soma.make_soma(INVALID_PTS_2)
예제 #4
0
def check_SomaC(points):
    sm = _soma.make_soma(points)
    nt.ok_('SomaSimpleContour' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaSimpleContour))
    np.testing.assert_allclose(sm.center, (0., 0., 0.), atol=1e-16)
    nt.eq_(sm.radius, 1.0)
예제 #5
0
    for diameter_scale, linewidth in it.product((1.0, None),
                                                (0.0, 1.2)):
        with get_fig_2d() as (fig, ax):
            view.plot_tree(ax, test_section, diameter_scale=diameter_scale, linewidth=linewidth)
        with get_fig_3d() as (fig, ax):
            view.plot_tree3d(ax, test_section, diameter_scale=diameter_scale, linewidth=linewidth)


soma0 = fst_neuron.soma

# upright, varying radius
soma_2pt_normal_pts = np.array([
    [0.0,   0.0,  0.0, 1.0,  1, 1, -1],
    [0.0,  10.0,  0.0, 10.0, 1, 2,  1],
])
soma_2pt_normal = make_soma(soma_2pt_normal_pts, soma_class=SOMA_CYLINDER)

# upright, uniform radius, multiple cylinders
soma_3pt_normal_pts = np.array([
    [0.0, -10.0,  0.0, 10.0, 1, 1, -1],
    [0.0,   0.0,  0.0, 10.0, 1, 2,  1],
    [0.0,   10.0, 0.0, 10.0, 1, 3,  2],
])
soma_3pt_normal = make_soma(soma_3pt_normal_pts, soma_class=SOMA_CYLINDER)

# increasing radius, multiple cylinders
soma_4pt_normal_pts = np.array([
    [0.0,   0.0,     0.0, 1.0, 1, 1, -1],
    [0.0,   -10.0,   0.0, 2.0, 1, 2, 1],
    [0.0,   -10.0, -10.0, 3.0, 1, 3, 2],
    [-10.0, -10.0, -10.0, 4.0, 1, 4, 3],
예제 #6
0
def test_make_Soma_contour():
    sm = _soma.make_soma(SOMA_THREEPOINTS_PTS, soma_class=_soma.SOMA_CONTOUR)
    nt.ok_('SomaSimpleContour' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaSimpleContour))
    nt.eq_(list(sm.center), [0, 0, 0])
    nt.assert_almost_equal(sm.radius, 29.33333333, places=5)
예제 #7
0
def test_make_Soma_ThreePoint():
    sm = _soma.make_soma(SOMA_THREEPOINTS_PTS, soma_class=_soma.SOMA_CONTOUR)
    nt.ok_('SomaThreePoint' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaThreePoint))
    nt.eq_(list(sm.center), [0, 0, 0])
    nt.eq_(sm.radius, 44)
예제 #8
0
def test_make_Soma_contour():
    sm = _soma.make_soma(SOMA_THREEPOINTS_PTS, soma_class=_soma.SOMA_CONTOUR)
    nt.ok_('SomaSimpleContour' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaSimpleContour))
    nt.eq_(list(sm.center), [0, 0, 0])
    nt.assert_almost_equal(sm.radius, 29.33333333, places=5)
예제 #9
0
def test_invalid_soma_points_2_raises_SomaError():
    _soma.make_soma(INVALID_PTS_2)
예제 #10
0
def check_SomaC(points):
    sm = _soma.make_soma(points)
    nt.ok_('SomaSimpleContour' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaSimpleContour))
    np.testing.assert_allclose(sm.center, (0., 0., 0.), atol=1e-16)
    nt.eq_(sm.radius, 1.0)
예제 #11
0
def test_make_Soma_ThreePointCylinder_small_radius():
    with warnings.catch_warnings(record=True):
        sm = _soma.make_soma(SOMA_THREEPOINTS_PTS_SMALL_RADIUS,
                             soma_class=_soma.SOMA_CYLINDER)
예제 #12
0
                           linewidth=linewidth)
        with get_fig_3d() as (fig, ax):
            view.plot_tree3d(ax,
                             test_section,
                             diameter_scale=diameter_scale,
                             linewidth=linewidth)


soma0 = fst_neuron.soma

#upright, varying radius
soma_2pt_normal_pts = np.array([
    [0.0, 0.0, 0.0, 1.0, 1, 1, -1],
    [0.0, 10.0, 0.0, 10.0, 1, 2, 1],
])
soma_2pt_normal = make_soma(soma_2pt_normal_pts, soma_class=SOMA_CYLINDER)

#upright, uniform radius, multiple cylinders
soma_3pt_normal_pts = np.array([
    [0.0, -10.0, 0.0, 10.0, 1, 1, -1],
    [0.0, 0.0, 0.0, 10.0, 1, 2, 1],
    [0.0, 10.0, 0.0, 10.0, 1, 3, 2],
])
soma_3pt_normal = make_soma(soma_3pt_normal_pts, soma_class=SOMA_CYLINDER)

#increasing radius, multiple cylinders
soma_4pt_normal_pts = np.array([
    [0.0, 0.0, 0.0, 1.0, 1, 1, -1],
    [0.0, -10.0, 0.0, 2.0, 1, 2, 1],
    [0.0, -10.0, -10.0, 3.0, 1, 3, 2],
    [-10.0, -10.0, -10.0, 4.0, 1, 4, 3],
예제 #13
0
def test_make_Soma_ThreePoint():
    sm = _soma.make_soma(SOMA_THREEPOINTS_PTS)
    nt.ok_('SomaThreePoint' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaThreePoint))
    nt.assert_items_equal(sm.center, (11, 22, 33))
    nt.eq_(sm.radius, 0.0)
예제 #14
0
def test_make_Soma_SinglePoint():
    sm = _soma.make_soma(SOMA_SINGLE_PTS)
    nt.ok_('SomaSinglePoint' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaSinglePoint))
    nt.assert_items_equal(sm.center, (11, 22, 33))
    nt.ok_(sm.radius == 44)
예제 #15
0
def test_make_Soma_Cylinders():
    points = [[0, 0, -10, 40],
              [0, 0,   0, 40],
              [0, 0,  10, 40],
              ]
    s = _soma.SomaCylinders(points)
    # if r = 2*h (ie: as in this case 10 - -10 == 20), then the
    # area of a cylinder (excluding end caps) is:
    # 2*pi*r*h == 4*pi*r^2 == area of a sphere of radius 20
    nt.eq_(s.radius, 20.0)
    nt.assert_almost_equal(s.area, 5026.548245743669)
    nt.eq_(s.center, [0, 0, -10])
    nt.ok_('SomaCylinders' in str(s))

    # cylinder: h = 10, r = 20
    soma_2pt_normal = np.array([
        [0.0,   0.0,  0.0, 20.0, 1, 1, -1],
        [0.0, -10.0,  0.0, 20.0, 1, 2,  1],
    ])
    s = _soma.make_soma(soma_2pt_normal, soma_class=_soma.SOMA_CYLINDER)
    nt.assert_almost_equal(s.area, 1256.6370614) # see r = 2*h above
    nt.eq_(list(s.center), [0., 0., 0.])

    #check tapering
    soma_2pt_normal = np.array([
        [0.0,   0.0,  0.0, 0.0, 1, 1, -1],
        [0.0, -10.0,  0.0, 20.0, 1, 2,  1],
    ])
    s = _soma.make_soma(soma_2pt_normal, soma_class=_soma.SOMA_CYLINDER)
    nt.assert_almost_equal(s.area, 1404.9629462081452) # cone area, not including 'bottom'

    # neuromorpho style
    soma_3pt_neuromorpho = np.array([
        [0.0,   0.0,  0.0, 10.0, 1, 1, -1],
        [0.0, -10.0,  0.0, 10.0, 1, 2,  1],
        [0.0,   10.0, 0.0, 10.0, 1, 3,  1],
    ])
    s = _soma.make_soma(soma_3pt_neuromorpho, soma_class=_soma.SOMA_CYLINDER)
    nt.ok_('SomaNeuromorphoThreePointCylinders' in str(s))
    nt.eq_(list(s.center), [0., 0., 0.])
    nt.assert_almost_equal(s.area, 1256.6370614)

    # some neuromorpho files don't follow the convention
    #but have (ys + rs) as point 2, and have xs different in each line
    # ex: http://neuromorpho.org/dableFiles/brumberg/CNG%20version/april11s1cell-1.CNG.swc
    soma_3pt_neuromorpho = np.array([
        [ 0.0,   0.0,  0.0, 10.0, 1, 1, -1],
        [-2.0,   6.0,  0.0, 10.0, 1, 2,  1],
        [ 2.0,  -6.0,  0.0, 10.0, 1, 3,  1],
    ])
    s = _soma.make_soma(soma_3pt_neuromorpho, soma_class=_soma.SOMA_CYLINDER)
    nt.ok_('SomaNeuromorphoThreePointCylinders' in str(s))
    nt.eq_(list(s.center), [0., 0., 0.])
    nt.assert_almost_equal(s.area, 794.76706126368811)

    soma_4pt_normal = np.array([
        [0.0, 0.0,  0.0, 0.0,  1, 1, -1],
        [0.0, 2.0,  0.0, 2.0,  1, 2, 1],
        [0.0, 4.0,  0.0, 4.0,  1, 3, 2],
        [0.0, 6.0,  0.0, 6.0,  1, 4, 3],
        [0.0, 8.0,  0.0, 8.0,  1, 5, 4],
        [0.0, 10.0, 0.0, 10.0, 1, 6, 5],
    ])
    s = _soma.make_soma(soma_4pt_normal, soma_class=_soma.SOMA_CYLINDER)
    nt.eq_(list(s.center), [0., 0., 0.])
    nt.assert_almost_equal(s.area, 444.288293851) # cone area, not including bottom
예제 #16
0
def test_make_Soma_Cylinders():
    points = [
        [0, 0, -10, 40],
        [0, 0, 0, 40],
        [0, 0, 10, 40],
    ]
    s = _soma.SomaCylinders(points)
    # if r = 2*h (ie: as in this case 10 - -10 == 20), then the
    # area of a cylinder (excluding end caps) is:
    # 2*pi*r*h == 4*pi*r^2 == area of a sphere of radius 20
    nt.eq_(s.radius, 20.0)
    nt.assert_almost_equal(s.area, 5026.548245743669)
    nt.eq_(s.center, [0, 0, -10])
    nt.ok_('SomaCylinders' in str(s))

    # cylinder: h = 10, r = 20
    soma_2pt_normal = np.array([
        [0.0, 0.0, 0.0, 20.0, 1, 1, -1],
        [0.0, -10.0, 0.0, 20.0, 1, 2, 1],
    ])
    s = _soma.make_soma(soma_2pt_normal, soma_class=_soma.SOMA_CYLINDER)
    nt.assert_almost_equal(s.area, 1256.6370614)  # see r = 2*h above
    nt.eq_(list(s.center), [0., 0., 0.])

    #check tapering
    soma_2pt_normal = np.array([
        [0.0, 0.0, 0.0, 0.0, 1, 1, -1],
        [0.0, -10.0, 0.0, 20.0, 1, 2, 1],
    ])
    s = _soma.make_soma(soma_2pt_normal, soma_class=_soma.SOMA_CYLINDER)
    nt.assert_almost_equal(
        s.area, 1404.9629462081452)  # cone area, not including 'bottom'

    # neuromorpho style
    soma_3pt_neuromorpho = np.array([
        [0.0, 0.0, 0.0, 10.0, 1, 1, -1],
        [0.0, -10.0, 0.0, 10.0, 1, 2, 1],
        [0.0, 10.0, 0.0, 10.0, 1, 3, 1],
    ])
    with warnings.catch_warnings(record=True):
        s = _soma.make_soma(soma_3pt_neuromorpho,
                            soma_class=_soma.SOMA_CYLINDER)
    nt.ok_('SomaNeuromorphoThreePointCylinders' in str(s))
    nt.eq_(list(s.center), [0., 0., 0.])
    nt.assert_almost_equal(s.area, 1256.6370614)

    # some neuromorpho files don't follow the convention
    #but have (ys + rs) as point 2, and have xs different in each line
    # ex: http://neuromorpho.org/dableFiles/brumberg/CNG%20version/april11s1cell-1.CNG.swc
    soma_3pt_neuromorpho = np.array([
        [0.0, 0.0, 0.0, 10.0, 1, 1, -1],
        [-2.0, 6.0, 0.0, 10.0, 1, 2, 1],
        [2.0, -6.0, 0.0, 10.0, 1, 3, 1],
    ])
    with warnings.catch_warnings(record=True):
        s = _soma.make_soma(soma_3pt_neuromorpho,
                            soma_class=_soma.SOMA_CYLINDER)
    nt.ok_('SomaNeuromorphoThreePointCylinders' in str(s))
    nt.eq_(list(s.center), [0., 0., 0.])
    nt.assert_almost_equal(s.area, 794.76706126368811)

    soma_4pt_normal = np.array([
        [0.0, 0.0, 0.0, 0.0, 1, 1, -1],
        [0.0, 2.0, 0.0, 2.0, 1, 2, 1],
        [0.0, 4.0, 0.0, 4.0, 1, 3, 2],
        [0.0, 6.0, 0.0, 6.0, 1, 4, 3],
        [0.0, 8.0, 0.0, 8.0, 1, 5, 4],
        [0.0, 10.0, 0.0, 10.0, 1, 6, 5],
    ])
    s = _soma.make_soma(soma_4pt_normal, soma_class=_soma.SOMA_CYLINDER)
    nt.eq_(list(s.center), [0., 0., 0.])
    nt.assert_almost_equal(s.area,
                           444.288293851)  # cone area, not including bottom
예제 #17
0
def test_make_Soma_SinglePoint():
    sm = _soma.make_soma(SOMA_SINGLE_PTS)
    nt.ok_('SomaSinglePoint' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaSinglePoint))
    nt.eq_(list(sm.center), [11, 22, 33])
    nt.ok_(sm.radius == 44)
예제 #18
0
def test_make_Soma_SinglePoint():
    sm = _soma.make_soma(SOMA_SINGLE_PTS)
    nt.ok_('SomaSinglePoint' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaSinglePoint))
    nt.eq_(list(sm.center), [11, 22, 33])
    nt.ok_(sm.radius == 44)
예제 #19
0
def test_make_Soma_ThreePointCylinder():
    sm = _soma.make_soma(SOMA_THREEPOINTS_PTS, soma_class=_soma.SOMA_CYLINDER)
    nt.ok_('SomaNeuromorphoThreePointCylinders' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaNeuromorphoThreePointCylinders))
    nt.eq_(list(sm.center), [0, 0, 0])
    nt.eq_(sm.radius, 44)
예제 #20
0
def test_make_Soma_ThreePoint():
    sm = _soma.make_soma(SOMA_THREEPOINTS_PTS)
    nt.ok_('SomaThreePoint' in str(sm))
    nt.ok_(isinstance(sm, _soma.SomaThreePoint))
    nt.eq_(list(sm.center), [11, 22, 33])
    nt.eq_(sm.radius, 0.0)