def has_no_dangling_branch(neuron):
soma_center = neuron.soma.points[:, COLS.XYZ].mean(axis=<NUM_LIT:0>)<EOL>recentered_soma = neuron.soma.points[:, COLS.XYZ] - soma_center<EOL>radius = np.linalg.norm(recentered_soma, axis=<NUM_LIT:1>)<EOL>soma_max_radius = radius.max()<EOL>def is_dangling(neurite):<EOL><INDENT>'''<STR_LIT>'''<EOL>starting_point = neurite.points[<NUM_LIT:1>][COLS.XYZ]<EOL>if np.linalg.norm(starting_point - soma_center) - soma_max_radius <= <NUM_LIT>:<EOL><INDENT>return False<EOL><DEDENT>if neurite.type != NeuriteType.axon:<EOL><INDENT>return True<EOL><DEDENT>all_points = list(chain.from_iterable(n.points[<NUM_LIT:1>:]<EOL>for n in iter_neurites(neurite)<EOL>if n.type != NeuriteType.axon))<EOL>res = [np.linalg.norm(starting_point - p[COLS.XYZ]) >= <NUM_LIT:2> * p[COLS.R] + <NUM_LIT:2><EOL>for p in all_points]<EOL>return all(res)<EOL><DEDENT>bad_ids = [(n.root_node.id, [n.root_node.points[<NUM_LIT:1>]])<EOL>for n in iter_neurites(neuron) if is_dangling(n)]<EOL>return CheckResult(len(bad_ids) == <NUM_LIT:0>, bad_ids)<EOL>
Check if the neuron has dangling neurites