示例#1
0
 def test_toString(self):
     """ tests __str__ output """
     otp = rb.OrganRandomParameter(rb.Organism())
     otp.name = "the great organ"
     otp.organType = 1
     otp.subType = 2
     self.assertEqual(otp.__str__(False), "Name: the great organ, organType: 1, subType, 2", "toString: value unexpected")
示例#2
0
 def root_example_rtp(self):
     """ an example used in the tests below, a main root with laterals """
     self.plant = rb.Organism(
     )  # Root has no dependency on RootSystem anymore
     p0 = rb.RootRandomParameter(self.plant)
     p0.name, p0.type, p0.la, p0.lb, p0.nob, p0.ln, p0.r, p0.dx = "taproot", 1, 1, 10, 20, (
         89. / 19.), 1, 0.5
     p0.successor = a2i([2])  # to rb.std_int_double_()
     p0.successorP = a2v([1.])  # rb.std_vector_double_()
     p1 = rb.RootRandomParameter(self.plant)
     p1.name, p1.type, p1.la, p1.ln, p1.r, p1.dx = "lateral", 2, 25, 0, 2, 0.1
     self.p0, self.p1 = p0, p1  # Python will garbage collect them away, if not stored
     self.plant.setOrganRandomParameter(
         self.p0)  # the organism manages the type parameters
     self.plant.setOrganRandomParameter(self.p1)
     self.param0 = self.p0.realize(
     )  # set up root by hand (without a root system)
     self.param0.la = 0  # its important parent has zero length, otherwise creation times are messed up
     self.param0.lb = 0
     # param0 is stored, because otherwise garbage collection deletes it, an program will crash <---
     parentroot = rb.Root(1, self.param0, True, True, 0., 0.,
                          rb.Vector3d(0, 0, -1), 0, 0, False, 0)
     parentroot.setOrganism(self.plant)
     parentroot.addNode(rb.Vector3d(0, 0, -3),
                        0)  # there is no nullptr in Python
     self.root = rb.Root(self.plant, self.p0.subType, rb.Vector3d(0, 0, -1),
                         0, parentroot, 0, 0)
     self.root.setOrganism(self.plant)
示例#3
0
 def test_realize(self):
     """ calls realize """
     otp = rb.OrganRandomParameter(rb.Organism())
     otp.subType = 2
     p = otp.realize();
     self.assertEqual(p.__class__.__name__, "OrganSpecificParameter", "realize: unexpected class type")
     self.assertEqual(p.subType, 2, "realize: unexpected sub type")
示例#4
0
 def test_parameter(self):
     """ tests getParameter() """
     plant = rb.Organism()
     srp = rb.SeedRandomParameter(plant)
     srp.firstB = 0.123
     srp.delaySBs = 12
     ot = srp.getParameter("organType")  # test defaults
     st = srp.getParameter("subType")
     nz = srp.getParameter("nz")
     firstB = srp.getParameter("firstB")
     delaySBs = srp.getParameter("delaySB_dev")
     firstB2 = srp.getParameter(
         "firstB_mean"
     )  # we can always add "_mean" to avoid naming conflicts
     self.assertEqual(ot, 1., "getParameter: value unexpected")
     self.assertEqual(st, -1., "getParameter: value unexpected")
     self.assertEqual(nz, 1., "getParameter: value unexpected")
     self.assertEqual(firstB, 0.123, "getParameter: value unexpected")
     self.assertEqual(firstB, firstB2, "getParameter: value unexpected")
     self.assertEqual(delaySBs, 12, "getParameter: value unexpected")
     srp.firstB = 123  # change values
     srp.delaySBs = 456
     firstB = srp.getParameter("firstB")
     delaySBs = srp.getParameter("delaySB_dev")
     self.assertEqual(firstB, 123, "getParameter: value unexpected")
     self.assertEqual(delaySBs, 456, "getParameter: value unexpected")
示例#5
0
 def test_toString(self):
     """ tests __str__ output """
     self.rtp = rb.RootRandomParameter(rb.Organism())
     self.add_successors()
     rtp = self.rtp  # rename
     rtp.name = "the root"
     self.assertEqual(rtp.__str__(False),
                      "Name: the root, organType: 2, subType, -1",
                      "toString: value unexpected")
示例#6
0
 def test_parameter(self):
     """ tests getParameter() """
     otp = rb.OrganRandomParameter(rb.Organism())
     otp.organType = 1
     otp.subType = 2
     ot = otp.getParameter("organType")
     st = otp.getParameter("subType")
     self.assertEqual(ot, 1., "getParameter: value unexpected")
     self.assertEqual(st, 2., "getParameter: value unexpected")
示例#7
0
 def test_constructors(self):
     """ tests three different kinds of constructors """
     human1 = rb.Organism()
     otp = rb.OrganRandomParameter(human1)
     human1.setOrganRandomParameter(otp)
     op = otp.realize()
     # 1. constructor from scratch
     hand = rb.Organ(human1.getOrganIndex(), op, True, True, 0, 15., False, 0)
     hand.setOrganism(human1)
     # 2. used in simulation (must have parent, since there is no nullptr in Pyhton)
     thumb = rb.Organ(human1, hand, 0, 0, 4)
     little_finger = rb.Organ(human1, hand, 0, 0, 3)
     hand.addChild(thumb)
     hand.addChild(little_finger)
     # 3. deep copy (with a factory function)
     human2 = rb.Organism()
     hand2 = hand.copy(human2)
     self.assertEqual(str(hand), str(hand2), "deep copy: the organs shold be equal")
     self.assertIsNot(hand.getParam(), hand2.getParam(), "deep copy: organs have same parameter set")
示例#8
0
 def test_toString(self):
     """ tests __str__ output """
     self.srp = rb.SeedRandomParameter(rb.Organism())
     srp = self.srp  # rename
     srp.name = "the seed"
     # print(srp.__str__(False))
     # print(srp)
     self.assertEqual(srp.__str__(False),
                      "Name: the seed, organType: 1, subType, -1",
                      "toString: value unexpected")
示例#9
0
 def root_example(self):
     """ example root parameters used below """
     self.plant = rb.Organism()
     self.rtp = rb.RootRandomParameter(self.plant)
     self.rtp.la = 1.5
     self.rtp.lb = 5.5
     self.rtp.ln = 1.25
     self.rtp.lns = 0.12
     self.rtp.nob = 8
     self.rtp.subType = 1
示例#10
0
 def test_constructors(self):
     """ tests constructor and copy """
     plant = rb.Organism()
     otp = rb.OrganRandomParameter(plant)
     self.assertEqual(otp.name, "organ", "copy: default value unexpected")
     self.assertEqual(otp.organType, 0, "copy: default value unexpected")
     self.assertEqual(otp.subType, 0, "copy: default value unexpected")
     otp2 = otp.copy(plant)
     self.assertIsNot(otp, otp2, "copy: organ type parameter set is not copied")
     self.assertEqual(otp2.name, otp.name, "copy: value unexpected")
     self.assertEqual(otp2.organType, otp.organType, "copy: value unexpected")
     self.assertEqual(otp2.subType, otp.subType, "copy: value unexpected")
示例#11
0
 def shoot_example(self):
     """ example root parameters used below """
     self.plant = rb.Organism()
     self.srp = rb.SeedRandomParameter(self.plant)
     self.srp.firstB = 10
     self.srp.delayB = 7
     self.srp.nC = 5
     self.srp.firstSB = 21
     self.srp.delaySB = 4
     self.srp.delayRC = 15
     self.srp.nz = 1.
     self.srp.subType = 0
示例#12
0
 def hand_example(self):
     """ an example used in the tests below, a hand with two fingers """
     self.human1 = rb.Organism()  # same example as in test_constructor ...
     otp = rb.OrganRandomParameter(self.human1)
     self.human1.setOrganRandomParameter(otp)
     op = otp.realize()
     self.hand = rb.Organ(self.human1.getOrganIndex(), op, True, True, 0, 15., False, 0)
     self.hand.setOrganism(self.human1)
     self.thumb = rb.Organ(self.human1, self.hand, 0, 0, 4)  # delayedfor 4 days
     self.little_finger = rb.Organ(self.human1, self.hand, 0, 0, 3)  # delayed for 3 days
     self.hand.addChild(self.thumb)
     self.hand.addChild(self.little_finger)
示例#13
0
 def test_organ_type_parameters(self):
     """ test ability to set, get, read, and write type parameters """
     human1 = rb.Organism()  # same example as in test_constructor ...
     otp1 = rb.OrganRandomParameter(human1)
     otp1.name = "nose"
     otp1.subType = 1
     otp2 = rb.OrganRandomParameter(human1)
     otp2.subType = 2
     otp2.name = "eye"
     human1.setOrganRandomParameter(otp1)  # set
     human1.setOrganRandomParameter(otp2)
     otps = human1.getOrganRandomParameter(rb.OrganTypes.organ)
     self.assertEqual(otps[0].name, "nose", "otp: name not expected ")
     self.assertEqual(otps[1].name, "eye", "otp: name not expected ")
     otp3 = rb.OrganRandomParameter(human1)
     otp3.organType = rb.OrganTypes.root
     otp3.subType = 1
     otp3.name = "rootyhand"
     human1.setOrganRandomParameter(otp3)
     human1.writeParameters("human.xml")
     human2 = rb.Organism()  # read again
     prototype1 = rb.OrganRandomParameter(human2)
     prototype1.organType = rb.OrganTypes.organ
     prototype2 = rb.OrganRandomParameter(human2)
     prototype2.organType = rb.OrganTypes.root
     human2.setOrganRandomParameter(
         prototype1
     )  # set prototypes for reading, subTypes are overwritten if equal
     human2.setOrganRandomParameter(prototype2)
     human2.readParameters("human.xml")
     otp1 = human2.getOrganRandomParameter(rb.OrganTypes.organ, 1)
     otp2 = human2.getOrganRandomParameter(rb.OrganTypes.organ, 2)
     self.assertEqual(otp1.name, "nose", "otp: name not expected ")
     self.assertEqual(otp2.name, "eye", "otp: name not expected ")
     self.assertEqual(otp1.subType, 1, "otp: subType not expected ")
     self.assertEqual(otp2.subType, 2, "otp: subType not expected ")
     rtp = human2.getOrganRandomParameter(rb.OrganTypes.root, 1)
     self.assertEqual(rtp.name, "rootyhand", "otp: name not expected ")
     self.assertEqual(rtp.subType, 1, "otp: subType not expected ")
示例#14
0
 def test_xml(self):
     """ write the organ type parameter as xml, and rereads it """
     plant = rb.Organism()
     otp = rb.OrganRandomParameter(plant)
     otp.name = "the great organ"
     otp.organType = 1  # seed
     otp.subType = 2
     otp.writeXML("organ.xml")
     otp2 = rb.OrganRandomParameter(plant)
     otp2.readXML("organ.xml")
     self.assertEqual(otp2.name, otp.name, "xml: value unexpected")
     self.assertEqual(otp2.organType, otp.organType, "xml: value unexpected")
     self.assertEqual(otp2.subType, otp.subType, "xml: value unexpected")
示例#15
0
 def test_constructors(self):
     """ tests constructor and copy """
     plant = rb.Organism()
     srp = rb.SeedRandomParameter(plant)
     srp.firstB = 123
     srp.firstBs = 456
     srp.nz = 789
     srp2 = srp.copy(plant)
     self.assertIsNot(srp, srp2,
                      "copy: organ type parameter set is not copied")
     self.assertEqual(srp2.name, srp.name, "copy: value unexpected")
     self.assertEqual(srp2.organType, srp.organType,
                      "copy: value unexpected")
     self.assertEqual(srp2.subType, srp.subType, "copy: value unexpected")
     self.assertEqual(srp2.firstB, srp.firstB, "copy: value unexpected")
     self.assertEqual(srp2.firstBs, srp.firstBs, "copy: value unexpected")
     self.assertEqual(srp2.nz, srp.nz, "copy: value unexpected")
示例#16
0
 def test_copy(self):
     """ checks if the organism is properly copied """
     self.hand_example()
     self.add_nodes()
     human2 = rb.Organism(self.human1)  # copy constructor
     self.assertIsNot(self.human1, human2, "copy: not a copy")
     self.assertEqual(self.human1.rand(), human2.rand(),
                      "copy: random generator seed was not copied")
     o1 = self.human1.getOrgans()  # check organs
     o2 = human2.getOrgans()
     self.assertEqual(len(o2), 3, "copy: unexpected number of organs")
     for i in range(0, len(o1)):
         self.assertIsNot(o1[i], o2[i], "copy: organ is not copied")
     p1 = self.human1.getOrganRandomParameter(0)
     p2 = human2.getOrganRandomParameter(0)
     for i in range(0, len(p1)):
         self.assertIsNot(p1[i], p2[i],
                          "copy: OrganTypeParameters is not copied")
示例#17
0
 def test_constructors(self):
     """ tests constructor and copy """
     plant = rb.Organism()
     otp = rb.RootRandomParameter(plant)
     otp.theta = 123
     otp.thetas = 456
     otp.gf = 789
     otp2 = otp.copy(plant)
     self.assertIsNot(otp, otp2,
                      "copy: organ type parameter set is not copied")
     self.assertEqual(otp2.name, otp.name, "copy: value unexpected")
     self.assertEqual(otp2.organType, otp.organType,
                      "copy: value unexpected")
     self.assertEqual(otp2.subType, otp.subType, "copy: value unexpected")
     self.assertEqual(otp2.a, otp.a, "copy: value unexpected")
     self.assertEqual(otp2.theta, otp.theta, "copy: value unexpected")
     self.assertEqual(otp2.thetas, otp.thetas, "copy: value unexpected")
     self.assertEqual(otp2.gf, otp.gf, "copy: value unexpected")
示例#18
0
 def test_constructors(self):
     """ tests three different kinds of constructors """
     self.root_example_rtp()
     # 1. constructor from scratch
     param = self.p0.realize()
     root = rb.Root(1, param, True, True, 0., 0., rb.Vector3d(0, 0, -1), 0,
                    0, False, 0)
     root.setOrganism(self.plant)
     root.addNode(rb.Vector3d(0, 0, -3),
                  0)  # parent must have at least one nodes
     # 2. used in simulation (must have parent, since there is no nullptr in Pyhton)
     root2 = rb.Root(self.plant, self.p1.subType, rb.Vector3d(0, 0, -1), 0,
                     root, 0, 0)
     root.addChild(root2)
     # 3. deep copy (with a factory function)
     plant2 = rb.Organism()
     root3 = root.copy(plant2)
     self.assertEqual(str(root), str(root3),
                      "deep copy: the organs shold be equal")
     self.assertIsNot(root.getParam(), root3.getParam(),
                      "deep copy: organs have same parameter set")
示例#19
0
 def test_parameter(self):
     """ tests getParameter() """
     rtp = rb.RootRandomParameter(rb.Organism())
     rtp.lns = 0.123
     rtp.la = 12
     ot = rtp.getParameter("organType")  # test defaults
     st = rtp.getParameter("subType")
     gf = rtp.getParameter("gf")
     ln = rtp.getParameter("ln")
     lns = rtp.getParameter("ln_dev")
     la = rtp.getParameter(
         "la_mean")  # we can always add "_mean" to avoid naming conflicts
     self.assertEqual(ot, 2., "getParameter: value unexpected")
     self.assertEqual(st, -1., "getParameter: value unexpected")
     self.assertEqual(gf, 1., "getParameter: value unexpected")
     self.assertEqual(ln, 1., "getParameter: value unexpected")
     self.assertEqual(lns, 0.123, "getParameter: value unexpected")
     self.assertEqual(la, 12, "getParameter: value unexpected")
     rtp.theta = 123  # change values
     rtp.thetas = 456
     theta = rtp.getParameter("theta")
     thetas = rtp.getParameter("theta_dev")
     self.assertEqual(theta, 123, "getParameter: value unexpected")
     self.assertEqual(thetas, 456, "getParameter: value unexpected")