forked from Plant-Root-Soil-Interactions-Modelling/CRootBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example4c.py
94 lines (79 loc) · 2.48 KB
/
example4c.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import py_rootbox as rb
import math
rs = rb.RootSystem()
name = "Anagallis_femina_Leitner_2010"
rs.openFile(name)
# box with a left and a right compartment for analysis
sideBox = rb.SDF_PlantBox(10,20,50)
left = rb.SDF_RotateTranslate(sideBox, rb.Vector3d(-4.99,0,0))
right = rb.SDF_RotateTranslate(sideBox, rb.Vector3d(4.99,0,0))
leftright = rb.SDF_Union(left,right)
rs.setGeometry(leftright)
# left compartment has a minimum of 0.01, 1 elsewhere
maxS = 1. # maximal
minS = 0.01 # minimal
slope = 1. # [cm] linear gradient between min and max
leftC = rb.SDF_Complement(left)
soilprop = rb.SoilLookUpSDF(leftC, maxS, minS, slope) # for root elongation
soilprop2 = rb.SoilLookUpSDF(left, 1., 0.002, slope) # for branching
# Manually set scaling function and tropism parameters
sigma = [0.4, 1., 1., 1., 1. ] * 2
for i in range(0,10):
p = rs.getRootTypeParameter(i+1)
p.dx = 0.25 # adjust resolution
p.tropismS = sigma[i]
# 1. Scale elongation
p.se = soilprop
# # 2. Scale insertion angle
# p.sa = soilprop
# # 3. Scale branching probability
# p = rs.getRootTypeParameter(2)
# p.ln = p.ln/5
# p.nob = p.nob*5
# p = rs.getRootTypeParameter(3)
# p.sbp = soilprop2
# simulation
rs.initialize()
simtime = 120.
dt = 1.
N = 120/dt
for i in range(0,round(N)):
rs.simulate(dt,True)
# analyse
print()
print("Left compartment: ")
al = rb.SegmentAnalyser(rs)
al.crop(left)
ll = al.getSummed(rb.ScalarType.length)
print('Total root length', ll, 'cm')
lmct = al.getSummed(rb.ScalarType.time)/al.getSummed(rb.ScalarType.one)
print('Mean age', simtime-lmct, 'days')
lroots = al.getRoots()
lm_theta = 0
for r in lroots:
lm_theta += r.param.theta
lm_theta /= len(lroots)
print('Mean insertion angle is ', lm_theta/math.pi*180, 'degrees')
print()
print("Right compartment: ")
ar = rb.SegmentAnalyser(rs)
ar.crop(right)
lr = ar.getSummed(rb.ScalarType.length)
print('Total root length', lr, 'cm')
rmct = ar.getSummed(rb.ScalarType.time)/ar.getSummed(rb.ScalarType.one)
print('Mean age', simtime-rmct, 'days')
rroots = ar.getRoots()
rm_theta = 0
for r in lroots:
rm_theta += r.param.theta
rm_theta /= len(rroots)
print('Mean insertion angle is ', rm_theta/math.pi*180, 'degrees')
print()
# write results
rs.write("results/example_4c1.py") # compartment geometry
rs.write("results/example_4c1.vtp") # root system
# class MySoil(rb.SoilPropertySDF): # todo
# def getValue(p, r):
# print("haha")
# return 1.
# mysoil = MySoil(leftC, maxS, minS, slope)