idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
46,600 | def has_no_fat_ends ( neuron , multiple_of_mean = 2.0 , final_point_count = 5 ) : bad_ids = [ ] for leaf in _nf . iter_sections ( neuron . neurites , iterator_type = Tree . ileaf ) : mean_radius = np . mean ( leaf . points [ 1 : ] [ - final_point_count : , COLS . R ] ) if mean_radius * multiple_of_mean <= leaf . points... | Check if leaf points are too large |
46,601 | def has_no_narrow_start ( neuron , frac = 0.9 ) : bad_ids = [ ( neurite . root_node . id , [ neurite . root_node . points [ 1 ] ] ) for neurite in neuron . neurites if neurite . root_node . points [ 1 ] [ COLS . R ] < frac * neurite . root_node . points [ 2 ] [ COLS . R ] ] return CheckResult ( len ( bad_ids ) == 0 , b... | Check if neurites have a narrow start |
46,602 | def has_no_dangling_branch ( neuron ) : soma_center = neuron . soma . points [ : , COLS . XYZ ] . mean ( axis = 0 ) recentered_soma = neuron . soma . points [ : , COLS . XYZ ] - soma_center radius = np . linalg . norm ( recentered_soma , axis = 1 ) soma_max_radius = radius . max ( ) def is_dangling ( neurite ) : starti... | Check if the neuron has dangling neurites |
46,603 | def has_no_narrow_neurite_section ( neuron , neurite_filter , radius_threshold = 0.05 , considered_section_min_length = 50 ) : considered_sections = ( sec for sec in iter_sections ( neuron , neurite_filter = neurite_filter ) if sec . length > considered_section_min_length ) def narrow_section ( section ) : return secti... | Check if the neuron has dendrites with narrow sections |
46,604 | def transform_header ( mtype_name ) : head_dict = OrderedDict ( ) head_dict [ "m-type" ] = mtype_name head_dict [ "components" ] = defaultdict ( OrderedDict ) return head_dict | Add header to json output to wrap around distribution data . |
46,605 | def draw ( obj , plane = '3d' , inline = False , ** kwargs ) : if plane . lower ( ) == '3d' : return _plot_neuron3d ( obj , inline , ** kwargs ) return _plot_neuron ( obj , plane , inline , ** kwargs ) | Draw the morphology using in the given plane |
46,606 | def _make_trace ( neuron , plane ) : for neurite in iter_neurites ( neuron ) : segments = list ( iter_segments ( neurite ) ) segs = [ ( s [ 0 ] [ COLS . XYZ ] , s [ 1 ] [ COLS . XYZ ] ) for s in segments ] coords = dict ( x = list ( chain . from_iterable ( ( p1 [ 0 ] , p2 [ 0 ] , None ) for p1 , p2 in segs ) ) , y = li... | Create the trace to be plotted |
46,607 | def get_figure ( neuron , plane , title ) : data = list ( _make_trace ( neuron , plane ) ) axis = dict ( gridcolor = 'rgb(255, 255, 255)' , zerolinecolor = 'rgb(255, 255, 255)' , showbackground = True , backgroundcolor = 'rgb(230, 230,230)' ) if plane != '3d' : soma_2d = [ { 'type' : 'circle' , 'xref' : 'x' , 'yref' : ... | Returns the plotly figure containing the neuron |
46,608 | def rotate ( obj , axis , angle , origin = None ) : R = _rodrigues_to_dcm ( axis , angle ) try : return obj . transform ( PivotRotation ( R , origin ) ) except AttributeError : raise NotImplementedError | Rotation around unit vector following the right hand rule |
46,609 | def _sin ( x ) : return 0. if np . isclose ( np . mod ( x , np . pi ) , 0. ) else np . sin ( x ) | sine with case for pi multiples |
46,610 | def _rodrigues_to_dcm ( axis , angle ) : ux , uy , uz = axis / np . linalg . norm ( axis ) uxx = ux * ux uyy = uy * uy uzz = uz * uz uxy = ux * uy uxz = ux * uz uyz = uy * uz sn = _sin ( angle ) cs = _sin ( np . pi / 2. - angle ) cs1 = 1. - cs R = np . zeros ( [ 3 , 3 ] ) R [ 0 , 0 ] = cs + uxx * cs1 R [ 0 , 1 ] = uxy ... | Generates transformation matrix from unit vector and rotation angle . The rotation is applied in the direction of the axis which is a unit vector following the right hand rule . |
46,611 | def total_length ( nrn_pop , neurite_type = NeuriteType . all ) : nrns = _neuronfunc . neuron_population ( nrn_pop ) return list ( sum ( section_lengths ( n , neurite_type = neurite_type ) ) for n in nrns ) | Get the total length of all sections in the group of neurons or neurites |
46,612 | def n_segments ( neurites , neurite_type = NeuriteType . all ) : return sum ( len ( s . points ) - 1 for s in iter_sections ( neurites , neurite_filter = is_type ( neurite_type ) ) ) | Number of segments in a collection of neurites |
46,613 | def n_neurites ( neurites , neurite_type = NeuriteType . all ) : return sum ( 1 for _ in iter_neurites ( neurites , filt = is_type ( neurite_type ) ) ) | Number of neurites in a collection of neurites |
46,614 | def n_sections ( neurites , neurite_type = NeuriteType . all , iterator_type = Tree . ipreorder ) : return sum ( 1 for _ in iter_sections ( neurites , iterator_type = iterator_type , neurite_filter = is_type ( neurite_type ) ) ) | Number of sections in a collection of neurites |
46,615 | def n_bifurcation_points ( neurites , neurite_type = NeuriteType . all ) : return n_sections ( neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point ) | number of bifurcation points in a collection of neurites |
46,616 | def n_forking_points ( neurites , neurite_type = NeuriteType . all ) : return n_sections ( neurites , neurite_type = neurite_type , iterator_type = Tree . iforking_point ) | number of forking points in a collection of neurites |
46,617 | def n_leaves ( neurites , neurite_type = NeuriteType . all ) : return n_sections ( neurites , neurite_type = neurite_type , iterator_type = Tree . ileaf ) | number of leaves points in a collection of neurites |
46,618 | def total_area_per_neurite ( neurites , neurite_type = NeuriteType . all ) : return [ neurite . area for neurite in iter_neurites ( neurites , filt = is_type ( neurite_type ) ) ] | Surface area in a collection of neurites . |
46,619 | def map_sections ( fun , neurites , neurite_type = NeuriteType . all , iterator_type = Tree . ipreorder ) : return map ( fun , iter_sections ( neurites , iterator_type = iterator_type , neurite_filter = is_type ( neurite_type ) ) ) | Map fun to all the sections in a collection of neurites |
46,620 | def section_lengths ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _section_length , neurites , neurite_type = neurite_type ) | section lengths in a collection of neurites |
46,621 | def section_term_lengths ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _section_length , neurites , neurite_type = neurite_type , iterator_type = Tree . ileaf ) | Termination section lengths in a collection of neurites |
46,622 | def section_bif_lengths ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _section_length , neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point ) | Bifurcation section lengths in a collection of neurites |
46,623 | def section_branch_orders ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . branch_order , neurites , neurite_type = neurite_type ) | section branch orders in a collection of neurites |
46,624 | def section_bif_branch_orders ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . branch_order , neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point ) | Bifurcation section branch orders in a collection of neurites |
46,625 | def section_term_branch_orders ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . branch_order , neurites , neurite_type = neurite_type , iterator_type = Tree . ileaf ) | Termination section branch orders in a collection of neurites |
46,626 | def section_path_lengths ( neurites , neurite_type = NeuriteType . all ) : dist = { } neurite_filter = is_type ( neurite_type ) for s in iter_sections ( neurites , neurite_filter = neurite_filter ) : dist [ s ] = s . length def pl2 ( node ) : return sum ( dist [ n ] for n in node . iupstream ( ) ) return map_sections (... | Path lengths of a collection of neurites |
46,627 | def map_neurons ( fun , neurites , neurite_type ) : nrns = _neuronfunc . neuron_population ( neurites ) return [ fun ( n , neurite_type = neurite_type ) for n in nrns ] | Map fun to all the neurites in a single or collection of neurons |
46,628 | def map_segments ( func , neurites , neurite_type ) : neurite_filter = is_type ( neurite_type ) return [ s for ss in iter_sections ( neurites , neurite_filter = neurite_filter ) for s in func ( ss ) ] | Map func to all the segments in a collection of neurites |
46,629 | def segment_volumes ( neurites , neurite_type = NeuriteType . all ) : def _func ( sec ) : return [ morphmath . segment_volume ( seg ) for seg in zip ( sec . points [ : - 1 ] , sec . points [ 1 : ] ) ] return map_segments ( _func , neurites , neurite_type ) | Volumes of the segments in a collection of neurites |
46,630 | def segment_radii ( neurites , neurite_type = NeuriteType . all ) : def _seg_radii ( sec ) : pts = sec . points [ : , COLS . R ] return np . divide ( np . add ( pts [ : - 1 ] , pts [ 1 : ] ) , 2.0 ) return map_segments ( _seg_radii , neurites , neurite_type ) | arithmetic mean of the radii of the points in segments in a collection of neurites |
46,631 | def segment_taper_rates ( neurites , neurite_type = NeuriteType . all ) : def _seg_taper_rates ( sec ) : pts = sec . points [ : , COLS . XYZR ] diff = np . diff ( pts , axis = 0 ) distance = np . linalg . norm ( diff [ : , COLS . XYZ ] , axis = 1 ) return np . divide ( 2 * np . abs ( diff [ : , COLS . R ] ) , distance ... | taper rates of the segments in a collection of neurites |
46,632 | def segment_midpoints ( neurites , neurite_type = NeuriteType . all ) : def _seg_midpoint ( sec ) : pts = sec . points [ : , COLS . XYZ ] return np . divide ( np . add ( pts [ : - 1 ] , pts [ 1 : ] ) , 2.0 ) return map_segments ( _seg_midpoint , neurites , neurite_type ) | Return a list of segment mid - points in a collection of neurites |
46,633 | def local_bifurcation_angles ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _bifurcationfunc . local_bifurcation_angle , neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point ) | Get a list of local bifurcation angles in a collection of neurites |
46,634 | def remote_bifurcation_angles ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( _bifurcationfunc . remote_bifurcation_angle , neurites , neurite_type = neurite_type , iterator_type = Tree . ibifurcation_point ) | Get a list of remote bifurcation angles in a collection of neurites |
46,635 | def bifurcation_partitions ( neurites , neurite_type = NeuriteType . all ) : return map ( _bifurcationfunc . bifurcation_partition , iter_sections ( neurites , iterator_type = Tree . ibifurcation_point , neurite_filter = is_type ( neurite_type ) ) ) | Partition at bifurcation points of a collection of neurites |
46,636 | def partition_asymmetries ( neurites , neurite_type = NeuriteType . all ) : return map ( _bifurcationfunc . partition_asymmetry , iter_sections ( neurites , iterator_type = Tree . ibifurcation_point , neurite_filter = is_type ( neurite_type ) ) ) | Partition asymmetry at bifurcation points of a collection of neurites |
46,637 | def partition_pairs ( neurites , neurite_type = NeuriteType . all ) : return map ( _bifurcationfunc . partition_pair , iter_sections ( neurites , iterator_type = Tree . ibifurcation_point , neurite_filter = is_type ( neurite_type ) ) ) | Partition pairs at bifurcation points of a collection of neurites . Partition pait is defined as the number of bifurcations at the two daughters of the bifurcating section |
46,638 | def section_term_radial_distances ( neurites , neurite_type = NeuriteType . all , origin = None ) : return section_radial_distances ( neurites , neurite_type = neurite_type , origin = origin , iterator_type = Tree . ileaf ) | Get the radial distances of the termination sections for a collection of neurites |
46,639 | def section_bif_radial_distances ( neurites , neurite_type = NeuriteType . all , origin = None ) : return section_radial_distances ( neurites , neurite_type = neurite_type , origin = origin , iterator_type = Tree . ibifurcation_point ) | Get the radial distances of the bifurcation sections for a collection of neurites |
46,640 | def number_of_sections_per_neurite ( neurites , neurite_type = NeuriteType . all ) : return list ( sum ( 1 for _ in n . iter_sections ( ) ) for n in iter_neurites ( neurites , filt = is_type ( neurite_type ) ) ) | Get the number of sections per neurite in a collection of neurites |
46,641 | def total_length_per_neurite ( neurites , neurite_type = NeuriteType . all ) : return list ( sum ( s . length for s in n . iter_sections ( ) ) for n in iter_neurites ( neurites , filt = is_type ( neurite_type ) ) ) | Get the path length per neurite in a collection |
46,642 | def terminal_path_lengths_per_neurite ( neurites , neurite_type = NeuriteType . all ) : return list ( sectionfunc . section_path_length ( s ) for n in iter_neurites ( neurites , filt = is_type ( neurite_type ) ) for s in iter_sections ( n , iterator_type = Tree . ileaf ) ) | Get the path lengths to each terminal point per neurite in a collection |
46,643 | def total_volume_per_neurite ( neurites , neurite_type = NeuriteType . all ) : return list ( sum ( s . volume for s in n . iter_sections ( ) ) for n in iter_neurites ( neurites , filt = is_type ( neurite_type ) ) ) | Get the volume per neurite in a collection |
46,644 | def neurite_volume_density ( neurites , neurite_type = NeuriteType . all ) : def vol_density ( neurite ) : return neurite . volume / convex_hull ( neurite ) . volume return list ( vol_density ( n ) for n in iter_neurites ( neurites , filt = is_type ( neurite_type ) ) ) | Get the volume density per neurite |
46,645 | def section_volumes ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . section_volume , neurites , neurite_type = neurite_type ) | section volumes in a collection of neurites |
46,646 | def section_areas ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . section_area , neurites , neurite_type = neurite_type ) | section areas in a collection of neurites |
46,647 | def section_tortuosity ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . section_tortuosity , neurites , neurite_type = neurite_type ) | section tortuosities in a collection of neurites |
46,648 | def section_end_distances ( neurites , neurite_type = NeuriteType . all ) : return map_sections ( sectionfunc . section_end_distance , neurites , neurite_type = neurite_type ) | section end to end distances in a collection of neurites |
46,649 | def principal_direction_extents ( neurites , neurite_type = NeuriteType . all , direction = 0 ) : def _pde ( neurite ) : points = neurite . points [ : , : 3 ] return morphmath . principal_direction_extent ( points ) [ direction ] return map ( _pde , iter_neurites ( neurites , filt = is_type ( neurite_type ) ) ) | Principal direction extent of neurites in neurons |
46,650 | def _get_linewidth ( tree , linewidth , diameter_scale ) : if diameter_scale is not None and tree : linewidth = [ 2 * segment_radius ( s ) * diameter_scale for s in iter_segments ( tree ) ] return linewidth | calculate the desired linewidth based on tree contents |
46,651 | def plot_tree ( ax , tree , plane = 'xy' , diameter_scale = _DIAMETER_SCALE , linewidth = _LINEWIDTH , color = None , alpha = _ALPHA ) : plane0 , plane1 = _plane2col ( plane ) segs = [ ( ( s [ 0 ] [ plane0 ] , s [ 0 ] [ plane1 ] ) , ( s [ 1 ] [ plane0 ] , s [ 1 ] [ plane1 ] ) ) for s in iter_segments ( tree ) ] linewid... | Plots a 2d figure of the tree s segments |
46,652 | def plot_soma ( ax , soma , plane = 'xy' , soma_outline = True , linewidth = _LINEWIDTH , color = None , alpha = _ALPHA ) : plane0 , plane1 = _plane2col ( plane ) color = _get_color ( color , tree_type = NeuriteType . soma ) if isinstance ( soma , SomaCylinders ) : plane0 , plane1 = _plane2col ( plane ) for start , end... | Generates a 2d figure of the soma . |
46,653 | def plot_neuron ( ax , nrn , neurite_type = NeuriteType . all , plane = 'xy' , soma_outline = True , diameter_scale = _DIAMETER_SCALE , linewidth = _LINEWIDTH , color = None , alpha = _ALPHA ) : plot_soma ( ax , nrn . soma , plane = plane , soma_outline = soma_outline , linewidth = linewidth , color = color , alpha = a... | Plots a 2D figure of the neuron that contains a soma and the neurites |
46,654 | def plot_tree3d ( ax , tree , diameter_scale = _DIAMETER_SCALE , linewidth = _LINEWIDTH , color = None , alpha = _ALPHA ) : segs = [ ( s [ 0 ] [ COLS . XYZ ] , s [ 1 ] [ COLS . XYZ ] ) for s in iter_segments ( tree ) ] linewidth = _get_linewidth ( tree , diameter_scale = diameter_scale , linewidth = linewidth ) color =... | Generates a figure of the tree in 3d . |
46,655 | def plot_soma3d ( ax , soma , color = None , alpha = _ALPHA ) : color = _get_color ( color , tree_type = NeuriteType . soma ) if isinstance ( soma , SomaCylinders ) : for start , end in zip ( soma . points , soma . points [ 1 : ] ) : common . plot_cylinder ( ax , start = start [ COLS . XYZ ] , end = end [ COLS . XYZ ] ... | Generates a 3d figure of the soma . |
46,656 | def _generate_collection ( group , ax , ctype , colors ) : color = TREE_COLOR [ ctype ] collection = PolyCollection ( group , closed = False , antialiaseds = True , edgecolors = 'face' , facecolors = color ) ax . add_collection ( collection ) if color not in colors : label = str ( ctype ) . replace ( 'NeuriteType.' , '... | Render rectangle collection |
46,657 | def plot_dendrogram ( ax , obj , show_diameters = True ) : dnd = Dendrogram ( obj , show_diameters = show_diameters ) dnd . generate ( ) _render_dendrogram ( dnd , ax , 0. ) ax . set_title ( 'Morphology Dendrogram' ) ax . set_xlabel ( 'micrometers (um)' ) ax . set_ylabel ( 'micrometers (um)' ) ax . set_aspect ( 'auto' ... | Dendrogram of obj |
46,658 | def make_neurites ( rdw ) : post_action = _NEURITE_ACTION [ rdw . fmt ] trunks = rdw . neurite_root_section_ids ( ) if not trunks : return [ ] , [ ] nodes = tuple ( Section ( section_id = i , points = rdw . data_block [ sec . ids ] , section_type = _TREE_TYPES [ sec . ntype ] ) for i , sec in enumerate ( rdw . sections... | Build neurite trees from a raw data wrapper |
46,659 | def _remove_soma_initial_point ( tree ) : if tree . points [ 0 ] [ COLS . TYPE ] == POINT_TYPE . SOMA : tree . points = tree . points [ 1 : ] | Remove tree s initial point if soma |
46,660 | def _check_soma_topology_swc ( points ) : if len ( points ) == 3 : return parents = tuple ( p [ COLS . P ] for p in points if p [ COLS . P ] != ROOT_ID ) if len ( parents ) > len ( set ( parents ) ) : raise SomaError ( "Bifurcating soma" ) | check if points form valid soma |
46,661 | def points ( self ) : if self . _points is None : _points = self . soma . points . tolist ( ) for n in self . neurites : _points . extend ( n . points . tolist ( ) ) self . _points = np . array ( _points ) return self . _points | Return unordered array with all the points in this neuron |
46,662 | def transform ( self , trans ) : _data = deepcopy ( self . _data ) _data . data_block [ : , 0 : 3 ] = trans ( _data . data_block [ : , 0 : 3 ] ) return FstNeuron ( _data , self . name ) | Return a copy of this neuron with a 3D transformation applied |
46,663 | def vector ( p1 , p2 ) : return np . subtract ( p1 [ COLS . XYZ ] , p2 [ COLS . XYZ ] ) | compute vector between two 3D points |
46,664 | def interpolate_radius ( r1 , r2 , fraction ) : def f ( a , b , c ) : return a + c * ( b - a ) return f ( r2 , r1 , 1. - fraction ) if r1 > r2 else f ( r1 , r2 , fraction ) | Calculate the radius that corresponds to a point P that lies at a fraction of the length of a cut cone P1P2 where P1 P2 are the centers of the circles that bound the shape with radii r1 and r2 respectively . |
46,665 | def path_fraction_id_offset ( points , fraction , relative_offset = False ) : if not ( 0. <= fraction <= 1.0 ) : raise ValueError ( "Invalid fraction: %.3f" % fraction ) pts = np . array ( points ) [ : , COLS . XYZ ] lengths = np . linalg . norm ( np . diff ( pts , axis = 0 ) , axis = 1 ) cum_lengths = np . cumsum ( le... | Find the segment which corresponds to the fraction of the path length along the piecewise linear curve which is constructed from the set of points . |
46,666 | def path_fraction_point ( points , fraction ) : seg_id , offset = path_fraction_id_offset ( points , fraction , relative_offset = True ) return linear_interpolate ( points [ seg_id ] , points [ seg_id + 1 ] , offset ) | Computes the point which corresponds to the fraction of the path length along the piecewise linear curve which is constructed from the set of points . |
46,667 | def scalar_projection ( v1 , v2 ) : return np . dot ( v1 , v2 ) / np . linalg . norm ( v2 ) | compute the scalar projection of v1 upon v2 |
46,668 | def vector_projection ( v1 , v2 ) : return scalar_projection ( v1 , v2 ) * v2 / np . linalg . norm ( v2 ) | compute the vector projection of v1 upon v2 |
46,669 | def dist_point_line ( p , l1 , l2 ) : cross_prod = np . cross ( l2 - l1 , p - l1 ) return np . linalg . norm ( cross_prod ) / np . linalg . norm ( l2 - l1 ) | compute the orthogonal distance between from the line that goes through the points l1 l2 and the point p |
46,670 | def point_dist2 ( p1 , p2 ) : v = vector ( p1 , p2 ) return np . dot ( v , v ) | compute the square of the euclidian distance between two 3D points |
46,671 | def angle_3points ( p0 , p1 , p2 ) : vec1 = vector ( p1 , p0 ) vec2 = vector ( p2 , p0 ) return math . atan2 ( np . linalg . norm ( np . cross ( vec1 , vec2 ) ) , np . dot ( vec1 , vec2 ) ) | compute the angle in radians between three 3D points |
46,672 | def angle_between_vectors ( p1 , p2 ) : v1 = p1 / np . linalg . norm ( p1 ) v2 = p2 / np . linalg . norm ( p2 ) return np . arccos ( np . clip ( np . dot ( v1 , v2 ) , - 1.0 , 1.0 ) ) | Computes the angle in radians between vectors p1 and p2 Normalizes the input vectors and computes the relative angle between them . |
46,673 | def polygon_diameter ( points ) : return max ( point_dist ( p0 , p1 ) for ( p0 , p1 ) in combinations ( points , 2 ) ) | Compute the maximun euclidian distance between any two points in a list of points |
46,674 | def average_points_dist ( p0 , p_list ) : return np . mean ( list ( point_dist ( p0 , p1 ) for p1 in p_list ) ) | Computes the average distance between a list of points and a given point p0 . |
46,675 | def path_distance ( points ) : vecs = np . diff ( points , axis = 0 ) [ : , : 3 ] d2 = [ np . dot ( p , p ) for p in vecs ] return np . sum ( np . sqrt ( d2 ) ) | Compute the path distance from given set of points |
46,676 | def segment_radial_dist ( seg , pos ) : return point_dist ( pos , np . divide ( np . add ( seg [ 0 ] , seg [ 1 ] ) , 2.0 ) ) | Return the radial distance of a tree segment to a given point |
46,677 | def segment_area ( seg ) : r0 = seg [ 0 ] [ COLS . R ] r1 = seg [ 1 ] [ COLS . R ] h2 = point_dist2 ( seg [ 0 ] , seg [ 1 ] ) return math . pi * ( r0 + r1 ) * math . sqrt ( ( r0 - r1 ) ** 2 + h2 ) | Compute the surface area of a segment . |
46,678 | def segment_volume ( seg ) : r0 = seg [ 0 ] [ COLS . R ] r1 = seg [ 1 ] [ COLS . R ] h = point_dist ( seg [ 0 ] , seg [ 1 ] ) return math . pi * h * ( ( r0 * r0 ) + ( r0 * r1 ) + ( r1 * r1 ) ) / 3.0 | Compute the volume of a segment . |
46,679 | def taper_rate ( p0 , p1 ) : return 2 * abs ( p0 [ COLS . R ] - p1 [ COLS . R ] ) / point_dist ( p0 , p1 ) | Compute the taper rate between points p0 and p1 |
46,680 | def principal_direction_extent ( points ) : points = np . copy ( points ) points -= np . mean ( points , axis = 0 ) _ , eigv = pca ( points ) extent = np . zeros ( 3 ) for i in range ( eigv . shape [ 1 ] ) : scalar_projs = np . sort ( np . array ( [ np . dot ( p , eigv [ : , i ] ) for p in points ] ) ) extent [ i ] = s... | Calculate the extent of a set of 3D points . |
46,681 | def stylize ( ax , name , feature ) : ax . set_ylabel ( feature ) ax . set_title ( name , fontsize = 'small' ) | Stylization modifications to the plots |
46,682 | def plot_feature ( feature , cell ) : fig = pl . figure ( ) ax = fig . add_subplot ( 111 ) if cell is not None : try : histogram ( cell , feature , ax ) except ValueError : pass stylize ( ax , cell . name , feature ) return fig | Plot a feature |
46,683 | def path_end_to_end_distance ( neurite ) : trunk = neurite . root_node . points [ 0 ] return max ( morphmath . point_dist ( l . points [ - 1 ] , trunk ) for l in neurite . root_node . ileaf ( ) ) | Calculate and return end - to - end - distance of a given neurite . |
46,684 | def make_end_to_end_distance_plot ( nb_segments , end_to_end_distance , neurite_type ) : plt . figure ( ) plt . plot ( nb_segments , end_to_end_distance ) plt . title ( neurite_type ) plt . xlabel ( 'Number of segments' ) plt . ylabel ( 'End-to-end distance' ) plt . show ( ) | Plot end - to - end distance vs number of segments |
46,685 | def calculate_and_plot_end_to_end_distance ( neurite ) : def _dist ( seg ) : return morphmath . point_dist ( seg [ 1 ] , neurite . root_node . points [ 0 ] ) end_to_end_distance = [ _dist ( s ) for s in nm . iter_segments ( neurite ) ] make_end_to_end_distance_plot ( np . arange ( len ( end_to_end_distance ) ) + 1 , en... | Calculate and plot the end - to - end distance vs the number of segments for an increasingly larger part of a given neurite . |
46,686 | def tree_type_checker ( * ref ) : ref = tuple ( ref ) if NeuriteType . all in ref : def check_tree_type ( _ ) : return True else : def check_tree_type ( tree ) : return tree . type in ref return check_tree_type | Tree type checker functor |
46,687 | def dendrite_filter ( n ) : return n . type == NeuriteType . basal_dendrite or n . type == NeuriteType . apical_dendrite | Select only dendrites |
46,688 | def plot_somas ( somas ) : _ , ax = common . get_figure ( new_fig = True , subplot = 111 , params = { 'projection' : '3d' , 'aspect' : 'equal' } ) for s in somas : common . plot_sphere ( ax , s . center , s . radius , color = random_color ( ) , alpha = 1 ) plt . show ( ) | Plot set of somas on same figure as spheres each with different color |
46,689 | def _max_recursion_depth ( obj ) : neurites = obj . neurites if hasattr ( obj , 'neurites' ) else [ obj ] return max ( sum ( 1 for _ in neu . iter_sections ( ) ) for neu in neurites ) | Estimate recursion depth which is defined as the number of nodes in a tree |
46,690 | def _total_rectangles ( tree ) : return sum ( len ( sec . children ) + sec . points . shape [ 0 ] - 1 for sec in tree . iter_sections ( ) ) | Calculate the total number of segments that are required for the dendrogram . There is a vertical line for each segment and two horizontal line at each branching point |
46,691 | def _n_rectangles ( obj ) : return sum ( _total_rectangles ( neu ) for neu in obj . neurites ) if hasattr ( obj , 'neurites' ) else _total_rectangles ( obj ) | Calculate the total number of rectangles with respect to the type of the object |
46,692 | def _square_segment ( radius , origin ) : return np . array ( ( ( origin [ 0 ] - radius , origin [ 1 ] - radius ) , ( origin [ 0 ] - radius , origin [ 1 ] + radius ) , ( origin [ 0 ] + radius , origin [ 1 ] + radius ) , ( origin [ 0 ] + radius , origin [ 1 ] - radius ) ) ) | Vertices for a square |
46,693 | def _vertical_segment ( old_offs , new_offs , spacing , radii ) : return np . array ( ( ( new_offs [ 0 ] - radii [ 0 ] , old_offs [ 1 ] + spacing [ 1 ] ) , ( new_offs [ 0 ] - radii [ 1 ] , new_offs [ 1 ] ) , ( new_offs [ 0 ] + radii [ 1 ] , new_offs [ 1 ] ) , ( new_offs [ 0 ] + radii [ 0 ] , old_offs [ 1 ] + spacing [ ... | Vertices for a vertical rectangle |
46,694 | def _horizontal_segment ( old_offs , new_offs , spacing , diameter ) : return np . array ( ( ( old_offs [ 0 ] , old_offs [ 1 ] + spacing [ 1 ] ) , ( new_offs [ 0 ] , old_offs [ 1 ] + spacing [ 1 ] ) , ( new_offs [ 0 ] , old_offs [ 1 ] + spacing [ 1 ] - diameter ) , ( old_offs [ 0 ] , old_offs [ 1 ] + spacing [ 1 ] - di... | Vertices of a horizontal rectangle |
46,695 | def _spacingx ( node , max_dims , xoffset , xspace ) : x_spacing = _n_terminations ( node ) * xspace if x_spacing > max_dims [ 0 ] : max_dims [ 0 ] = x_spacing return xoffset - x_spacing / 2. | Determine the spacing of the current node depending on the number of the leaves of the tree |
46,696 | def _update_offsets ( start_x , spacing , terminations , offsets , length ) : return ( start_x + spacing [ 0 ] * terminations / 2. , offsets [ 1 ] + spacing [ 1 ] * 2. + length ) | Update the offsets |
46,697 | def _max_diameter ( tree ) : return 2. * max ( max ( node . points [ : , COLS . R ] ) for node in tree . ipreorder ( ) ) | Find max diameter in tree |
46,698 | def _generate_dendro ( self , current_section , spacing , offsets ) : max_dims = self . _max_dims start_x = _spacingx ( current_section , max_dims , offsets [ 0 ] , spacing [ 0 ] ) for child in current_section . children : segments = child . points terminations = _n_terminations ( child ) seg_lengths = np . linalg . no... | Recursive function for dendrogram line computations |
46,699 | def types ( self ) : neurites = self . _obj . neurites if hasattr ( self . _obj , 'neurites' ) else ( self . _obj , ) return ( neu . type for neu in neurites ) | Returns an iterator over the types of the neurites in the object . If the object is a tree then one value is returned . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.