Beispiel #1
0
def test_make_neuron_post_tree_action():
    def post_action(t):
        t.bar = 'foo'

    rd = RAW_DATA[0]
    nrn = utils.make_neuron(rd, post_action)
    for t in nrn.neurites:
        nt.ok_(hasattr(t, 'bar') and t.bar == 'foo')
Beispiel #2
0
def test_make_neuron_post_tree_action():
    def post_action(t):
        t.bar = 'foo'

    rd = RAW_DATA[0]
    nrn = utils.make_neuron(rd, post_action)
    for t in nrn.neurites:
        nt.ok_(hasattr(t, 'bar') and t.bar == 'foo')
Beispiel #3
0
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''Calculate inter-segment angles'''

import logging
import numpy as np
from neurom.core.dataformat import COLS
from neurom.io.readers import load_data
from neurom.io.utils import make_neuron
from neurom.analysis.morphtree import i_segment_meander_angle

# root level logger. This would be a top level application logger.
logging.basicConfig()
LOG = logging.getLogger()
LOG.setLevel(logging.DEBUG)
fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
LOG.handlers[0].setFormatter(fmt)

if __name__ == '__main__':

    filename = 'test_data/swc/Neuron.swc'
    rd = load_data(filename)
    nrn = make_neuron(rd)

    for tt in nrn.neurites:
        print 'Tree ID: {0}, type: {1}'.format(tt.value[COLS.ID],
                                               tt.value[COLS.TYPE])
        for a in i_segment_meander_angle(tt):
            LOG.debug('Angle %f', a)
            if np.isnan(a):
                LOG.warn('Found NaN angle. Check for zero length segments!')
Beispiel #4
0
from neurom import segments as seg
from neurom import iter_neurites

import math
from itertools import izip


class MockNeuron(object):
    pass


DATA_PATH = './test_data'
SWC_PATH = os.path.join(DATA_PATH, 'swc/')

data    = io.load_data(SWC_PATH + 'Neuron.swc')
neuron0 = make_neuron(data)
tree0   = neuron0.neurites[0]

def _make_neuron_tree():
    p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2]
    T = Tree(p)
    T1 = T.add_child(Tree([0.0, 1.0, 0.0, 1.0, 1, 1, 2]))
    T2 = T1.add_child(Tree([0.0, 2.0, 0.0, 1.0, 1, 1, 2]))
    T3 = T2.add_child(Tree([0.0, 4.0, 0.0, 2.0, 1, 1, 2]))
    T4 = T3.add_child(Tree([0.0, 5.0, 0.0, 2.0, 1, 1, 2]))
    T5 = T4.add_child(Tree([2.0, 5.0, 0.0, 1.0, 1, 1, 2]))
    T6 = T4.add_child(Tree([0.0, 5.0, 2.0, 1.0, 1, 1, 2]))
    T7 = T5.add_child(Tree([3.0, 5.0, 0.0, 0.75, 1, 1, 2]))
    T8 = T7.add_child(Tree([4.0, 5.0, 0.0, 0.75, 1, 1, 2]))
    T9 = T6.add_child(Tree([0.0, 5.0, 3.0, 0.75, 1, 1, 2]))
    T10 = T9.add_child(Tree([0.0, 6.0, 3.0, 0.75, 1, 1, 2]))
Beispiel #5
0
from neurom.analysis.morphtree import n_terminations
from neurom.analysis.morphtree import trunk_radius
from neurom.analysis.morphtree import trunk_length
from neurom.analysis.morphtree import trunk_direction
from neurom.analysis.morphtree import trunk_elevation
from neurom.analysis.morphtree import trunk_azimuth
from neurom.analysis.morphtree import get_bounding_box
import math
import numpy as np
from itertools import izip

DATA_PATH = './test_data'
SWC_PATH = os.path.join(DATA_PATH, 'swc/')

data    = load_data(SWC_PATH + 'Neuron.swc')
neuron0 = make_neuron(data)
tree0   = neuron0.neurites[0]
tree_types = [TreeType.axon,
              TreeType.basal_dendrite,
              TreeType.basal_dendrite,
              TreeType.apical_dendrite]


# Mock tree holding integers, not points
MOCK_TREE = Tree(0)
MOCK_TREE.add_child(Tree(11))
MOCK_TREE.add_child(Tree(12))
MOCK_TREE.children[0].add_child(Tree(111))
MOCK_TREE.children[0].add_child(Tree(112))
MOCK_TREE.children[1].add_child(Tree(121))
MOCK_TREE.children[1].add_child(Tree(122))
Beispiel #6
0
'''Calculate inter-segment angles'''

import logging
import numpy as np
from neurom.core.dataformat import COLS
from neurom.io.readers import load_data
from neurom.io.utils import make_neuron
from neurom.analysis.morphtree import i_segment_meander_angle


# root level logger. This would be a top level application logger.
logging.basicConfig()
LOG = logging.getLogger()
LOG.setLevel(logging.DEBUG)
fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
LOG.handlers[0].setFormatter(fmt)


if __name__ == '__main__':

    filename = 'test_data/swc/Neuron.swc'
    rd = load_data(filename)
    nrn = make_neuron(rd)

    for tt in nrn.neurites:
        print 'Tree ID: {0}, type: {1}'.format(tt.value[COLS.ID], tt.value[COLS.TYPE])
        for a in i_segment_meander_angle(tt):
            LOG.debug('Angle %f', a)
            if np.isnan(a):
                LOG.warn('Found NaN angle. Check for zero length segments!')
Beispiel #7
0
    soma = neuron.make_soma([rd.get_row(si) for si in get_soma_ids(rd)])

    for tr in trees:
        for p in point_iter(tree.ipreorder(tr)):
            print p

    print 'Initial segment IDs:', init_seg_ids

    nrn = neuron.Neuron(soma, trees)

    print 'Neuron soma raw data', [r for r in nrn.soma.iter()]
    print 'Neuron soma points', [as_point(p) for p in nrn.soma.iter()]

    print 'Neuron tree init points, types'
    for tt in nrn.neurites:
        print tt.value[COLS.ID], tt.value[COLS.TYPE]

    print 'Making neuron 2'
    nrn2 = make_neuron(rd)
    print 'Neuron 2 soma points', [r for r in nrn2.soma.iter()]
    print 'Neuron 2 soma points', [as_point(p) for p in nrn2.soma.iter()]
    print 'Neuron 2 tree init points, types'
    for tt in nrn2.neurites:
        print tt.value[COLS.ID], tt.value[COLS.TYPE]

    print 'Print neuron leaves as points'
    for tt in nrn2.neurites:
        for p in point_iter(tree.ileaf(tt)):
            print p
Beispiel #8
0
def test_make_neuron_no_soma_raises_SomaError():
    utils.make_neuron(NO_SOMA_RAW_DATA)
Beispiel #9
0
def test_make_neuron():
    rd = RAW_DATA[0]
    nrn = utils.make_neuron(rd)
    nt.ok_(np.all([s[COLS.ID] for s in nrn.soma.iter()] == SOMA_IDS[0]))
    _check_trees(nrn.neurites)
Beispiel #10
0
    for tr in trees:
        for p in point_iter(tree.ipreorder(tr)):
            LOG.debug(p)

    LOG.info('Initial segment IDs: %s', init_seg_ids)

    nrn = neuron.Neuron(soma, trees)

    LOG.info('Neuron soma raw data % s', [r for r in nrn.soma.iter()])
    LOG.info('Neuron soma points %s', [as_point(p)
                                       for p in nrn.soma.iter()])

    LOG.info('Neuron tree init points, types')
    for tt in nrn.neurites:
        LOG.info('%s, %s', tt.value[COLS.ID], tt.value[COLS.TYPE])

    LOG.info('Making neuron 2')
    nrn2 = make_neuron(rd)
    LOG.debug('Neuron 2 soma points %s', [r for r in nrn2.soma.iter()])
    LOG.debug('Neuron 2 soma points %s', [as_point(p)
                                          for p in nrn2.soma.iter()])
    LOG.info('Neuron 2 tree init points, types')
    for tt in nrn2.neurites:
        LOG.info('%s %s', tt.value[COLS.ID], tt.value[COLS.TYPE])

    LOG.debug('Print neuron leaves as points')
    for tt in nrn2.neurites:
        for p in point_iter(tree.ileaf(tt)):
            LOG.debug(p)
Beispiel #11
0
def test_make_neuron_no_soma_raises_SomaError():
    utils.make_neuron(NO_SOMA_RAW_DATA)
Beispiel #12
0
def test_make_neuron():
    rd = RAW_DATA[0]
    nrn = utils.make_neuron(rd)
    nt.ok_(np.all([s[COLS.ID] for s in nrn.soma.iter()] == SOMA_IDS[0]))
    _check_trees(nrn.neurites)
Beispiel #13
0
from nose import tools as nt
from neurom.io.utils import make_neuron
from neurom.io.utils import load_neuron
from neurom.io.readers import load_data
from neurom.view import view
from neurom.analysis.morphtree import find_tree_type
import os
import numpy as np
import pylab as plt


DATA_PATH = './test_data'
SWC_PATH = os.path.join(DATA_PATH, 'swc/')

data = load_data(SWC_PATH + 'Neuron.swc')
neuron0 = make_neuron(data, find_tree_type)
soma0 = neuron0.soma


def test_tree():
    axes = []
    for tree in neuron0.neurites:
        fig, ax = view.tree(tree)
        axes.append(ax)
    nt.ok_(axes[0].get_data_ratio() > 1.00 )
    nt.ok_(axes[1].get_data_ratio() > 0.80 )
    nt.ok_(axes[2].get_data_ratio() > 1.00 )
    nt.ok_(axes[3].get_data_ratio() > 0.85 )
    tree0 = neuron0.neurites[0]
    fig, ax = view.tree(tree0, treecolor='black', diameter=False, alpha=1., linewidth=1.2)
    c = ax.collections[0]