Esempio n. 1
0
def segment_centre_of_mass(seg):
    '''Calculate and return centre of mass of a segment.

    C, seg_volalculated as centre of mass of conical frustum'''
    h = mm.segment_length(seg)
    r0 = seg[0][COLS.R]
    r1 = seg[1][COLS.R]
    num = r0 * r0 + 2 * r0 * r1 + 3 * r1 * r1
    denom = 4 * (r0 * r0 + r0 * r1 + r1 * r1)
    centre_of_mass_z_loc = num / denom
    return seg[0][0:3] + (centre_of_mass_z_loc / h) * (seg[1][0:3] - seg[0][0:3])
Esempio n. 2
0
def segment_centre_of_mass(seg):
    """Calculate and return centre of mass of a segment.

    C, seg_volalculated as centre of mass of conical frustum"""
    h = mm.segment_length(seg)
    r0 = seg[0][COLS.R]
    r1 = seg[1][COLS.R]
    num = r0 * r0 + 2 * r0 * r1 + 3 * r1 * r1
    denom = 4 * (r0 * r0 + r0 * r1 + r1 * r1)
    centre_of_mass_z_loc = num / denom
    return seg[0][COLS.XYZ] + (centre_of_mass_z_loc / h) * (seg[1][COLS.XYZ] - seg[0][COLS.XYZ])
Esempio n. 3
0
    def _generate_dendro(self, current_node, spacing, offsets):
        '''Recursive function for dendrogram line computations
        '''
        max_dims = self._max_dims
        start_x = _spacingx(current_node, max_dims, offsets[0], spacing[0])

        radii = [0., 0.]
        # store the parent radius in order to construct polygonal segments
        # isntead of simple line segments
        radii[0] = current_node.value[COLS.R] if self._show_diameters else 0.

        for child in current_node.children:

            # segment length
            ln = segment_length((current_node.value, child.value))

            # extract the radius of the child node. Need both radius for
            # realistic segment representation
            radii[1] = child.value[COLS.R] if self._show_diameters else 0.

            # number of leaves in child
            terminations = n_terminations(child)

            # horizontal spacing with respect to the number of
            # terminations
            new_offsets = _update_offsets(start_x, spacing, terminations, offsets, ln)

            # create and store vertical segment
            self._rectangles[self._n] = _vertical_segment(offsets, new_offsets, spacing, radii)

            # assign segment id to color array
            # colors[n[0]] = child.value[4]
            self._n += 1

            if offsets[1] + spacing[1] * 2 + ln > max_dims[1]:
                max_dims[1] = offsets[1] + spacing[1] * 2. + ln

            self._max_dims = max_dims
            # recursive call to self.
            self._generate_dendro(child, spacing, new_offsets)

            # update the starting position for the next child
            start_x += terminations * spacing[0]

            # write the horizontal lines only for bifurcations, where the are actual horizontal
            # lines and not zero ones
            if offsets[0] != new_offsets[0]:

                # horizontal segment. Thickness is either 0 if show_diameters is false
                # or 1. if show_diameters is true
                self._rectangles[self._n] = _horizontal_segment(offsets, new_offsets, spacing, 0.)
                self._n += 1
Esempio n. 4
0
def has_all_nonzero_segment_lengths(neuron, threshold=0.0):
    '''Check presence of neuron segments with length not above threshold

    Arguments:
        neuron: Neuron object whose segments will be tested
        threshold: value above which a segment length is considered to be non-zero

    Return:
        status and list of (section_id, segment_id) of zero length segments
    '''
    bad_ids = []
    for sec in _nf.iter_sections(neuron):
        p = sec.points
        for i, s in enumerate(izip(p[:-1], p[1:])):
            if segment_length(s) <= threshold:
                bad_ids.append((sec.id, i))

    return CheckResult(len(bad_ids) == 0, bad_ids)
Esempio n. 5
0
def has_all_nonzero_segment_lengths(neuron, threshold=0.0):
    '''Check presence of neuron segments with length not above threshold

    Arguments:
        neuron(Neuron): The neuron object to test
        threshold(float): value above which a segment length is considered to
        be non-zero

    Returns:
        CheckResult with result including list of (section_id, segment_id)
        of zero length segments
    '''
    bad_ids = []
    for sec in _nf.iter_sections(neuron):
        p = sec.points
        for i, s in enumerate(zip(p[:-1], p[1:])):
            if segment_length(s) <= threshold:
                bad_ids.append((sec.id, i))

    return CheckResult(len(bad_ids) == 0, bad_ids)
Esempio n. 6
0
def test_segment_length():
    assert mm.segment_length(((0, 0, 0), (0, 0, 42))) == 42
    assert mm.segment_length(((0, 0, 0), (0, 42, 0))) == 42
    assert mm.segment_length(((0, 0, 0), (42, 0, 0))) == 42
Esempio n. 7
0
def test_segment_length():
    nt.ok_(mm.segment_length(((0,0,0), (0,0,42))) == 42)
    nt.ok_(mm.segment_length(((0,0,0), (0,42,0))) == 42)
    nt.ok_(mm.segment_length(((0,0,0), (42,0,0))) == 42)
Esempio n. 8
0
    # any function that takes a segment or section.

    # Get of all neurites in cell by iterating over sections,
    # and summing the section lengths
    def sec_len(sec):
        """Return the length of a section."""
        return mm.section_length(sec.points)

    print('Total neurite length (sections):',
          sum(sec_len(s) for s in nm.iter_sections(nrn)))

    # Get length of all neurites in cell by iterating over segments,
    # and summing the segment lengths.
    # This should yield the same result as iterating over sections.
    print('Total neurite length (segments):',
          sum(mm.segment_length(s) for s in nm.iter_segments(nrn)))

    # get volume of all neurites in cell by summing over segment
    # volumes
    print('Total neurite volume:',
          sum(mm.segment_volume(s) for s in nm.iter_segments(nrn)))

    # get area of all neurites in cell by summing over segment
    # areas
    print('Total neurite surface area:',
          sum(mm.segment_area(s) for s in nm.iter_segments(nrn)))

    # get total number of neurite points in cell.
    def n_points(sec):
        """number of points in a section."""
        n = len(sec.points)
    # any function that takes a segment or section.

    # Get of all neurites in cell by iterating over sections,
    # and summing the section lengths
    def sec_len(sec):
        '''Return the length of a section'''
        return mm.section_length(sec.points)

    print('Total neurite length (sections):',
          sum(sec_len(s) for s in nm.iter_sections(nrn)))

    # Get length of all neurites in cell by iterating over segments,
    # and summing the segment lengths.
    # This should yield the same result as iterating over sections.
    print('Total neurite length (segments):',
          sum(mm.segment_length(s) for s in nm.iter_segments(nrn)))

    # get volume of all neurites in cell by summing over segment
    # volumes
    print('Total neurite volume:',
          sum(mm.segment_volume(s) for s in nm.iter_segments(nrn)))

    # get area of all neurites in cell by summing over segment
    # areas
    print('Total neurite surface area:',
          sum(mm.segment_area(s) for s in nm.iter_segments(nrn)))

    # get total number of neurite points in cell.
    def n_points(sec):
        '''number of points in a section'''
        n = len(sec.points)