def _make_simple_tree(): p = [0.0, 0.0, 0.0, 1.0, 1, 1, 1] T = PointTree(p) T1 = T.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 1])) T2 = T1.add_child(PointTree([0.0, 4.0, 0.0, 1.0, 1, 1, 1])) T3 = T2.add_child(PointTree([0.0, 6.0, 0.0, 1.0, 1, 1, 1])) T4 = T3.add_child(PointTree([0.0, 8.0, 0.0, 1.0, 1, 1, 1])) T5 = T.add_child(PointTree([0.0, 0.0, 2.0, 1.0, 1, 1, 1])) T6 = T5.add_child(PointTree([0.0, 0.0, 4.0, 1.0, 1, 1, 1])) T7 = T6.add_child(PointTree([0.0, 0.0, 6.0, 1.0, 1, 1, 1])) T8 = T7.add_child(PointTree([0.0, 0.0, 8.0, 1.0, 1, 1, 1])) return T
def test_principal_direction_extent(): points = np.array([[-10., 0., 0.], [-9., 0., 0.], [9., 0., 0.], [10., 0., 0.]]) tree = PointTree(np.array([points[0][0], points[0][1], points[0][2], 1., 0., 0.])) tree.add_child(PointTree(np.array([points[1][0], points[1][1], points[1][2], 1., 0., 0.]))) tree.children[0].add_child(PointTree(np.array([points[2][0], points[2][1], points[2][2], 1., 0., 0.]))) tree.children[0].add_child(PointTree(np.array([points[3][0], points[3][1], points[3][2], 1., 0., 0.]))) extent = mtr.principal_direction_extent(tree) nt.assert_true(np.allclose(extent, [20., 0., 0.]))
def _make_odd_tree(): ''' The infamous invisible tree. This should fail check in case of integer division in partition ''' p = [0.0, 0.0, 0.0, 0.0, 0, 0, 0] T = PointTree(p) T.add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0])) T.add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0])) T.children[0].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0])) T.children[0].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0])) T.children[1].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0])) T.children[1].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0])) T.children[1].children[0].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0])) T.children[1].children[0].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0])) return T
def test_principal_directions_extents(): points = np.array([[-10., 0., 0.], [-9., 0., 0.], [9., 0., 0.], [10., 0., 0.]]) tree = PointTree(np.array([points[0][0], points[0][1], points[0][2], 1., 0., 0.])) tree.add_child(PointTree(np.array([points[1][0], points[1][1], points[1][2], 1., 0., 0.]))) tree.children[0].add_child(PointTree(np.array([points[2][0], points[2][1], points[2][2], 1., 0., 0.]))) tree.children[0].add_child(PointTree(np.array([points[3][0], points[3][1], points[3][2], 1., 0., 0.]))) neurites = [tree, tree, tree] extents0 = get_feat('principal_direction_extents', neurites, direction='first') nt.assert_true(np.allclose(extents0, [20., 20., 20.])) extents1 = get_feat('principal_direction_extents', neurites, direction='second') nt.assert_true(np.allclose(extents1, [0., 0., 0.])) extents2 = get_feat('principal_direction_extents', neurites, direction='third') nt.assert_true(np.allclose(extents2, [0., 0., 0.]))
def _make_tree(): '''This tree has 3 branching points''' p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2] T = PointTree(p) T1 = T.add_child(PointTree([0.0, 1.0, 0.0, 2.0, 1, 1, 2])) T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 3.0, 1, 1, 2])) T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 4.0, 1, 1, 2])) T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 5.0, 1, 1, 2])) T5 = T4.add_child(PointTree([2.0, 5.0, 0.0, 6.0, 1, 1, 2])) T6 = T4.add_child(PointTree([0.0, 5.0, 2.0, 7.0, 1, 1, 2])) return T
def _make_neuron_tree(): p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2] T = PointTree(p) T1 = T.add_child(PointTree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T4.add_child(PointTree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6 = T4.add_child(PointTree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(PointTree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(PointTree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T9.add_child(PointTree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) return T
def _form_branching_tree(): p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2] T = PointTree(p) T1 = T.add_child(PointTree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T4.add_child(PointTree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6 = T4.add_child(PointTree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(PointTree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(PointTree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T9.add_child(PointTree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) T11 = T9.add_child(PointTree([0.0, 6.0, 4.0, 0.75, 1, 1, 2])) T33 = T3.add_child(PointTree([1.0, 5.0, 0.0, 2.0, 1, 1, 2])) T331 = T33.add_child(PointTree([15.0, 15.0, 0.0, 2.0, 1, 1, 2])) return T
def _make_branching_tree_zero_length_bif_segments(): '''This tree has 3 branching points''' p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2] T = PointTree(p) T1 = T.add_child(PointTree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5_0 = T4.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T5_0.add_child(PointTree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6_0 = T4.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T6 = T6_0.add_child(PointTree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(PointTree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(PointTree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10_0 = T9.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T10_0.add_child(PointTree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) T11 = T9.add_child(PointTree([0.0, 6.0, 4.0, 0.75, 1, 1, 2])) T33 = T3.add_child(PointTree([1.0, 5.0, 0.0, 2.0, 1, 1, 2])) T331 = T33.add_child(PointTree([15.0, 15.0, 0.0, 2.0, 1, 1, 2])) return T
import numpy as np from nose import tools as nt from neurom.point_neurite.point_tree import PointTree from neurom.point_neurite.core import Neuron from neurom.core import make_soma from neurom.core import NeuriteType from neurom.point_neurite.treefunc import set_tree_type import neurom.point_neurite.dendrogram as dm TREE = PointTree(np.array([0., 0., 0., 10., 4., 0., 0.])) TREE.add_child(PointTree(np.array([3., 3., 3., 9., 4., 0., 0.]))) TREE.children[0].add_child(PointTree(np.array([10., 10., 10., 5., 4., 0., 0.]))) TREE.children[0].add_child(PointTree(np.array([-10., -10., -10., 7., 4., 0., 0.]))) set_tree_type(TREE) SOMA = make_soma(np.array([[0., 0., 0., 1., 1., 1., -1.]])) NEURON = Neuron(SOMA, [TREE, TREE, TREE]) OLD_OFFS = [1.2, -1.2] NEW_OFFS = [2.3, -2.3] SPACING = (40., 0.) def test_n_rectangles_tree(): nt.assert_equal(dm._n_rectangles(TREE), 5)
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from nose import tools as nt import os from neurom.point_neurite.core import iter_neurites from neurom.point_neurite import io from neurom.point_neurite.io.utils import make_neuron from neurom.point_neurite.point_tree import PointTree, isection from neurom.point_neurite import segments as seg from neurom.point_neurite import sections as sec # Mock tree holding integers, not points MOCK_TREE = PointTree(0) MOCK_TREE.add_child(PointTree(11)) MOCK_TREE.add_child(PointTree(12)) MOCK_TREE.children[0].add_child(PointTree(111)) MOCK_TREE.children[0].add_child(PointTree(112)) MOCK_TREE.children[1].add_child(PointTree(121)) MOCK_TREE.children[1].add_child(PointTree(122)) MOCK_TREE.children[1].children[0].add_child(PointTree(1211)) MOCK_TREE.children[1].children[0].children[0].add_child(PointTree(12111)) MOCK_TREE.children[1].children[0].children[0].add_child(PointTree(12112)) class MockNeuron(object): pass DATA_PATH = './test_data'
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from nose import tools as nt from copy import deepcopy from neurom.core._neuron import Neuron from neurom.core import make_soma from neurom.point_neurite.point_tree import PointTree from neurom.point_neurite.point_tree import val_iter from itertools import izip import numpy as np SOMA_SINGLE_PTS = [[11, 22, 33, 44, 1, 1, -1]] TREE = PointTree([0.0, 0.0, 0.0, 1.0, 1, 1, 2]) T1 = TREE.add_child(PointTree([0.0, 1.0, 0.0, 1.0, 1, 1, 2])) T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 2])) T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 2.0, 1, 1, 2])) T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2])) T5 = T4.add_child(PointTree([2.0, 5.0, 0.0, 1.0, 1, 1, 2])) T6 = T4.add_child(PointTree([0.0, 5.0, 2.0, 1.0, 1, 1, 2])) T7 = T5.add_child(PointTree([3.0, 5.0, 0.0, 0.75, 1, 1, 2])) T8 = T7.add_child(PointTree([4.0, 5.0, 0.0, 0.75, 1, 1, 2])) T9 = T6.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2])) T10 = T9.add_child(PointTree([0.0, 6.0, 3.0, 0.75, 1, 1, 2])) def test_deep_copy(): soma = make_soma([[0, 0, 0, 1, 1, 1, -1]]) nrn1 = Neuron(soma, [TREE])
def test_trunk_section_length(): t = PointTree((0, 0, 0, 42)) tt = t.add_child(PointTree((10, 0, 0, 4))) tt.add_child(PointTree((10, 15, 0, 4))) nt.assert_almost_equal(mtr.trunk_section_length(t), 25.0)
def test_trunk_origin_radius(): t = PointTree((0, 0, 0, 42)) t.add_child(PointTree((1, 0, 0, 4))) nt.assert_equal(mtr.trunk_origin_radius(t), 42.0)
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] tree_types = [NeuriteType.axon, NeuriteType.basal_dendrite, NeuriteType.basal_dendrite, NeuriteType.apical_dendrite] # Mock tree holding integers, not points MOCK_TREE = PointTree(0) MOCK_TREE.add_child(PointTree(11)) MOCK_TREE.add_child(PointTree(12)) MOCK_TREE.children[0].add_child(PointTree(111)) MOCK_TREE.children[0].add_child(PointTree(112)) MOCK_TREE.children[1].add_child(PointTree(121)) MOCK_TREE.children[1].add_child(PointTree(122)) MOCK_TREE.children[1].children[0].add_child(PointTree(1211)) MOCK_TREE.children[1].children[0].children[0].add_child(PointTree(12111)) MOCK_TREE.children[1].children[0].children[0].add_child(PointTree(12112)) T1111 = MOCK_TREE.children[0].children[0].add_child(PointTree(1111)) T11111 = T1111.add_child(PointTree(11111)) T11112 = T1111.add_child(PointTree(11112)) T11113 = T1111.add_child(PointTree(11113)) REF_TREE3 = PointTree(np.array([0.,0.,0.,1.,0.,0.,0.])) REF_TREE3.add_child(PointTree(np.array([1.,1.,1.,1.,0.,0.,0.])))