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()
# 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()
True) # cut and map segments """ add segment indices """ segs = rs.segments x = np.zeros(len(segs)) for i, s in enumerate(segs): try: x[i] = rs.seg2cell[i] except: # in case the segment is not within the domain x[i] = -1 """ infos on a specific cell""" ci = rs.soil_index(0, 0, -7) print("Cell at [0,0,-7] has index", ci) try: print(len(rs.cell2seg[ci]), "segments in this cell:") print(rs.cell2seg[ci]) except: print("There are no segments in this cell") """ vizualise roots """ # ana = pb.SegmentAnalyser(rs) # <---- wrong! ana = pb.SegmentAnalyser(rs.mappedSegments()) ana.addData("linear_index", x) pd = vp.segs_to_polydata(ana, 1., ["radius", "subType", "creationTime", "linear_index"]) rootActor, rootCBar = vp.plot_roots(pd, "linear_index", "segment index plot", False) """ vizualise soil """ grid = vp.uniform_grid(min_, max_, res_) # for visualization meshActor, meshCBar = vp.plot_mesh(grid, "", "", False) vp.render_window([meshActor, rootActor], "Test mapping", rootCBar, grid.GetBounds()).Start()
rs.getNumberOfSegments()) # shoot segments are mapped ana = pb.SegmentAnalyser( rs.mappedSegments() ) # rs is MappedSegments and RootSystem. So passing rs it is not unique which constructor is called. print("Number of segments", len(ana.segments), "x", len(x), "and", len(y)) ana.addData("linear_index", x) # node data are converted to segment data ana.addData("zebra", y) ana.mapPeriodic(max_[0] - min_[0], max_[1] - min_[1]) # data are also split pd = vp.segs_to_polydata( ana, 1., ["radius", "subType", "creationTime", "linear_index", "zebra"]) rootActor, rootCBar = vp.plot_roots(pd, "linear_index", 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() grid = vp.uniform_grid(min_, max_, res_) actors = vp.plot_mesh_cuts(pd, "linear_index") print(actors) print(len(actors)) # actors.extend([rootActor]) vp.render_window(actors, "Test mapping", rootCBar).Start()
import numpy as np import matplotlib.pyplot as plt """ root problem """ rs = pb.RootSystem() path = "../../../../modelparameter/rootsystem/" name = "Anagallis_femina_Leitner_2010" rs.readParameters(path + name + ".xml") for p in rs.getRootRandomParameter(): # Modify axial resolution p.dx = 5 # [cm] adjust resolution rs.initialize() """ initial growth """ rs.simulate(1) ana = pb.SegmentAnalyser(rs) pd = vp.segs_to_polydata(ana, 1., ["radius", "subType", "creationTime"]) rootActor, rootCBar = vp.plot_roots(pd, "creationTime", False) iren = vp.render_window(rootActor, "Animation", rootCBar) c = 0 max_age = 60 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"])