def _downstream_pathlength(section): '''The sum of this section and its descendents's pathlengths Reimplementation of the C++ function "children_length": https://bbpcode.epfl.ch/browse/code/platform/BlueRepairSDK/tree/BlueRepairSDK/src/morphstats.cpp#n112 ''' ret = section_length(section) for child in section.children: ret += _downstream_pathlength(child) return ret
def _sort_intact_sections_by_score(section, similar_section, axon_branches): '''Returns an array of sections sorted by their score''' reference = _downstream_pathlength(similar_section) - section_length( section) def score(branch): '''The score. The interpretation is something like the absolute difference in remaining children length''' return -abs(reference - _downstream_pathlength(branch)) return sorted(axon_branches, key=score)
def _branching_angles(section, order_offset=0): '''Return a list of 2-tuples. The first element is the branching order and the second one is the angles between the direction of the section and its children's ones Note: based on https://bbpcode.epfl.ch/browse/code/platform/BlueRepairSDK/tree/BlueRepairSDK/src/morphstats.cpp#n194 # noqa, pylint: disable=line-too-long ''' if section_length(section) < EPSILON: return [] res = [] branching_order = branch_order(section) - order_offset for child in section.children: if section_length(child) < EPSILON: continue theta = np.math.acos( np.dot(direction(section), direction(child)) / (section_length(section) * section_length(child))) res.append((branching_order, theta)) return res