def test_annotation(): with captured_output() as (_, err): with ostream_redirect(stdout=True, stderr=True): with tmp_asc_file("""((Dendrite) (3 -4 0 2) (3 -6 0 2) (3 -8 0 2) (3 -10 0 2) ( (3 -10 0 2) (0 -10 0 2) (-3 -10 0 2) | ; <-- empty sibling but still works ! ) ) """) as tmp_file: cell = Morphology(tmp_file.name) cell.remove_unifurcations() for n in (cell, cell.as_immutable(), cell.as_immutable().as_mutable()): assert len(n.annotations) == 1 annotation = n.annotations[0] assert annotation.type == morphio.AnnotationType.single_child
def get(self, node_id, transform=False): """Return NeuroM morphology object corresponding to `node_id`. Args: node_id (int/CircuitNodeId): could be a single int or a CircuitNodeId. transform (bool): If `transform` is True, rotate and translate morphology points according to `node_id` position in the circuit. """ filepath = self.get_filepath(node_id) result = Morphology(filepath) if transform: T = np.eye(4) T[:3, :3] = self._population.orientations(node_id) # rotations T[:3, 3] = self._population.positions(node_id).values # translations transformations.transform(result, T) return result.as_immutable()
def test_equality(): set_ignored_warning([Warning.wrong_duplicate, Warning.only_child], True) filename = joinp(DATA, 'simple2.asc') neuron_ref = Morphology(filename) ok_(not diff(neuron_ref, neuron_ref)) ok_(not diff(neuron_ref, filename)) ok_(not diff(neuron_ref, neuron_ref.as_immutable())) def mundane_section(neuron): '''Not a root section, not a leaf section''' return neuron.root_sections[0].children[0] a = Morphology(joinp(DATA, 'simple2.asc')) mundane_section(a).type = SectionType.apical_dendrite result = diff(neuron_ref, a) ok_(result) assert_equal(result.info, 'Section(id=1, points=[(0 5 0),..., (-6 5 0)]) and Section(id=1, points=[(0 5 0),..., (-6 5 0)]) have different section types') a = Morphology(joinp(DATA, 'simple2.asc')) mundane_section(a).points = [[0,0,0], [0,0,0], [0,0,1]] result = diff(neuron_ref, a) ok_(result) assert_equal(result.info, '\n'.join(['Attributes Section.points of:', 'Section(id=1, points=[(0 5 0),..., (-6 5 0)])', 'Section(id=1, points=[(0 0 0),..., (0 0 1)])', 'have the same shape but different values'])) a = Morphology(joinp(DATA, 'simple2.asc')) mundane_section(a).diameters = [0,0,0] result = diff(neuron_ref, a) ok_(result) assert_equal(result.info, '\n'.join(['Attributes Section.diameters of:', 'Section(id=1, points=[(0 5 0),..., (-6 5 0)])', 'Section(id=1, points=[(0 5 0),..., (-6 5 0)])', 'have the same shape but different values'])) a = Morphology(joinp(DATA, 'simple2.asc')) for section in a.iter(): section.perimeters = [1] * len(section.points) result = diff(neuron_ref, a) ok_(result) assert_equal(result.info, '\n'.join(['Attributes Section.perimeters of:', 'Section(id=0, points=[(0 0 0),..., (0 5 0)])', 'Section(id=0, points=[(0 0 0),..., (0 5 0)])', 'have different shapes: (0,) vs (2,)'])) a = Morphology(joinp(DATA, 'simple2.asc')) mundane_section(a).append_section(PointLevel([[-6, 5, 0], [4, 5, 6]], [2, 3])) result = diff(neuron_ref, a) ok_(result) assert_equal(result.info, 'Section(id=1, points=[(0 5 0),..., (-6 5 0)]) and Section(id=1, points=[(0 5 0),..., (-6 5 0)]) have different a different number of children') a = Morphology(joinp(DATA, 'simple2.asc')) a.delete_section(a.root_sections[0]) result = diff(neuron_ref, a) ok_(result) assert_equal(result.info, 'Both morphologies have different a different number of root sections') result = diff(joinp(DATA, 'single_child.asc'), joinp(DATA, 'not_single_child.asc')) ok_(not result) set_ignored_warning([Warning.wrong_duplicate, Warning.only_child], False)
def test_equality(): set_ignored_warning([Warning.wrong_duplicate, Warning.only_child], True) filename = DATA / 'simple2.asc' neuron_ref = Morphology(filename) assert not diff(neuron_ref, neuron_ref) assert not diff(neuron_ref, filename) assert not diff(neuron_ref, neuron_ref.as_immutable()) def mundane_section(neuron): '''Not a root section, not a leaf section''' return neuron.root_sections[0].children[0] a = Morphology(DATA / 'simple2.asc') mundane_section(a).type = SectionType.apical_dendrite result = diff(neuron_ref, a) assert result assert result.info == 'Section(id=1, points=[(0 5 0),..., (-6 5 0)]) and Section(id=1, points=[(0 5 0),..., (-6 5 0)]) have different section types' a = Morphology(DATA / 'simple2.asc') mundane_section(a).points = [[0,0,0], [0,0,0], [0,0,1]] result = diff(neuron_ref, a) assert result assert (result.info == '\n'.join(['Attributes Section.points of:', 'Section(id=1, points=[(0 5 0),..., (-6 5 0)])', 'Section(id=1, points=[(0 0 0),..., (0 0 1)])', 'have the same shape but different values', 'Vector points differs at index 0: [0. 5. 0.] != [0. 0. 0.]'])) a = Morphology(DATA / 'simple2.asc') mundane_section(a).diameters = [0,0,0] result = diff(neuron_ref, a) assert result assert (result.info == '\n'.join(['Attributes Section.diameters of:', 'Section(id=1, points=[(0 5 0),..., (-6 5 0)])', 'Section(id=1, points=[(0 5 0),..., (-6 5 0)])', 'have the same shape but different values', 'Vector diameters differs at index 0: 3.0 != 0.0'])) a = Morphology(DATA / 'simple2.asc') for section in a.iter(): section.perimeters = [1] * len(section.points) result = diff(neuron_ref, a) assert result assert (result.info == '\n'.join(['Attributes Section.perimeters of:', 'Section(id=0, points=[(0 0 0),..., (0 5 0)])', 'Section(id=0, points=[(0 0 0),..., (0 5 0)])', 'have different shapes: (0,) vs (2,)'])) a = Morphology(DATA / 'simple2.asc') mundane_section(a).append_section(PointLevel([[-6, 5, 0], [4, 5, 6]], [2, 3])) result = diff(neuron_ref, a) assert result assert result.info == 'Section(id=1, points=[(0 5 0),..., (-6 5 0)]) and Section(id=1, points=[(0 5 0),..., (-6 5 0)]) have a different number of children' a = Morphology(DATA / 'simple2.asc') a.delete_section(a.root_sections[0]) result = diff(neuron_ref, a) assert result assert result.info == 'Both morphologies have a different number of root sections' result = diff(DATA / 'single_child.asc', DATA / 'not_single_child.asc') if parse_version(get_distribution("morphio").version) < parse_version("3"): assert not result else: assert result set_ignored_warning([Warning.wrong_duplicate, Warning.only_child], False)