예제 #1
0
def timer_callback_(obj, ev):
    """ animation call back function (called every 0.1 second) """
    global rootActor
    global c

    c += 1
    print("hello", c)
    rs.simulate(1)
    ana = pb.SegmentAnalyser(rs)
    pd = vp.segs_to_polydata(ana, 1., ["radius", "subType", "creationTime"])
    newRootActor, rootCBar = vp.plot_roots(pd, "creationTime", False)
    renWin = iren.GetRenderWindow()
    ren = renWin.GetRenderers().GetFirstRenderer()
    ren.RemoveActor(rootActor)
    newRootActor.RotateX(-90)
    ren.AddActor(newRootActor)
    ren.ResetCamera()
    rootActor = newRootActor
    iren.Render()

    if c >= max_age:
        c = 0
        rs.initialize()
예제 #2
0
def vector_3d(a):
    return pb.Vector3d(a[0], a[1], a[2])


""" root problem """
r = XylemFluxPython("RootSystem.rsml")  # returns a MappedSegments object
segs = r.rs.segments

nodes = r.rs.nodes
for i in range(0, len(nodes)):
    nodes[i] = vector_3d(np.array(nodes[i]) / 100.)
r.rs.nodes = nodes
""" Mixed plot """
ana = pb.SegmentAnalyser(r.rs)
pd = vp.segs_to_polydata(ana, 1.e-2, ["radius", "subType", "creationTime"])
print("Root system bounds", pd.GetBounds())
rootActor, rootCBar = vp.plot_roots(pd, "creationTime", False)

ug = vp.read_vtu("benchmark3d_2-00001.vtu")
print("Mesh bounds", ug.GetBounds())
meshActor, meshCBar = vp.plot_mesh(
    ug, "water content", "",
    False)  # "pressure head"  # e.g. "S_liq" "water content"

vp.render_window([rootActor, meshActor], "mixed fun", meshCBar).Start()

# # Plot, using vtk
# rootActor, cBar = vp.plot_roots(rs, "creationTime", False)
# rootActor.RotateX(90) # to look at it from top
# vp.render_window(rootActor,"top view", cBar).Start()
예제 #3
0
#     try:
#         x[c] = rs.seg2cell[s.y - 1]
#     except:
#         x[c] = -1

y = np.zeros(x.shape[0])
for i in range(0, x.shape[0]):
   y[i] = i % 2 if x[i] >= 0 else i % 2 - 2  #

for i in range(0, x.shape[0]):
   x[i] = x[i] if x[i] >= 0 else -1

ana = pb.SegmentAnalyser(r.rs)
ana.addData("linear_index", x)  # node data are converted to segment data
ana.addData("zebra", y)
pd = vp.segs_to_polydata(ana, 1., ["radius", "subType", "creationTime", "linear_index", "zebra"])
rootActor, rootCBar = vp.plot_roots(pd, "zebra", False)

""" Mesh """
width_ = max_ - min_
ind_ = res_ / width_
print("min    ", min_)
print("max    ", max_)
print("width  ", width_)
print("cuboids", 1 / ind_)
grid = vp.uniform_grid(min_, max_, res_)
meshActor, meshCBar = vp.plot_mesh(grid, "", "", False)

vp.render_window([meshActor, rootActor], "Test mapping", rootCBar).Start()

예제 #4
0
import rsml_reader as rsml
import estimate_root_params as es
from xylem_flux import XylemFluxPython
import vtk_plot as vp
import plantbox as pb

time = range(1, 3)  # measurement times (not in the rsml)
name = ["RSML/m1/dicot/lupin/lupin_d{:g}.rsml".format(a) for a in range(1, 10)]

# time = range(1, 3)  # measurement times (not in the rsml)
# name = ["RSML/m1/monocot/maize/PL0{:g}_DAS0{:g}.rsml".format(1, a) for a in range(1, 8)]

# time = [75]  # measurement times (not in the rsml)
# name = ["RSML/Maize_Kutschera.rsml"]

rs = XylemFluxPython(
    name[0])  # parses rsml, XylemFluxPython.rs is of type MappedRootSegments
ana = pb.SegmentAnalyser(
    rs.rs)  # convert MappedRootSegments to a SegmentAnalyser

# radii = ana.data["radius"]  # DOES NOT WORK (why?)
# for i in range(0, len(radii)):
#     radii[i] /= 116.93
# ana.data["radius"] = radii

pd = vp.segs_to_polydata(
    ana, 1. /
    116.93)  # makes a vtkPolydata (to save as .vtp, or visualize with vtk)
vp.plot_roots(pd, "radius")  # plots vtkPolydata into an interactive window
예제 #5
0
p_s = np.linspace(-14000, -10000, 3001)
p_s[0:10] = -300
# 3 meter down, resolution in mm, dry with moist top
soil_index = lambda x, y, z: int(-10 * z)
r.rs.setSoilGrid(soil_index)
""" Numerical solution"""
rx = r.solve_neumann(
    simtime, -0., p_s,
    True)  # True: matric potential given per cell (not per segment)

print("Transpiration", r.collar_flux(0., rx, [p_s]), "cm3/day")
eswp = 0.
n = len(r.rs.segments)
seg2cell = r.rs.seg2cell
for i in range(0, n):
    eswp += suf[i] * p_s[seg2cell[i]]

print()
print("Equivalent soil water potential", eswp)

z = r.rs.nodes[1].z
print("Root collar potential          ", rx[1], "node z", z, "psi",
      p_s[soil_index(0, 0, z)])
print()
""" Additional vtk plot """
ana = pb.SegmentAnalyser(r.rs)
ana.addData("rx", rx)  # node data are converted to segment data
pd = vp.segs_to_polydata(
    ana, 1., ["radius", "subType", "creationTime", "length", "rx", "suf"])
vp.plot_roots(pd, "rx")