def test_extraction_at_node_scale(): files = shared_data(openalea.strawberry).glob('*.mtg') mtg_path = dict((name(f), f) for f in files) gariguette = read_mtg_file(mtg_path['Gariguette']) gariguette_extraction_at_node_scale = extract_at_node_scale(gariguette) assert len(gariguette_extraction_at_node_scale) == 784 gariguette_axillary_prod = prob_axillary_production(gariguette, order=0) assert len(gariguette_axillary_prod) == 19
def test4(): from openalea.core import alea from openalea.mtg.io import read_mtg_file fn = alea.run(('demo.mtg', 'agraf.mtg'), [])[0] g = read_mtg_file(fn) param = Quaking_Aspen() param.order = 2 wp = Weber_MTG(param, g) wp.run()
def __test_2D(): files = shared_data(openalea.strawberry).glob('*.mtg') mtg_path = dict((name(f), f) for f in files) gariguette = read_mtg_file(mtg_path['Gariguette']) gariguette.properties()['order'] = orders(gariguette) scene = visu2d.plot2d(gariguette, gariguette.vertices(scale=1)[53:54], dist=[3] * 3, display=False) PlantGL(scene)
def test_3D(): files = shared_data(openalea.strawberry).glob('*.mtg') mtg_path = dict((name(f), f) for f in files) gariguette = read_mtg_file(mtg_path['Gariguette']) gariguette.properties()['order'] = orders(gariguette) scene = visu3d.plot3d(gariguette, by=["Sample_date"], hide_leaves=False, display=False) assert scene.isValid() == True p = PlantGL(scene, group_by_color=True) assert len(p.object_ids) == 103
def test_extract_at_module_scale(): files = shared_data(openalea.strawberry).glob('*.mtg') mtg_path = dict((name(f), f) for f in files) gariguette = read_mtg_file(mtg_path['Gariguette']) gariguette_extraction_at_module_scale = extract_at_module_scale(gariguette) assert len(gariguette_extraction_at_module_scale) == 241 gariguette_frequency = occurence_module_order_along_time(data= gariguette_extraction_at_module_scale,frequency_type= "cdf") assert len(gariguette_frequency) == 6 mean= gariguette_extraction_at_module_scale.groupby(["Genotype", "order"]).mean() sd= gariguette_extraction_at_module_scale.groupby(["Genotype", "order"]).std() assert len(mean) == 6 assert len(sd) == 6
def weber_penn_mtg(mtg_file, parameters, seed, position): if not parameters or not mtg_file: raise WeberPennError( "Unable to run the Weber and Penn model without parameters.") random.seed(seed) if isinstance(mtg_file, str): g = read_mtg_file(mtg_file) else: g = mtg_file client = Weber_MTG(parameters, g) client.run() scene = client.plot() return scene,
def on_change_get_files(widget, event, data): # load mtgs misc.all_mtg = MTG() for file in data: g = read_mtg_file(file_paths[file]) misc.all_mtg = union(misc.all_mtg, g) # update table if misc.all_mtg: df = get_table_mtg(misc.all_mtg) # TODO: update_grid(df, tableMTG) else: update_grid(pd.DataFrame(), tableMTG) # update genotype selections update_selection_items() # update file description print_files_description()
def test_df2waffle(): files = shared_data(openalea.strawberry).glob('*.mtg') mtg_path = dict((name(f), f) for f in files) mtg = read_mtg_file(mtg_path['Capriss']) df = extract_at_node_scale(mtg) node_scale = df2waffle(df, index='rank', date='2015/03/02', variable='branching_type') assert node_scale.shape == (20, 9) df = extract_at_module_scale(mtg) module_scale = df2waffle(df, index='order', date='2015/03/02', variable='crown_status', aggfunc='median') assert module_scale.shape == (3, 9)
def test_extract_at_plant_scale(): files = shared_data(openalea.strawberry).glob('*.mtg') mtg_path = dict((name(f), f) for f in files) mtg = MTG() for k, genotype in enumerate(mtg_path): if (genotype=="Sicile") or (genotype=="Nils") or (genotype=='origine_stolon_gariguetteDV_6novembre2018') \ or (genotype=='friendlyfruit_varieties'): pass else: mtg = union(mtg, read_mtg_file(mtg_path[genotype])) genotypes = mtg.property('Genotype') for geno in set(genotypes.values()): vids = [ vid for vid in mtg.vertices(scale=1) if genotypes.get(vid) == geno ] df = extract_at_plant_scale(mtg, vids) assert not df.empty assert set(df['Genotype']) == {geno}
def MTG(filename): """ MTG constructor. Builds a MTG from a coding file (text file) containing the description of one or several plants. :Usage: :: MTG(filename) :Parameters: - `filename` (str): name of the coding file describing the mtg :Returns: If the parsing process succeeds, returns an object of type :func:`MTG`. Otherwise, an error is generated, and the formerly active `MTG` remains active. :Side Effect: If the :func:`MTG` is built, the new :func:`MTG` becomes the active :func:`MTG` (i.e. the :func:`MTG` implicitly used by other functions such as :func:`Father()`, :func:`Sons()`, :func:`VtxList()`, ...). :Details: The parsing process is approximatively proportional to the number of components defined in the coding file. :Background: MTG is an acronyme for Multiscale Tree Graph. .. seealso:: :func:`Activate` and all :mod:`openalea.mtg.aml` functions. """ global _g _g = read_mtg_file(filename) return _g
import openalea.mtg.io as io reload(io) #io.debug = 1 fn = r'data/agraf.mtg' fn2 = r'data/rapple.mtg' #fn = r'data/mtg5.mtg' """ f = open(fn) s = f.read() f.close() r = io.Reader(s) # skip the header r.header() # read the MTG header r._nb_feature=2 r._feature_head = ['nbEl', 'diam'] r._feature_slice=slice(5,7) #debug r.preprocess_code() print r._new_code """ g = io.read_mtg_file(fn)
def test_import_mtg(): files = shared_data(openalea.strawberry).glob('*.mtg') mtg_path = dict((name(f), f) for f in files) gariguette = read_mtg_file(mtg_path['Gariguette']) straws = split(gariguette) assert isinstance(straws[0], openalea.mtg.mtg.MTG)