コード例 #1
0
ファイル: test_morphologies.py プロジェクト: DorenCalliku/bsb
    def test_legacy_runs_without_errors(self):
        import random

        # The old compartment based system should still run without errors
        v = len(Branch.vectors)
        root = Branch(*(np.ones(v) for i in range(v)))
        branches = [root]
        for _ in range(20):
            branch = Branch(*(np.ones(v) for i in range(v)))
            branch.label(random.choice(["A", "B", "C"]))
            random.choice(branches).attach_child(branch)
            branches.append(branch)
        m = Morphology([root])
        # Call all of the legacy functions
        m.update_compartment_tree()
        m.voxelize(1)
        # Too complex to give correct input and already covered by other tests
        # m.create_compartment_map()
        m.get_bounding_box()
        m.get_search_radius()
        m.get_compartment_network()
        m.get_compartment_positions()
        m.get_compartment_positions(labels=["A"])
        m.get_plot_range()
        m.get_compartment_tree()
        m.get_compartment_tree(labels=["B"])
        m.get_compartment_submask(["C"])
        m.get_compartments()
        m.get_compartments(labels=["A"])
        m.get_branches()
        m.get_branches(labels=["B"])
コード例 #2
0
ファイル: test_morphologies.py プロジェクト: DorenCalliku/bsb
 def test_point_labels(self):
     v = len(Branch.vectors)
     branch = Branch(*(np.ones(v) for i in range(v)))
     branch.label_points("A", [False, True] + [False] * (v - 2))
     self.assertEqual([], branch._full_labels)
     self.assertEqual([[], ["A"]] + [[]] * (v - 2),
                      list(map(list, branch.label_walk())))
コード例 #3
0
ファイル: test_morphologies.py プロジェクト: DorenCalliku/bsb
 def test_branch_nargs(self):
     v = len(Branch.vectors)
     Branch(*(np.ones(i) for i in range(v)))
     with self.assertRaises(TypeError):
         Branch(*(np.ones(i) for i in range(v - 1)))
     with self.assertRaises(TypeError):
         Branch(*(np.ones(i) for i in range(v + 1)))
コード例 #4
0
ファイル: test_morphologies.py プロジェクト: DorenCalliku/bsb
 def test_full_labels(self):
     v = len(Branch.vectors)
     branch = Branch(*(np.ones(v) for i in range(v)))
     branch.label("A", "B", "C")
     self.assertEqual(["A", "B", "C"], branch._full_labels)
     self.assertEqual(["A", "B", "C"], list(next(branch.label_walk())))
     self.assertTrue(
         all(["A", "B", "C"] == list(l) for l in branch.label_walk()))
コード例 #5
0
 def test_rotate(self):
     root = Branch(
         np.array([0.0, 1.0, 2.0]),
         np.array([0.0, 0.0, 0.0]),
         np.array([0.0, 0.0, 0.0]),
         np.array([1.0, 1.0, 1.0]),
     )
     m = Morphology([root])
     v0 = [1.0, 0.0, 0.0]
     v = [0.0, 1.0, 0.0]
     # Store pre rotation checks
     x0 = m.compartments[0].end.copy()
     # Rotate
     m.rotate(v0, v)
     s = m.compartments[0].start
     # Verify rotations
     self.assertEqualPoints(s, [0.0, 0.0, 0.0], "Rotation moved the origin!")
     self.assertEqualPoints(m.compartments[0].end, [0.0, 1.0, 0.0], v0=v0, v=v, x0=x0)
コード例 #6
0
ファイル: test_morphologies.py プロジェクト: DorenCalliku/bsb
 def test_properties(self):
     branch = Branch(
         np.array([0, 1, 2]),
         np.array([0, 1, 2]),
         np.array([0, 1, 2]),
         np.array([0, 1, 2]),
     )
     self.assertEqual(3, branch.size, "Incorrect branch size")
     comps = branch.to_compartments()
     self.assertTrue(np.array_equal(comps[0].midpoint, [0.5, 0.5, 0.5]))
     self.assertEqual(comps[0].spherical, np.sqrt(3) / 2)
     self.assertTrue(branch.terminal)
     branch.attach_child(
         Branch(*(np.ones(0) for i in range(len(Branch.vectors)))))
     self.assertFalse(branch.terminal)
コード例 #7
0
ファイル: test_morphologies.py プロジェクト: DorenCalliku/bsb
 def test_mr_labels(self):
     v = len(Branch.vectors)
     branch = Branch(*(np.ones(v) for i in range(v)))
     branch.label_points("A", [False, True] + [False] * (v - 2))
     branch.label("B")
     m = Morphology([branch])
     mr = bsb.output.MorphologyRepository("tmp.h5")
     mr.get_handle("w")
     mr.save_morphology("test", m)
     m_loaded = mr.get_morphology("test")
     branch_loaded = m_loaded.roots[0]
     self.assertEqual(["B"], branch_loaded._full_labels)
     self.assertEqual(
         [["B"], ["B", "A"]] + [["B"]] * (v - 2),
         list(map(list, branch_loaded.label_walk())),
     )
コード例 #8
0
ファイル: test_morphologies.py プロジェクト: DorenCalliku/bsb
 def test_branch_attachment(self):
     v = len(Branch.vectors)
     branch_A = Branch(*(np.ones(v) for i in range(v)))
     branch_B = Branch(*(np.ones(v) for i in range(v)))
     branch_C = Branch(*(np.ones(v) for i in range(v)))
     branch_D = Branch(*(np.ones(v) for i in range(v)))
     branch_A.attach_child(branch_B)
     branch_A.attach_child(branch_C)
     branch_B.attach_child(branch_D)
     self.assertEqual([branch_B, branch_C], branch_A._children)
     self.assertFalse(branch_A.terminal)
     self.assertFalse(branch_B.terminal)
     self.assertTrue(branch_C.terminal)
     self.assertTrue(branch_D.terminal)
     branch_A.detach_child(branch_C)
     self.assertIsNone(branch_C._parent)
     with self.assertRaises(ValueError):
         branch_A.detach_child(branch_D)
     self.assertEqual(branch_B, branch_D._parent)