1. Quick Start to manipulate MTGs¶
1.1. Reading an MTG file and activate it¶
A plant architecture described in a coding file can be loaded in
openalea.mtg.aml as follows:
>>> from openalea.mtg.aml import MTG >>> g1 = MTG('user/agraf.mtg') # some errors may occur while loading the MTG ERROR: Missing component for vertex 2532
The MTG function attempts to read a valid MTG description and parses the coding file. If errors are detected during the parsing, they are displayed on the screen and the parsing fails. In this case, no MTG is built and the user should make corrections to the coding file. If the parsing succeeds, this function creates an internal representation of the plant (or a set of plants) encoded as a MTG. In this example, the MTG object is stored in variable g1 for further use. Note that a MTG should always be stored in a variable otherwise it is destroyed immediately after its building. The last built MTG is considered as the “active” MTG. It is used as an implicit argument by all the functions of the MTG module.
It is possible to change the active MTG using
g1 = MTG("filename1") # g1 is the current MTG g2 = MTG("filename2") # g2 becomes the current MTG Activate(g1) # g1 is now again the current MTG
the notion of activation is very important. Each call to a function in the package MTG will look at the active MTG.
PlantFrame is still in development and not all MTG files can be plotted with the current code, especially the files that have no information about positions
The following examples shows how to plot the contents of a MTG given that a dressing data file (DRF) is available. See the File syntax section for more information about the MTG and DRF syntax. Note that the following code should be simplified in the future.
1 2 3 4 5 6 7 8 9 10 11 12
from openalea.mtg.aml import MTG from openalea.mtg.dresser import dressing_data_from_file from openalea.mtg.plantframe import PlantFrame, compute_axes, build_scene g = MTG('agraf.mtg') dressing_data = dressing_data_from_file('agraf.drf') topdia = lambda x: g.property('TopDia').get(x) pf = PlantFrame(g, TopDiameter=topdia, DressingData = dressing_data) axes = compute_axes(g, 3, pf.points, pf.origin) diameters = pf.algo_diameter() scene = build_scene(pf.g, pf.origin, axes, pf.points, diameters, 10000) from vplants.plantgl.all import Viewer Viewer.display(scene)