def test__repair(): neuron = load_neuron(Path(DATA_PATH, 'valid.h5')) axon = neuron.root_sections[0] assert_equal(axon.type, SectionType.axon) test_module.repair(neuron, axon, [axon], [axon], set(), y_extent=10000) assert_equal(len(axon.children), 1) assert_array_equal(axon.children[0].points[0], axon.points[-1]) ok_(not diff(neuron, DATA_PATH / 'axon-repair.h5'))
def test__repair_no_intact_axon(): filename = Path(DATA_PATH, 'valid.h5') neuron = load_neuron(filename) axon = neuron.root_sections[0] used_axon_branches = set() test_module.repair(neuron, axon, [], [axon], used_axon_branches, y_extent=10000) # There should not be any repair ok_(not diff(neuron, filename))
def run(self, outputfile: Path, plot_file: Optional[Path] = None): '''Run''' if self.cut_leaves.size == 0: L.warning('No cut leaves. Nothing to repair for morphology %s', self.inputfile) self.neuron.write(outputfile) return # See https://github.com/BlueBrain/MorphIO/issues/161 keep_axons_alive = list() for axon_donor in self.axon_donors: if self.legacy_detection: plane = CutPlane.find_legacy(axon_donor, 'z') else: plane = CutPlane.find(axon_donor) keep_axons_alive.append(plane) self.donated_intact_axon_sections.extend([ section for section in iter_sections(plane.morphology) if section.type == SectionType.axon and is_branch_intact(section, plane.cut_leaves_coordinates) ]) self._fill_repair_type_map() self._fill_statistics_for_intact_subtrees() intact_axonal_sections = [ section for section in iter_sections(self.neuron) if section.type == SectionType.axon and is_branch_intact(section, self.cut_leaves) ] # BlueRepairSDK used to have a bounding cylinder filter but # I don't know what is it good at so I have commented # the only relevant line # bounding_cylinder_radius = 10000 cut_sections_in_bounding_cylinder = [ section for section in iter_sections(self.neuron) if (is_cut_section(section, cut_points=self.cut_leaves) # and np.linalg.norm(section.points[-1, COLS.XZ]) < bounding_cylinder_radius ) ] used_axon_branches = set() cut_leaves_ids = { section: len(section.points) for section in cut_sections_in_bounding_cylinder } for section in sorted(cut_sections_in_bounding_cylinder, key=section_path_length): type_ = self.repair_type_map[section] if not self.repair_flags.get(type_, True): continue L.info('Repairing: %s, section id: %s', type_, section.id) if type_ in { RepairType.basal, RepairType.oblique, RepairType.tuft }: origin = self._get_origin(section) if section.type == NeuriteType.basal_dendrite: _continuation(section, origin) self._grow(section, self._get_order_offset(section), origin) elif type_ == RepairType.axon: axon.repair(self.neuron, section, intact_axonal_sections, self.donated_intact_axon_sections, used_axon_branches, self.max_y_extent) elif type_ == RepairType.trunk: L.info('Trunk repair is not (nor has ever been) implemented') else: raise Exception('Unknown type: {}'.format(type_)) if plot_file is not None: try: from neuror.view import plot_repaired_neuron plot_repaired_neuron(self.neuron, cut_leaves_ids, plot_file) except ImportError: L.warning( 'Skipping writing plots as [plotly] extra is not installed' ) self.neuron.write(outputfile) L.info('Repair successful for %s', self.inputfile)