Beispiel #1
0
def test_trunk_origin_elevations():
    class Mock(object):
        pass

    n0 = Mock()
    n1 = Mock()

    s = make_soma([[0, 0, 0, 4]])
    t0 = Section(((1, 0, 0, 2), (2, 1, 1, 2)))
    t0.type = NeuriteType.basal_dendrite
    t1 = Section(((0, 1, 0, 2), (1, 2, 1, 2)))
    t1.type = NeuriteType.basal_dendrite
    n0.neurites = [Neurite(t0), Neurite(t1)]
    n0.soma = s

    t2 = Section(((0, -1, 0, 2), (-1, -2, -1, 2)))
    t2.type = NeuriteType.basal_dendrite
    n1.neurites = [Neurite(t2)]
    n1.soma = s

    pop = Population([n0, n1])
    nt.eq_(list(_nf.trunk_origin_elevations(pop)),
           [0.0, np.pi/2., -np.pi/2.])

    nt.eq_(
        list(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.basal_dendrite)),
        [0.0, np.pi/2., -np.pi/2.])

    nt.eq_(len(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.axon)),
           0)

    nt.eq_(len(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.apical_dendrite)),
           0)
Beispiel #2
0
def test_trunk_origin_elevations():
    n0 = load_neuron(StringIO(u"""
    1 1 0 0 0 4 -1
    2 3 1 0 0 2 1
    3 3 2 1 1 2 2
    4 3 0 1 0 2 1
    5 3 1 2 1 2 4
    """), reader='swc')

    n1 = load_neuron(StringIO(u"""
    1 1 0 0 0 4 -1
    2 3 0 -1 0 2 1
    3 3 -1 -2 -1 2 2
    """), reader='swc')

    pop = Population([n0, n1])
    assert_array_equal(_nf.trunk_origin_elevations(pop),
                       [0.0, np.pi/2., -np.pi/2.])

    assert_array_equal(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.basal_dendrite),
                       [0.0, np.pi/2., -np.pi/2.])

    assert_array_equal(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.axon),
                       [])

    assert_array_equal(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.apical_dendrite),
                       [])
def test_segment_radial_distances_origin():
    origin = (-100, -200, -300)
    ref_segs = nf.segment_radial_distances(NEURON)
    ref_segs_origin = nf.segment_radial_distances(NEURON, origin=origin)

    rad_dists = get_feature('segment_radial_distances', NEURON)
    rad_dists_origin = get_feature('segment_radial_distances',
                                   NEURON,
                                   origin=origin)

    nt.ok_(np.all(rad_dists == ref_segs))
    nt.ok_(np.all(rad_dists_origin == ref_segs_origin))
    nt.ok_(np.all(rad_dists_origin != ref_segs))

    nrns = [
        nm.load_neuron(Path(SWC_PATH, f))
        for f in ('point_soma_single_neurite.swc',
                  'point_soma_single_neurite2.swc')
    ]
    pop = Population(nrns)
    rad_dist_nrns = []
    for nrn in nrns:
        rad_dist_nrns.extend(nm.get('segment_radial_distances', nrn))

    rad_dist_nrns = np.array(rad_dist_nrns)
    rad_dist_pop = nm.get('segment_radial_distances', pop)
    assert_allclose(rad_dist_nrns, rad_dist_pop)
Beispiel #4
0
def test_population():
	pop = Population(NEURONS, name='foo')

	nt.assert_equal(len(pop.neurons), 3)
	nt.ok_(pop.neurons[0].name, 'Neuron')
	nt.ok_(pop.neurons[1].name, 'Single_basal')
	nt.ok_(pop.neurons[2].name, 'Neuron_small_radius')

	nt.assert_equal(len(pop.somata), 3)

	nt.assert_equal(len(pop.neurites),TOT_NEURITES)

	nt.assert_equal(pop.name, 'foo')
Beispiel #5
0
def test_section_radial_distances_endpoint():
    ref_sec_rad_dist = nf.section_radial_distances(NEURON)

    rad_dists = fst_get('section_radial_distances', NEURON)

    nt.eq_(len(rad_dists), 84)
    nt.ok_(np.all(rad_dists == ref_sec_rad_dist))

    nrns = [nm.load_neuron(os.path.join(SWC_PATH, f)) for
            f in ('point_soma_single_neurite.swc', 'point_soma_single_neurite2.swc')]
    pop = Population(nrns)
    rad_dist_nrns = [nm.get('section_radial_distances', nrn) for nrn in nrns]
    rad_dist_pop = nm.get('section_radial_distances', pop)
    assert_items_equal(rad_dist_pop, rad_dist_nrns)
Beispiel #6
0
def test_section_radial_distances_endpoint():
    ref_sec_rad_dist = nf.section_radial_distances(NEURON)

    rad_dists = get_feature('section_radial_distances', NEURON)

    assert len(rad_dists) == 84
    assert np.all(rad_dists == ref_sec_rad_dist)

    nrns = [
        nm.load_neuron(Path(SWC_PATH, f))
        for f in ('point_soma_single_neurite.swc',
                  'point_soma_single_neurite2.swc')
    ]
    pop = Population(nrns)
    rad_dist_nrns = [nm.get('section_radial_distances', nrn) for nrn in nrns]
    rad_dist_pop = nm.get('section_radial_distances', pop)
    assert_items_equal(rad_dist_pop, rad_dist_nrns)
Beispiel #7
0
def test_segment_meander_angles_single_section():
    feat = 'segment_meander_angles'

    nrn = nm.load_neuron(StringIO(u"""((CellBody) (0 0 0 0))
                                      ((Dendrite)
                                       (0 0 0 2)
                                       (1 0 0 2)
                                       (1 1 0 2)
                                       (2 1 0 2)
                                       (2 2 0 2)))"""),
                         reader='asc')

    nrt = nrn.neurites[0]
    pop = Population([nrn])

    ref = [math.pi / 2, math.pi / 2, math.pi / 2]

    assert ref == get_feature(feat, nrt).tolist()
    assert ref == get_feature(feat, nrn).tolist()
    assert ref == get_feature(feat, pop).tolist()
Beispiel #8
0
                    load_neuron, fst)
from neurom.fst import get as fst_get
from neurom.fst import NEURITEFEATURES
from neurom.fst import _neuritefunc as nf
from neurom.core.types import tree_type_checker as _is_type
from neurom.exceptions import NeuroMError


_PWD = os.path.dirname(os.path.abspath(__file__))
DATA_PATH = os.path.join(_PWD, '../../../test_data')
NRN_FILES = [os.path.join(DATA_PATH, 'h5/v1', f)
             for f in ('Neuron.h5', 'Neuron_2_branch.h5', 'bio_neuron-001.h5')]

NRNS = load_neurons(NRN_FILES)
NRN = NRNS[0]
POP = Population(NRNS)

NEURITES = (NeuriteType.axon,
            NeuriteType.apical_dendrite,
            NeuriteType.basal_dendrite,
            NeuriteType.all)


def assert_items_equal(a, b):
    nt.eq_(sorted(a), sorted(b))


def assert_features_for_neurite(feat, neurons, expected, exact=True):
    for neurite_type, expected_values in expected.items():
        print('neurite_type: %s' % neurite_type)
Beispiel #9
0
from os.path import join as joinp

from nose import tools as nt
from neurom.core.population import Population
from neurom import load_neuron

_path = os.path.dirname(os.path.abspath(__file__))
DATA_PATH = joinp(_path, '../../../test_data')

NRN1 = load_neuron(joinp(DATA_PATH, 'swc/Neuron.swc'))
NRN2 = load_neuron(joinp(DATA_PATH, 'swc/Single_basal.swc'))
NRN3 = load_neuron(joinp(DATA_PATH, 'swc/Neuron_small_radius.swc'))

NEURONS = [NRN1, NRN2, NRN3]
TOT_NEURITES = sum(len(N.neurites) for N in NEURONS)
POP = Population(NEURONS, name='foo')


def test_population():
    nt.assert_equal(len(POP.neurons), 3)
    nt.ok_(POP.neurons[0].name, 'Neuron')
    nt.ok_(POP.neurons[1].name, 'Single_basal')
    nt.ok_(POP.neurons[2].name, 'Neuron_small_radius')

    nt.assert_equal(len(POP.somata), 3)

    nt.assert_equal(len(POP.neurites), TOT_NEURITES)

    nt.assert_equal(POP.name, 'foo')