def area(self): '''Return the surface area of this section. The area is calculated from the segments, as defined by this section's points ''' return sum(morphmath.segment_area(s) for s in iter_segments(self))
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)
def __init__(self, points): """Initialize a SomaCyliners object.""" super().__init__(points) self.area = sum( morphmath.segment_area((p0, p1)) for p0, p1 in zip(points, points[1:])) self.radius = math.sqrt(self.area / (4. * math.pi))
def area(self): """Return the surface area of this section. The area is calculated from the segments, as defined by this section's points """ return sum(morphmath.segment_area(s) for s in iter_segments(self))
def soma_to_single_point(soma): '''surface preserving cylindrical soma to a single point sphere''' logger.info('Converting soma to a single point sphere, while preserving the surface') neurom_points = np.hstack((soma.points, 0.5 * soma.diameters[:, None])) surface_area = sum(morphmath.segment_area(seg) for seg in zip(neurom_points[1:], neurom_points[:-1])) soma.points = np.mean(soma.points, axis=0)[None, :] soma.diameters = [float((surface_area / np.pi) ** 0.5)]
def test_segment_area(): 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) a01 = mm.segment_area((p0, p1)) a02 = mm.segment_area((p0, p2)) a03 = mm.segment_area((p0, p3)) a04 = mm.segment_area((p0, p4)) a45 = mm.segment_area((p4, p5)) a05 = mm.segment_area((p0, p5)) assert_almost_equal(a01, 37.6991118, decimal=6) assert_almost_equal(2 * a01, a02) assert_almost_equal(a03, 141.3716694, decimal=6) assert_almost_equal(a45, a05 - a04) assert_almost_equal(mm.segment_area((p0, p3)), mm.segment_area((p3, p0)))
def test_segment_area(): 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) a01 = mm.segment_area((p0, p1)) a02 = mm.segment_area((p0, p2)) a03 = mm.segment_area((p0, p3)) a04 = mm.segment_area((p0, p4)) a45 = mm.segment_area((p4, p5)) a05 = mm.segment_area((p0, p5)) nt.assert_almost_equal(a01, 37.6991118, places=6) nt.assert_almost_equal(2*a01, a02) nt.assert_almost_equal(a03, 141.3716694, places=6) nt.assert_almost_equal(a45, a05 - a04) nt.assert_almost_equal(mm.segment_area((p0, p3)), mm.segment_area((p3, p0)))
def __init__(self, points): super(SomaCylinders, self).__init__(points) self.area = sum( morphmath.segment_area((p0, p1)) for p0, p1 in zip(points, points[1:])) self.radius = math.sqrt(self.area / (4. * math.pi))
def __init__(self, points): super(SomaCylinders, self).__init__(points) self.area = sum(morphmath.segment_area((p0, p1)) for p0, p1 in zip(points, points[1:])) self.radius = math.sqrt(self.area / (4. * math.pi))
def segment_areas(neurites, neurite_type=NeuriteType.all): """Areas of the segments in a collection of neurites.""" return [morphmath.segment_area(seg) for seg in iter_segments(neurites, is_type(neurite_type))]
# 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))) # get mean radius of neurite points in cell. # p[COLS.R] yields the radius for point p. # Note: this includes duplicated points at beginning of # non-trunk sections
# 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))) # get mean radius of neurite points in cell. # p[COLS.R] yields the radius for point p. # Note: this includes duplicated points at beginning of # non-trunk sections