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)
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")
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
def rs_example_rtp(self): """ an example used in some of the tests below, 100 basals with laterals """ self.rs = rb.RootSystem() srp = rb.SeedRandomParameter(self.rs) srp.subType = 0 srp.seedPos = rb.Vector3d(0., 0., -3.) srp.maxB = 100 srp.firstB = 10 srp.delayB = 3 self.rs.setRootSystemParameter(srp) p0 = rb.RootRandomParameter(self.rs) p0.name, p0.type, p0.la, p0.nob, p0.ln, p0.r, p0.dx = "taproot", 1, 10, 20, 89. / 19., 1, 0.5 p0.lb = 2 p0.successor = a2i([2]) # to rb.std_int_double_() p0.successorP = a2v([1.]) # rb.std_vector_double_() p1 = rb.RootRandomParameter(self.rs) p1.name, p1.type, p1.la, p1.ln, p1.r, p1.dx = "lateral", 2, 25, 0, 2, 0.1 self.p0, self.p1, self.srp = p0, p1, srp # Python will garbage collect them away, if not stored self.rs.setOrganRandomParameter( self.p0) # the organism manages the type parameters self.rs.setOrganRandomParameter(self.p1)
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")
def test_xml(self): """ write the organ as xml, and rereads it """ self.root_example() self.add_successors() otp = self.rtp # rename otp.name = "lateral" otp.subType = 2 otp.writeXML("root.xml") otp2 = rb.RootRandomParameter(self.plant) otp2.readXML("root.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") self.assertEqual(otp2.nob, otp.nob, "xml: value unexpected") # value self.assertEqual(otp2.lns, otp.lns, "xml: value unexpected") # dev for i in range(0, 3): self.assertEqual(otp2.successor[i], otp.successor[i], "xml: value unexpected") for i in range(0, 3): self.assertAlmostEqual(otp2.successorP[i], otp.successorP[i], 7, "xml: value unexpected")
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")
"""everything from scratch (without parameter files)""" import py_rootbox as rb from rb_tools import * import math rs = rb.RootSystem() # Root type parameter p0 = rb.RootRandomParameter(rs) # with default values, p1 = rb.RootRandomParameter(rs) # all standard deviations are 0 p0.name = "taproot" p0.subType = 1 p0.lb = 1 p0.la = 10 p0.nob = 20 p0.ln = 89. / 19. p0.theta = 30. / 180. * math.pi p0.r = 1 p0.dx = 0.5 p0.successor = a2i([2]) # add successors p0.successorP = a2v([1]) p0.tropismT = rb.TropismType.gravi p0.tropismN = 1. p0.tropismS = 0.2 p1.name = "lateral" p1.subType = 2 p1.la = 25 p1.las = 10 # add standard deviation p1.ln = 0