idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
234,500 | def plot_labels ( ax , label_fontsize = 14 , xlabel = None , xlabel_arg = None , ylabel = None , ylabel_arg = None , zlabel = None , zlabel_arg = None ) : xlabel = xlabel if xlabel is not None else ax . get_xlabel ( ) or 'X' ylabel = ylabel if ylabel is not None else ax . get_ylabel ( ) or 'Y' xlabel_arg = dict_if_none ( xlabel_arg ) ylabel_arg = dict_if_none ( ylabel_arg ) ax . set_xlabel ( xlabel , fontsize = label_fontsize , * * xlabel_arg ) ax . set_ylabel ( ylabel , fontsize = label_fontsize , * * ylabel_arg ) if hasattr ( ax , 'zaxis' ) : zlabel = zlabel if zlabel is not None else ax . get_zlabel ( ) or 'Z' zlabel_arg = dict_if_none ( zlabel_arg ) ax . set_zlabel ( zlabel , fontsize = label_fontsize , * * zlabel_arg ) | Sets the labels options of a matplotlib plot | 259 | 11 |
234,501 | def plot_ticks ( ax , tick_fontsize = 12 , xticks = None , xticks_args = None , yticks = None , yticks_args = None , zticks = None , zticks_args = None ) : if xticks is not None : ax . set_xticks ( xticks ) xticks_args = dict_if_none ( xticks_args ) ax . xaxis . set_tick_params ( labelsize = tick_fontsize , * * xticks_args ) if yticks is not None : ax . set_yticks ( yticks ) yticks_args = dict_if_none ( yticks_args ) ax . yaxis . set_tick_params ( labelsize = tick_fontsize , * * yticks_args ) if zticks is not None : ax . set_zticks ( zticks ) zticks_args = dict_if_none ( zticks_args ) ax . zaxis . set_tick_params ( labelsize = tick_fontsize , * * zticks_args ) | Function that defines the labels options of a matplotlib plot . | 251 | 13 |
234,502 | def update_plot_limits ( ax , white_space ) : if hasattr ( ax , 'zz_dataLim' ) : bounds = ax . xy_dataLim . bounds ax . set_xlim ( bounds [ 0 ] - white_space , bounds [ 0 ] + bounds [ 2 ] + white_space ) ax . set_ylim ( bounds [ 1 ] - white_space , bounds [ 1 ] + bounds [ 3 ] + white_space ) bounds = ax . zz_dataLim . bounds ax . set_zlim ( bounds [ 0 ] - white_space , bounds [ 0 ] + bounds [ 2 ] + white_space ) else : bounds = ax . dataLim . bounds assert not any ( map ( np . isinf , bounds ) ) , 'Cannot set bounds if dataLim has infinite elements' ax . set_xlim ( bounds [ 0 ] - white_space , bounds [ 0 ] + bounds [ 2 ] + white_space ) ax . set_ylim ( bounds [ 1 ] - white_space , bounds [ 1 ] + bounds [ 3 ] + white_space ) | Sets the limit options of a matplotlib plot . | 237 | 12 |
234,503 | def plot_legend ( ax , no_legend = True , legend_arg = None ) : legend_arg = dict_if_none ( legend_arg ) if not no_legend : ax . legend ( * * legend_arg ) | Function that defines the legend options of a matplotlib plot . | 53 | 13 |
234,504 | def generate_cylindrical_points ( start , end , start_radius , end_radius , linspace_count = _LINSPACE_COUNT ) : v = end - start length = norm ( v ) v = v / length n1 , n2 = _get_normals ( v ) # pylint: disable=unbalanced-tuple-unpacking l , theta = np . meshgrid ( np . linspace ( 0 , length , linspace_count ) , np . linspace ( 0 , 2 * np . pi , linspace_count ) ) radii = np . linspace ( start_radius , end_radius , linspace_count ) rsin = np . multiply ( radii , np . sin ( theta ) ) rcos = np . multiply ( radii , np . cos ( theta ) ) return np . array ( [ start [ i ] + v [ i ] * l + n1 [ i ] * rsin + n2 [ i ] * rcos for i in range ( 3 ) ] ) | Generate a 3d mesh of a cylinder with start and end points and varying radius | 232 | 17 |
234,505 | def plot_cylinder ( ax , start , end , start_radius , end_radius , color = 'black' , alpha = 1. , linspace_count = _LINSPACE_COUNT ) : assert not np . all ( start == end ) , 'Cylinder must have length' x , y , z = generate_cylindrical_points ( start , end , start_radius , end_radius , linspace_count = linspace_count ) ax . plot_surface ( x , y , z , color = color , alpha = alpha ) | plot a 3d cylinder | 123 | 5 |
234,506 | def plot_sphere ( ax , center , radius , color = 'black' , alpha = 1. , linspace_count = _LINSPACE_COUNT ) : u = np . linspace ( 0 , 2 * np . pi , linspace_count ) v = np . linspace ( 0 , np . pi , linspace_count ) sin_v = np . sin ( v ) x = center [ 0 ] + radius * np . outer ( np . cos ( u ) , sin_v ) y = center [ 1 ] + radius * np . outer ( np . sin ( u ) , sin_v ) z = center [ 2 ] + radius * np . outer ( np . ones_like ( u ) , np . cos ( v ) ) ax . plot_surface ( x , y , z , linewidth = 0.0 , color = color , alpha = alpha ) | Plots a 3d sphere given the center and the radius . | 195 | 13 |
234,507 | def has_sequential_ids ( data_wrapper ) : db = data_wrapper . data_block ids = db [ : , COLS . ID ] steps = ids [ np . where ( np . diff ( ids ) != 1 ) [ 0 ] + 1 ] . astype ( int ) return CheckResult ( len ( steps ) == 0 , steps ) | Check that IDs are increasing and consecutive | 78 | 7 |
234,508 | def no_missing_parents ( data_wrapper ) : db = data_wrapper . data_block ids = np . setdiff1d ( db [ : , COLS . P ] , db [ : , COLS . ID ] ) [ 1 : ] return CheckResult ( len ( ids ) == 0 , ids . astype ( np . int ) + 1 ) | Check that all points have existing parents Point s parent ID must exist and parent must be declared before child . | 80 | 21 |
234,509 | def is_single_tree ( data_wrapper ) : db = data_wrapper . data_block bad_ids = db [ db [ : , COLS . P ] == - 1 ] [ 1 : , COLS . ID ] return CheckResult ( len ( bad_ids ) == 0 , bad_ids . tolist ( ) ) | Check that data forms a single tree | 71 | 7 |
234,510 | def has_soma_points ( data_wrapper ) : db = data_wrapper . data_block return CheckResult ( POINT_TYPE . SOMA in db [ : , COLS . TYPE ] , None ) | Checks if the TYPE column of raw data block has an element of type soma | 46 | 17 |
234,511 | def has_all_finite_radius_neurites ( data_wrapper , threshold = 0.0 ) : db = data_wrapper . data_block neurite_ids = np . in1d ( db [ : , COLS . TYPE ] , POINT_TYPE . NEURITES ) zero_radius_ids = db [ : , COLS . R ] <= threshold bad_pts = np . array ( db [ neurite_ids & zero_radius_ids ] [ : , COLS . ID ] , dtype = int ) . tolist ( ) return CheckResult ( len ( bad_pts ) == 0 , bad_pts ) | Check that all points with neurite type have a finite radius | 142 | 12 |
234,512 | def has_valid_soma ( data_wrapper ) : try : make_soma ( data_wrapper . soma_points ( ) ) return CheckResult ( True ) except SomaError : return CheckResult ( False ) | Check if a data block has a valid soma | 48 | 10 |
234,513 | def _pelita_member_filter ( parent_name , item_names ) : filtered_names = [ ] if parent_name not in sys . modules : return item_names module = sys . modules [ parent_name ] for item_name in item_names : item = getattr ( module , item_name , None ) location = getattr ( item , '__module__' , None ) if location is None or ( location + "." ) . startswith ( parent_name + "." ) : filtered_names . append ( item_name ) return filtered_names | Filter a list of autodoc items for which to generate documentation . | 123 | 14 |
234,514 | def has_axon ( neuron , treefun = _read_neurite_type ) : return CheckResult ( NeuriteType . axon in ( treefun ( n ) for n in neuron . neurites ) ) | Check if a neuron has an axon | 48 | 8 |
234,515 | def has_apical_dendrite ( neuron , min_number = 1 , treefun = _read_neurite_type ) : types = [ treefun ( n ) for n in neuron . neurites ] return CheckResult ( types . count ( NeuriteType . apical_dendrite ) >= min_number ) | Check if a neuron has apical dendrites | 72 | 10 |
234,516 | def has_basal_dendrite ( neuron , min_number = 1 , treefun = _read_neurite_type ) : types = [ treefun ( n ) for n in neuron . neurites ] return CheckResult ( types . count ( NeuriteType . basal_dendrite ) >= min_number ) | Check if a neuron has basal dendrites | 71 | 9 |
234,517 | def has_no_flat_neurites ( neuron , tol = 0.1 , method = 'ratio' ) : return CheckResult ( len ( get_flat_neurites ( neuron , tol , method ) ) == 0 ) | Check that a neuron has no flat neurites | 53 | 9 |
234,518 | def has_all_nonzero_segment_lengths ( neuron , threshold = 0.0 ) : 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 ) | Check presence of neuron segments with length not above threshold | 114 | 10 |
234,519 | def has_all_nonzero_section_lengths ( neuron , threshold = 0.0 ) : bad_ids = [ s . id for s in _nf . iter_sections ( neuron . neurites ) if section_length ( s . points ) <= threshold ] return CheckResult ( len ( bad_ids ) == 0 , bad_ids ) | Check presence of neuron sections with length not above threshold | 75 | 10 |
234,520 | def has_all_nonzero_neurite_radii ( neuron , threshold = 0.0 ) : bad_ids = [ ] seen_ids = set ( ) for s in _nf . iter_sections ( neuron ) : for i , p in enumerate ( s . points ) : info = ( s . id , i ) if p [ COLS . R ] <= threshold and info not in seen_ids : seen_ids . add ( info ) bad_ids . append ( info ) return CheckResult ( len ( bad_ids ) == 0 , bad_ids ) | Check presence of neurite points with radius not above threshold | 124 | 11 |
234,521 | 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 [ - 1 , COLS . R ] : bad_ids . append ( ( leaf . id , leaf . points [ - 1 : ] ) ) return CheckResult ( len ( bad_ids ) == 0 , bad_ids ) | Check if leaf points are too large | 155 | 7 |
234,522 | 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 , bad_ids ) | Check if neurites have a narrow start | 114 | 8 |
234,523 | 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 ) : '''Is the neurite dangling ?''' starting_point = neurite . points [ 1 ] [ COLS . XYZ ] if np . linalg . norm ( starting_point - soma_center ) - soma_max_radius <= 12. : return False if neurite . type != NeuriteType . axon : return True all_points = list ( chain . from_iterable ( n . points [ 1 : ] for n in iter_neurites ( neurite ) if n . type != NeuriteType . axon ) ) res = [ np . linalg . norm ( starting_point - p [ COLS . XYZ ] ) >= 2 * p [ COLS . R ] + 2 for p in all_points ] return all ( res ) bad_ids = [ ( n . root_node . id , [ n . root_node . points [ 1 ] ] ) for n in iter_neurites ( neuron ) if is_dangling ( n ) ] return CheckResult ( len ( bad_ids ) == 0 , bad_ids ) | Check if the neuron has dangling neurites | 342 | 8 |
234,524 | 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 ) : '''Select narrow sections''' return section . points [ : , COLS . R ] . mean ( ) < radius_threshold bad_ids = [ ( section . id , section . points [ 1 ] ) for section in considered_sections if narrow_section ( section ) ] return CheckResult ( len ( bad_ids ) == 0 , bad_ids ) | Check if the neuron has dendrites with narrow sections | 163 | 11 |
234,525 | 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 . | 58 | 11 |
234,526 | 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 | 73 | 8 |
234,527 | 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 = list ( chain . from_iterable ( ( p1 [ 1 ] , p2 [ 1 ] , None ) for p1 , p2 in segs ) ) , z = list ( chain . from_iterable ( ( p1 [ 2 ] , p2 [ 2 ] , None ) for p1 , p2 in segs ) ) ) color = TREE_COLOR . get ( neurite . root_node . type , 'black' ) if plane . lower ( ) == '3d' : plot_fun = go . Scatter3d else : plot_fun = go . Scatter coords = dict ( x = coords [ plane [ 0 ] ] , y = coords [ plane [ 1 ] ] ) yield plot_fun ( line = dict ( color = color , width = 2 ) , mode = 'lines' , * * coords ) | Create the trace to be plotted | 300 | 6 |
234,528 | 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 = [ # filled circle { 'type' : 'circle' , 'xref' : 'x' , 'yref' : 'y' , 'fillcolor' : 'rgba(50, 171, 96, 0.7)' , 'x0' : neuron . soma . center [ 0 ] - neuron . soma . radius , 'y0' : neuron . soma . center [ 1 ] - neuron . soma . radius , 'x1' : neuron . soma . center [ 0 ] + neuron . soma . radius , 'y1' : neuron . soma . center [ 1 ] + neuron . soma . radius , 'line' : { 'color' : 'rgba(50, 171, 96, 1)' , } , } , ] else : soma_2d = [ ] theta = np . linspace ( 0 , 2 * np . pi , 100 ) phi = np . linspace ( 0 , np . pi , 100 ) z = np . outer ( np . ones ( 100 ) , np . cos ( phi ) ) + neuron . soma . center [ 2 ] r = neuron . soma . radius data . append ( go . Surface ( x = ( np . outer ( np . cos ( theta ) , np . sin ( phi ) ) + neuron . soma . center [ 0 ] ) * r , y = ( np . outer ( np . sin ( theta ) , np . sin ( phi ) ) + neuron . soma . center [ 1 ] ) * r , z = z * r , cauto = False , surfacecolor = [ 'black' ] * len ( z ) , showscale = False , ) ) layout = dict ( autosize = True , title = title , scene = dict ( # This is used for 3D plots xaxis = axis , yaxis = axis , zaxis = axis , camera = dict ( up = dict ( x = 0 , y = 0 , z = 1 ) , eye = dict ( x = - 1.7428 , y = 1.0707 , z = 0.7100 , ) ) , aspectmode = 'data' ) , yaxis = dict ( scaleanchor = "x" ) , # This is used for 2D plots shapes = soma_2d , ) res = dict ( data = data , layout = layout ) return res | Returns the plotly figure containing the neuron | 601 | 8 |
234,529 | 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 | 58 | 10 |
234,530 | def _sin ( x ) : return 0. if np . isclose ( np . mod ( x , np . pi ) , 0. ) else np . sin ( x ) | sine with case for pi multiples | 37 | 8 |
234,531 | 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 * cs1 - uz * sn R [ 0 , 2 ] = uxz * cs1 + uy * sn R [ 1 , 0 ] = uxy * cs1 + uz * sn R [ 1 , 1 ] = cs + uyy * cs1 R [ 1 , 2 ] = uyz * cs1 - ux * sn R [ 2 , 0 ] = uxz * cs1 - uy * sn R [ 2 , 1 ] = uyz * cs1 + ux * sn R [ 2 , 2 ] = cs + uzz * cs1 return R | 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 . | 275 | 32 |
234,532 | 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 | 71 | 15 |
234,533 | 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 | 59 | 9 |
234,534 | 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 | 53 | 10 |
234,535 | 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 | 69 | 9 |
234,536 | 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 | 57 | 13 |
234,537 | 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 | 54 | 11 |
234,538 | 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 | 50 | 10 |
234,539 | 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 . | 60 | 10 |
234,540 | 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 | 69 | 12 |
234,541 | 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 | 45 | 8 |
234,542 | 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 | 57 | 10 |
234,543 | 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 | 61 | 12 |
234,544 | 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 | 49 | 9 |
234,545 | 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 | 65 | 13 |
234,546 | 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 | 61 | 11 |
234,547 | def section_path_lengths ( neurites , neurite_type = NeuriteType . all ) : # Calculates and stores the section lengths in one pass, # then queries the lengths in the path length iterations. # This avoids repeatedly calculating the lengths of the # same sections. dist = { } neurite_filter = is_type ( neurite_type ) for s in iter_sections ( neurites , neurite_filter = neurite_filter ) : dist [ s ] = s . length def pl2 ( node ) : '''Calculate the path length using cached section lengths''' return sum ( dist [ n ] for n in node . iupstream ( ) ) return map_sections ( pl2 , neurites , neurite_type = neurite_type ) | Path lengths of a collection of neurites | 167 | 8 |
234,548 | 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 | 57 | 14 |
234,549 | 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 | 62 | 12 |
234,550 | def segment_volumes ( neurites , neurite_type = NeuriteType . all ) : 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 map_segments ( _func , neurites , neurite_type ) | Volumes of the segments in a collection of neurites | 93 | 11 |
234,551 | def segment_radii ( neurites , neurite_type = NeuriteType . all ) : def _seg_radii ( sec ) : '''vectorized mean radii''' 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 | 103 | 18 |
234,552 | def segment_taper_rates ( neurites , neurite_type = NeuriteType . all ) : def _seg_taper_rates ( sec ) : '''vectorized taper rates''' 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 ) return map_segments ( _seg_taper_rates , neurites , neurite_type ) | taper rates of the segments in a collection of neurites | 145 | 12 |
234,553 | def segment_midpoints ( neurites , neurite_type = NeuriteType . all ) : def _seg_midpoint ( sec ) : '''Return the mid-points of segments in a section''' 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 | 109 | 14 |
234,554 | 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 | 73 | 16 |
234,555 | 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 | 73 | 16 |
234,556 | 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 | 79 | 14 |
234,557 | 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 | 76 | 16 |
234,558 | 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 | 72 | 43 |
234,559 | 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 | 67 | 14 |
234,560 | 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 | 71 | 17 |
234,561 | 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 | 72 | 14 |
234,562 | 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 | 72 | 10 |
234,563 | 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 | 89 | 14 |
234,564 | 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 | 72 | 9 |
234,565 | def neurite_volume_density ( neurites , neurite_type = NeuriteType . all ) : def vol_density ( neurite ) : '''volume density of a single 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 | 96 | 7 |
234,566 | 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 | 47 | 8 |
234,567 | 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 | 47 | 8 |
234,568 | 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 | 52 | 11 |
234,569 | 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 | 51 | 11 |
234,570 | def principal_direction_extents ( neurites , neurite_type = NeuriteType . all , direction = 0 ) : def _pde ( neurite ) : '''Get the PDE of a single neurite''' # Get the X, Y,Z coordinates of the points in each section 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 | 123 | 9 |
234,571 | 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 | 61 | 12 |
234,572 | 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 ) ] linewidth = _get_linewidth ( tree , diameter_scale = diameter_scale , linewidth = linewidth ) color = _get_color ( color , tree . type ) collection = LineCollection ( segs , color = color , linewidth = linewidth , alpha = alpha ) ax . add_collection ( collection ) | Plots a 2d figure of the tree s segments | 193 | 11 |
234,573 | 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 in zip ( soma . points , soma . points [ 1 : ] ) : common . project_cylinder_onto_2d ( ax , ( plane0 , plane1 ) , start = start [ COLS . XYZ ] , end = end [ COLS . XYZ ] , start_radius = start [ COLS . R ] , end_radius = end [ COLS . R ] , color = color , alpha = alpha ) else : if soma_outline : ax . add_artist ( Circle ( soma . center [ [ plane0 , plane1 ] ] , soma . radius , color = color , alpha = alpha ) ) else : plane0 , plane1 = _plane2col ( plane ) points = [ ( p [ plane0 ] , p [ plane1 ] ) for p in soma . iter ( ) ] if points : points . append ( points [ 0 ] ) # close the loop ax . plot ( points , color = color , alpha = alpha , linewidth = linewidth ) ax . set_xlabel ( plane [ 0 ] ) ax . set_ylabel ( plane [ 1 ] ) bounding_box = geom . bounding_box ( soma ) ax . dataLim . update_from_data_xy ( np . vstack ( ( [ bounding_box [ 0 ] [ plane0 ] , bounding_box [ 0 ] [ plane1 ] ] , [ bounding_box [ 1 ] [ plane0 ] , bounding_box [ 1 ] [ plane1 ] ] ) ) , ignore = False ) | Generates a 2d figure of the soma . | 447 | 11 |
234,574 | 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 = alpha ) for neurite in iter_neurites ( nrn , filt = tree_type_checker ( neurite_type ) ) : plot_tree ( ax , neurite , plane = plane , diameter_scale = diameter_scale , linewidth = linewidth , color = color , alpha = alpha ) ax . set_title ( nrn . name ) ax . set_xlabel ( plane [ 0 ] ) ax . set_ylabel ( plane [ 1 ] ) | Plots a 2D figure of the neuron that contains a soma and the neurites | 219 | 18 |
234,575 | 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 = _get_color ( color , tree . type ) collection = Line3DCollection ( segs , color = color , linewidth = linewidth , alpha = alpha ) ax . add_collection3d ( collection ) _update_3d_datalim ( ax , tree ) | Generates a figure of the tree in 3d . | 178 | 11 |
234,576 | 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 ] , start_radius = start [ COLS . R ] , end_radius = end [ COLS . R ] , color = color , alpha = alpha ) else : common . plot_sphere ( ax , center = soma . center [ COLS . XYZ ] , radius = soma . radius , color = color , alpha = alpha ) # unlike w/ 2d Axes, the dataLim isn't set by collections, so it has to be updated manually _update_3d_datalim ( ax , soma ) | Generates a 3d figure of the soma . | 225 | 11 |
234,577 | def _generate_collection ( group , ax , ctype , colors ) : color = TREE_COLOR [ ctype ] # generate segment collection collection = PolyCollection ( group , closed = False , antialiaseds = True , edgecolors = 'face' , facecolors = color ) # add it to the axes ax . add_collection ( collection ) # dummy plot for the legend if color not in colors : label = str ( ctype ) . replace ( 'NeuriteType.' , '' ) . replace ( '_' , ' ' ) . capitalize ( ) ax . plot ( ( 0. , 0. ) , ( 0. , 0. ) , c = color , label = label ) colors . add ( color ) | Render rectangle collection | 157 | 3 |
234,578 | def plot_dendrogram ( ax , obj , show_diameters = True ) : # create dendrogram and generate rectangle collection dnd = Dendrogram ( obj , show_diameters = show_diameters ) dnd . generate ( ) # render dendrogram and take into account neurite displacement which # starts as zero. It is important to avoid overlapping of neurites # and to determine tha limits of the figure. _render_dendrogram ( dnd , ax , 0. ) ax . set_title ( 'Morphology Dendrogram' ) ax . set_xlabel ( 'micrometers (um)' ) ax . set_ylabel ( 'micrometers (um)' ) ax . set_aspect ( 'auto' ) ax . legend ( ) | Dendrogram of obj | 169 | 5 |
234,579 | def make_neurites ( rdw ) : post_action = _NEURITE_ACTION [ rdw . fmt ] trunks = rdw . neurite_root_section_ids ( ) if not trunks : return [ ] , [ ] # One pass over sections to build nodes 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 ) ) # One pass over nodes to connect children to parents for i , node in enumerate ( nodes ) : parent_id = rdw . sections [ i ] . pid parent_type = nodes [ parent_id ] . type # only connect neurites if parent_id != ROOT_ID and parent_type != NeuriteType . soma : nodes [ parent_id ] . add_child ( node ) neurites = tuple ( Neurite ( nodes [ i ] ) for i in trunks ) if post_action is not None : for n in neurites : post_action ( n . root_node ) return neurites , nodes | Build neurite trees from a raw data wrapper | 262 | 9 |
234,580 | 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 | 47 | 8 |
234,581 | 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 | 83 | 7 |
234,582 | 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 | 67 | 11 |
234,583 | 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 | 62 | 12 |
234,584 | def vector ( p1 , p2 ) : return np . subtract ( p1 [ COLS . XYZ ] , p2 [ COLS . XYZ ] ) | compute vector between two 3D points | 35 | 8 |
234,585 | def interpolate_radius ( r1 , r2 , fraction ) : def f ( a , b , c ) : ''' Returns the length of the interpolated radius calculated using similar triangles. ''' 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 . | 83 | 52 |
234,586 | 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 ( lengths ) offset = cum_lengths [ - 1 ] * fraction seg_id = np . argmin ( cum_lengths < offset ) if seg_id > 0 : offset -= cum_lengths [ seg_id - 1 ] if relative_offset : offset /= lengths [ seg_id ] return seg_id , offset | 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 . | 178 | 27 |
234,587 | 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 . | 66 | 28 |
234,588 | def scalar_projection ( v1 , v2 ) : return np . dot ( v1 , v2 ) / np . linalg . norm ( v2 ) | compute the scalar projection of v1 upon v2 | 37 | 12 |
234,589 | def vector_projection ( v1 , v2 ) : return scalar_projection ( v1 , v2 ) * v2 / np . linalg . norm ( v2 ) | compute the vector projection of v1 upon v2 | 41 | 11 |
234,590 | 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 | 65 | 24 |
234,591 | 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 | 32 | 15 |
234,592 | 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 | 76 | 12 |
234,593 | 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 . | 81 | 28 |
234,594 | 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 | 39 | 18 |
234,595 | 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 . | 41 | 17 |
234,596 | 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 | 59 | 10 |
234,597 | 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 | 47 | 12 |
234,598 | 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 . | 88 | 9 |
234,599 | 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 . | 91 | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.