Example #1
0
    def volume(self):
        '''Return the volume of this section.

        The volume is calculated from the segments, as defined by this
        section's points
        '''
        return sum(morphmath.segment_volume(s) for s in iter_segments(self))
Example #2
0
    def save_morph_data(self, morph_stats_filename):

        if not os.path.exists(morph_stats_filename):

            #  load a neuron from an SWC file
            nrn = nm.load_neuron(self.morph_file)

            morph_stats = {}

            morph_stats['cell_id'] = self.cell_id
            morph_stats['soma_suface'] = nm.get('soma_surface_areas', nrn)[0]
            morph_stats['soma_radius'] = np.mean(nm.get('soma_radii', nrn))

            # Morph stats
            for nrn_type_ in NEURITES:

                morph_stats['length' + '.' +
                            str(nrn_type_).split('.')[1]] = np.sum(
                                nm.get('segment_lengths',
                                       nrn,
                                       neurite_type=nrn_type_))
                morph_stats['area' + '.' + str(nrn_type_).split('.')[1]] = sum(
                    mm.segment_area(s) for s in nm.iter_segments(
                        nrn, neurite_filter=tree_type_checker(nrn_type_)))
                morph_stats[
                    'volume' + '.' + str(nrn_type_).split('.')[1]] = sum(
                        mm.segment_volume(s) for s in nm.iter_segments(
                            nrn, neurite_filter=tree_type_checker(nrn_type_)))
                morph_stats['taper_rate' + '.' + str(nrn_type_).split('.')[1]] = \
                    np.mean([mm.segment_taper_rate(s) for s in nm.iter_segments(
                        nrn, neurite_filter=tree_type_checker(nrn_type_))])

            utility.save_json(morph_stats_filename, morph_stats)
Example #3
0
    def volume(self):
        """Return the volume of this section.

        The volume is calculated from the segments, as defined by this
        section's points
        """
        return sum(morphmath.segment_volume(s) for s in iter_segments(self))
Example #4
0
def test_segment_volume():
    p0 = Point(0.0, 0.0, 0.0, 3.0)
    p1 = Point(2.0, 0.0, 0.0, 3.0)
    p2 = Point(4.0, 0.0, 0.0, 3.0)
    p3 = Point(4.0, 0.0, 0.0, 6.0)
    p4 = Point(1.0, 0.0, 0.0, 3.0)
    p5 = Point(4.0, 0.0, 0.0, 3.0)

    v01 = mm.segment_volume((p0, p1))
    v02 = mm.segment_volume((p0, p2))
    v03 = mm.segment_volume((p0, p3))
    v04 = mm.segment_volume((p0, p4))
    v45 = mm.segment_volume((p4, p5))
    v05 = mm.segment_volume((p0, p5))

    assert_almost_equal(v01, 56.5486677, decimal=6)
    assert_almost_equal(2 * v01, v02)
    assert_almost_equal(v03, 263.8937829, decimal=6)
    assert_almost_equal(v45, v05 - v04)
    assert_almost_equal(mm.segment_volume((p0, p3)), mm.segment_volume((p3, p0)))
Example #5
0
def test_segment_volume():
    p0 = Point(0.0, 0.0, 0.0, 3.0, 1)
    p1 = Point(2.0, 0.0, 0.0, 3.0, 1)
    p2 = Point(4.0, 0.0, 0.0, 3.0, 1)
    p3 = Point(4.0, 0.0, 0.0, 6.0, 1)
    p4 = Point(1.0, 0.0, 0.0, 3.0, 1)
    p5 = Point(4.0, 0.0, 0.0, 3.0, 1)

    v01 = mm.segment_volume((p0, p1))
    v02 = mm.segment_volume((p0, p2))
    v03 = mm.segment_volume((p0, p3))
    v04 = mm.segment_volume((p0, p4))
    v45 = mm.segment_volume((p4, p5))
    v05 = mm.segment_volume((p0, p5))

    nt.assert_almost_equal(v01, 56.5486677, places=6)
    nt.assert_almost_equal(2*v01, v02)
    nt.assert_almost_equal(v03, 263.8937829, places=6)
    nt.assert_almost_equal(v45, v05 - v04)
    nt.assert_almost_equal(mm.segment_volume((p0, p3)), mm.segment_volume((p3, p0)))
Example #6
0
 def _func(sec):
     '''list of segment volumes of a section'''
     return [morphmath.segment_volume(seg) for seg in zip(sec.points[:-1], sec.points[1:])]
Example #7
0
 def volume(self):
     return sum(
         morphmath.segment_volume((p0, p1))
         for p0, p1 in zip(self.points, self.points[1:]))
Example #8
0
 def volume(self):
     """Return the volume of soma."""
     return sum(morphmath.segment_volume((p0, p1))
                for p0, p1 in zip(self.points, self.points[1:]))
Example #9
0
        """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)
        # Non-root sections have duplicate first point
        return n if sec.parent is None else n - 1

    print('Total number of points:',
          sum(n_points(s) for s in nm.iter_sections(nrn)))
Example #10
0
 def _func(sec):
     '''list of segment volumes of a section'''
     return [morphmath.segment_volume(seg) for seg in zip(sec.points[:-1], sec.points[1:])]
        '''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)
        # Non-root sections have duplicate first point
        return n if sec.parent is None else n - 1

    print('Total number of points:',
          sum(n_points(s) for s in nm.iter_sections(nrn)))