idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
235,500
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
235,501
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
235,502
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
235,503
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
235,504
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
235,505
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
235,506
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
235,507
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
235,508
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
235,509
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
235,510
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
235,511
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
235,512
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
235,513
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
235,514
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
235,515
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
235,516
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
235,517
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 .
235,518
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
235,519
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 .
235,520
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 .
235,521
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
235,522
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
235,523
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
235,524
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
235,525
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
235,526
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
235,527
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
235,528
def vector ( p1 , p2 ) : return np . subtract ( p1 [ COLS . XYZ ] , p2 [ COLS . XYZ ] )
compute vector between two 3D points
235,529
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 .
235,530
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 .
235,531
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 .
235,532
def scalar_projection ( v1 , v2 ) : return np . dot ( v1 , v2 ) / np . linalg . norm ( v2 )
compute the scalar projection of v1 upon v2
235,533
def vector_projection ( v1 , v2 ) : return scalar_projection ( v1 , v2 ) * v2 / np . linalg . norm ( v2 )
compute the vector projection of v1 upon v2
235,534
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
235,535
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
235,536
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
235,537
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 .
235,538
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
235,539
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 .
235,540
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
235,541
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
235,542
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 .
235,543
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 .
235,544
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
235,545
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 .
235,546
def stylize ( ax , name , feature ) : ax . set_ylabel ( feature ) ax . set_title ( name , fontsize = 'small' )
Stylization modifications to the plots
235,547
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
235,548
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 .
235,549
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
235,550
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 .
235,551
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
235,552
def dendrite_filter ( n ) : return n . type == NeuriteType . basal_dendrite or n . type == NeuriteType . apical_dendrite
Select only dendrites
235,553
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
235,554
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
235,555
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
235,556
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
235,557
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
235,558
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
235,559
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
235,560
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
235,561
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
235,562
def _max_diameter ( tree ) : return 2. * max ( max ( node . points [ : , COLS . R ] ) for node in tree . ipreorder ( ) )
Find max diameter in tree
235,563
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
235,564
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 .
235,565
def register_neurite_feature ( name , func ) : if name in NEURITEFEATURES : raise NeuroMError ( 'Attempt to hide registered feature %s' % name ) def _fun ( neurites , neurite_type = _ntype . all ) : return list ( func ( n ) for n in _ineurites ( neurites , filt = _is_type ( neurite_type ) ) ) NEURONFEATURES [ name ] = ...
Register a feature to be applied to neurites
235,566
def get ( feature , obj , ** kwargs ) : feature = ( NEURITEFEATURES [ feature ] if feature in NEURITEFEATURES else NEURONFEATURES [ feature ] ) return _np . array ( list ( feature ( obj , ** kwargs ) ) )
Obtain a feature from a set of morphology objects
235,567
def _get_doc ( ) : def get_docstring ( func ) : docstring = ':\n' if func . __doc__ : docstring += _indent ( func . __doc__ , 2 ) return docstring ret = [ '\nNeurite features (neurite, neuron, neuron population):' ] ret . extend ( _INDENT + '- ' + feature + get_docstring ( func ) for feature , func in sorted ( NEURITEF...
Get a description of all the known available features
235,568
def read ( filename , remove_duplicates = False , data_wrapper = DataWrapper ) : with h5py . File ( filename , mode = 'r' ) as h5file : version = get_version ( h5file ) if version == 'H5V1' : points , groups = _unpack_v1 ( h5file ) elif version == 'H5V2' : stg = next ( s for s in ( 'repaired' , 'unraveled' , 'raw' ) if...
Read a file and return a data_wrapper d data
235,569
def _remove_duplicate_points ( points , groups ) : group_initial_ids = groups [ : , GPFIRST ] to_be_reduced = np . zeros ( len ( group_initial_ids ) ) to_be_removed = [ ] for ig , g in enumerate ( groups ) : iid , typ , pid = g [ GPFIRST ] , g [ GTYPE ] , g [ GPID ] if pid != - 1 and typ != 1 and groups [ pid ] [ GTYPE...
Removes the duplicate points from the beginning of a section if they are present in points - groups representation .
235,570
def _unpack_v1 ( h5file ) : points = np . array ( h5file [ 'points' ] ) groups = np . array ( h5file [ 'structure' ] ) return points , groups
Unpack groups from HDF5 v1 file
235,571
def _unpack_v2 ( h5file , stage ) : points = np . array ( h5file [ 'neuron1/%s/points' % stage ] ) groups_stage = stage if stage != 'unraveled' else 'raw' groups = np . array ( h5file [ 'neuron1/structure/%s' % groups_stage ] ) stypes = np . array ( h5file [ 'neuron1/structure/sectiontype' ] ) groups = np . hstack ( [ ...
Unpack groups from HDF5 v2 file
235,572
def fit_results_to_dict ( fit_results , min_bound = None , max_bound = None ) : type_map = { 'norm' : 'normal' , 'expon' : 'exponential' , 'uniform' : 'uniform' } param_map = { 'uniform' : lambda p : [ ( 'min' , p [ 0 ] ) , ( 'max' , p [ 0 ] + p [ 1 ] ) ] , 'norm' : lambda p : [ ( 'mu' , p [ 0 ] ) , ( 'sigma' , p [ 1 ]...
Create a JSON - comparable dict from a FitResults object
235,573
def fit ( data , distribution = 'norm' ) : params = getattr ( _st , distribution ) . fit ( data ) return FitResults ( params , _st . kstest ( data , distribution , params ) , distribution )
Calculate the parameters of a fit of a distribution to a data set
235,574
def optimal_distribution ( data , distr_to_check = ( 'norm' , 'expon' , 'uniform' ) ) : fit_results = [ fit ( data , d ) for d in distr_to_check ] return min ( fit_results , key = lambda fit : fit . errs [ 0 ] )
Calculate the parameters of a fit of different distributions to a data set and returns the distribution of the minimal ks - distance .
235,575
def scalar_stats ( data , functions = ( 'min' , 'max' , 'mean' , 'std' ) ) : stats = { } for func in functions : stats [ func ] = getattr ( np , func ) ( data ) return stats
Calculate the stats from the given numpy functions
235,576
def total_score ( paired_dats , p = 2 , test = StatTests . ks ) : scores = np . array ( [ compare_two ( fL1 , fL2 , test = test ) . dist for fL1 , fL2 in paired_dats ] ) return np . linalg . norm ( scores , p )
Calculates the p - norm of the distances that have been calculated from the statistical test that has been applied on all the paired datasets .
235,577
def iter_neurites ( obj , mapfun = None , filt = None , neurite_order = NeuriteIter . FileOrder ) : neurites = ( ( obj , ) if isinstance ( obj , Neurite ) else obj . neurites if hasattr ( obj , 'neurites' ) else obj ) if neurite_order == NeuriteIter . NRN : last_position = max ( NRN_ORDER . values ( ) ) + 1 neurites = ...
Iterator to a neurite neuron or neuron population
235,578
def iter_sections ( neurites , iterator_type = Tree . ipreorder , neurite_filter = None , neurite_order = NeuriteIter . FileOrder ) : return chain . from_iterable ( iterator_type ( neurite . root_node ) for neurite in iter_neurites ( neurites , filt = neurite_filter , neurite_order = neurite_order ) )
Iterator to the sections in a neurite neuron or neuron population .
235,579
def iter_segments ( obj , neurite_filter = None , neurite_order = NeuriteIter . FileOrder ) : sections = iter ( ( obj , ) if isinstance ( obj , Section ) else iter_sections ( obj , neurite_filter = neurite_filter , neurite_order = neurite_order ) ) return chain . from_iterable ( zip ( sec . points [ : - 1 ] , sec . poi...
Return an iterator to the segments in a collection of neurites
235,580
def graft_neuron ( root_section ) : assert isinstance ( root_section , Section ) return Neuron ( soma = Soma ( root_section . points [ : 1 ] ) , neurites = [ Neurite ( root_section ) ] )
Returns a neuron starting at root_section
235,581
def points ( self ) : _pts = [ v for s in self . root_node . ipreorder ( ) for v in s . points [ 1 : , COLS . XYZR ] ] _pts . insert ( 0 , self . root_node . points [ 0 ] [ COLS . XYZR ] ) return np . array ( _pts )
Return unordered array with all the points in this neurite
235,582
def transform ( self , trans ) : clone = deepcopy ( self ) for n in clone . iter_sections ( ) : n . points [ : , 0 : 3 ] = trans ( n . points [ : , 0 : 3 ] ) return clone
Return a copy of this neurite with a 3D transformation applied
235,583
def iter_sections ( self , order = Tree . ipreorder , neurite_order = NeuriteIter . FileOrder ) : return iter_sections ( self , iterator_type = order , neurite_order = neurite_order )
iteration over section nodes
235,584
def eval_stats ( values , mode ) : if mode == 'raw' : return values . tolist ( ) if mode == 'total' : mode = 'sum' try : return getattr ( np , mode ) ( values , axis = 0 ) except ValueError : pass return None
Extract a summary statistic from an array of list of values
235,585
def _stat_name ( feat_name , stat_mode ) : if feat_name [ - 1 ] == 's' : feat_name = feat_name [ : - 1 ] if feat_name == 'soma_radii' : feat_name = 'soma_radius' if stat_mode == 'raw' : return feat_name return '%s_%s' % ( stat_mode , feat_name )
Set stat name based on feature name and stat mode
235,586
def extract_stats ( neurons , config ) : stats = defaultdict ( dict ) for ns , modes in config [ 'neurite' ] . items ( ) : for n in config [ 'neurite_type' ] : n = _NEURITE_MAP [ n ] for mode in modes : stat_name = _stat_name ( ns , mode ) stat = eval_stats ( nm . get ( ns , neurons , neurite_type = n ) , mode ) if sta...
Extract stats from neurons
235,587
def get_header ( results ) : ret = [ 'name' , ] values = next ( iter ( results . values ( ) ) ) for k , v in values . items ( ) : if isinstance ( v , dict ) : for metric in v . keys ( ) : ret . append ( '%s:%s' % ( k , metric ) ) else : ret . append ( k ) return ret
Extracts the headers using the first value in the dict as the template
235,588
def generate_flattened_dict ( headers , results ) : for name , values in results . items ( ) : row = [ ] for header in headers : if header == 'name' : row . append ( name ) elif ':' in header : neurite_type , metric = header . split ( ':' ) row . append ( values [ neurite_type ] [ metric ] ) else : row . append ( value...
extract from results the fields in the headers list
235,589
def add_child ( self , tree ) : tree . parent = self self . children . append ( tree ) return tree
Add a child to the list of this tree s children
235,590
def ipreorder ( self ) : children = deque ( ( self , ) ) while children : cur_node = children . pop ( ) children . extend ( reversed ( cur_node . children ) ) yield cur_node
Depth - first pre - order iteration of tree nodes
235,591
def ipostorder ( self ) : children = [ self , ] seen = set ( ) while children : cur_node = children [ - 1 ] if cur_node not in seen : seen . add ( cur_node ) children . extend ( reversed ( cur_node . children ) ) else : children . pop ( ) yield cur_node
Depth - first post - order iteration of tree nodes
235,592
def deprecated ( fun_name = None , msg = "" ) : def _deprecated ( fun ) : @ wraps ( fun ) def _wrapper ( * args , ** kwargs ) : name = fun_name if fun_name is not None else fun . __name__ _warn_deprecated ( 'Call to deprecated function %s. %s' % ( name , msg ) ) return fun ( * args , ** kwargs ) return _wrapper return ...
Issue a deprecation warning for a function
235,593
def check_wrapper ( fun ) : @ wraps ( fun ) def _wrapper ( * args , ** kwargs ) : title = fun . __name__ . replace ( '_' , ' ' ) . capitalize ( ) result = fun ( * args , ** kwargs ) result . title = title return result return _wrapper
Decorate a checking function
235,594
def run ( self , path ) : SEPARATOR = '=' * 40 summary = { } res = True for _f in utils . get_files_by_path ( path ) : L . info ( SEPARATOR ) status , summ = self . _check_file ( _f ) res &= status if summ is not None : summary . update ( summ ) L . info ( SEPARATOR ) status = 'PASS' if res else 'FAIL' return { 'files'...
Test a bunch of files and return a summary JSON report
235,595
def _do_check ( self , obj , check_module , check_str ) : opts = self . _config [ 'options' ] if check_str in opts : fargs = opts [ check_str ] if isinstance ( fargs , list ) : out = check_wrapper ( getattr ( check_module , check_str ) ) ( obj , * fargs ) else : out = check_wrapper ( getattr ( check_module , check_str ...
Run a check function on obj
235,596
def _check_loop ( self , obj , check_mod_str ) : check_module = self . _check_modules [ check_mod_str ] checks = self . _config [ 'checks' ] [ check_mod_str ] result = True summary = OrderedDict ( ) for check in checks : ok = self . _do_check ( obj , check_module , check ) summary [ ok . title ] = ok . status result &=...
Run all the checks in a check_module
235,597
def _check_file ( self , f ) : L . info ( 'File: %s' , f ) full_result = True full_summary = OrderedDict ( ) try : data = load_data ( f ) except Exception as e : L . error ( 'Failed to load data... skipping tests for this file' ) L . error ( e . args ) return False , { f : OrderedDict ( [ ( 'ALL' , False ) ] ) } try : ...
Run tests on a morphology file
235,598
def _log_msg ( self , msg , ok ) : if self . _config [ 'color' ] : CGREEN , CRED , CEND = '\033[92m' , '\033[91m' , '\033[0m' else : CGREEN = CRED = CEND = '' LOG_LEVELS = { False : logging . ERROR , True : logging . INFO } L . log ( LOG_LEVELS [ ok ] , '%35s %s' + CEND , msg , CGREEN + 'PASS' if ok else CRED + 'FAIL' ...
Helper to log message to the right level
235,599
def _sanitize_config ( config ) : if 'checks' in config : checks = config [ 'checks' ] if 'structural_checks' not in checks : checks [ 'structural_checks' ] = [ ] if 'neuron_checks' not in checks : checks [ 'neuron_checks' ] = [ ] else : raise ConfigError ( 'Need to have "checks" in the config' ) if 'options' not in co...
check that the config has the correct keys add missing keys if necessary