示例#1
0
def extract_at_module_scale(g, vids=[], convert=convert):

    if not vids:
        vids = g.vertices(scale=1)

    orders = algo.orders(g, scale=2)

    module_variables = _module_variables(g)
    visible_modules(g, vids=vids)
    complete_module(g, vids=vids)

    module_ids = [
        v for v in g.property('visible')
        if g.complex_at_scale(v, scale=1) in vids
    ]

    module_df = OrderedDict()
    module_df['Genotype'] = [genotype(mid, g) for mid in module_ids]
    module_df['date'] = [date(mid, g) for mid in module_ids]
    module_df['modality'] = [modality(mid, g) for mid in module_ids]
    module_df['plant'] = [plant(mid, g) for mid in module_ids]
    module_df['order'] = [orders[mid] for mid in module_ids]

    visibles = property(g, 'visible')

    for name in (module_variables):
        f = module_variables[name]
        module_df[name] = [f(mid, g) for mid in module_ids]
    #plant_df['nb_ramifications'] = [sum(1 for v in g.components(pid) if (type_of_crown(v, g)==3 and v in visibles)) for pid in plant_ids]
    module_df['vid'] = module_ids
    module_df['plant_vid'] = [g.complex(v) for v in module_ids]

    df = pd.DataFrame(module_df)
    return df
示例#2
0
def extract_at_plant_scale(g, vids=[], convert=convert):
    """Compute the properties at plant scale of a MTG. 

    :param g: The MTG
    :type g: MTG
    :param vids: list of vids that are included in the extraction at scale 1, defaults to []
    :type vids: list, optional
    :param convert: Dictionary of equivalence of data name from fr to eng , defaults to convert
    :type convert: dict, optional
    :return: A dataframe of computed properties at plant scale
    :rtype: DataFrame
    """

    #TODO: compute this only one. It would be nice if we can compute this in the init of a class Extractor.
    orders = algo.orders(g, scale=2)

    plant_variables = _plant_variables(g)

    # plant_ids is a list of plants we wat to process.
    if not vids:
        plant_ids = g.vertices(scale=1)
    else:
        plant_ids = [pid for pid in g.vertices(scale=1) if pid in vids]

    visible_modules(g, vids=plant_ids)
    compute_leaf_area(g, vids=plant_ids)

    plant_df = OrderedDict()
    # for name in ('Genotype', 'date', 'plant'):
    #     plant_df[name] = [plant_variables[name](pid) for pid in plant_ids]
    plant_df['Genotype'] = [genotype(pid, g) for pid in plant_ids]
    plant_df['date'] = [date(pid, g) for pid in plant_ids]
    plant_df['modality'] = [modality(pid, g) for pid in plant_ids]
    plant_df['plant'] = [plant(pid, g) for pid in plant_ids]

    visibles = property(g, 'visible')

    for name in (plant_variables):
        f = plant_variables[name]
        plant_df[name] = [
            sum(f(v, g) for v in g.components(pid) if v in visibles)
            for pid in plant_ids
        ]

    #plant_df['Total_leaf_area'] = [mean_leaf_area(pid, g) * (sum(nb_visible_leaves(v,g) for v in g.components(pid) if v in visibles) for pid in plant_ids]
    plant_df['leaf_area'] = [mean_leaf_area(pid, g) for pid in plant_ids]
    plant_df['order_max'] = [
        max(orders[v] for v in g.components(pid) if v in visibles)
        for pid in plant_ids
    ]
    plant_df['nb_ramifications'] = [
        sum(1 for v in g.components(pid)
            if (type_of_crown(v, g) == 3 and v in visibles))
        for pid in plant_ids
    ]
    plant_df['vid'] = plant_ids

    df = pd.DataFrame(plant_df)
    return df
示例#3
0
def extract_at_plant_scale(g, vids=[], convert=convert):
    """
    Return computed properties at plant scale

    Parameters
    ----------
    - g: MTG
    - vids : a subset of vertex ids at scale 1

    Returns
    -------
    - a Dataframe
    """
    #TODO: compute this only one. It would be nice if we can compute this in the init of a class Extractor.
    orders = algo.orders(g, scale=2)

    plant_variables = _plant_variables(g)

    # plant_ids is a list of plants we wat to process.
    if not vids:
        plant_ids = g.vertices(scale=1)
    else:
        plant_ids = [pid for pid in g.vertices(scale=1) if pid in vids]

    visible_modules(g, vids=plant_ids)
    compute_leaf_area(g, vids=plant_ids)

    plant_df = OrderedDict()
    # for name in ('Genotype', 'date', 'plant'):
    #     plant_df[name] = [plant_variables[name](pid) for pid in plant_ids]
    plant_df['Genotype'] = [genotype(pid, g) for pid in plant_ids]
    plant_df['date'] = [date(pid, g) for pid in plant_ids]
    plant_df['modality'] = [modality(pid, g) for pid in plant_ids]
    plant_df['plant'] = [plant(pid, g) for pid in plant_ids]

    visibles = property(g, 'visible')

    for name in (plant_variables):
        f = plant_variables[name]
        plant_df[name] = [
            sum(f(v, g) for v in g.components(pid) if v in visibles)
            for pid in plant_ids
        ]

    #plant_df['Total_leaf_area'] = [mean_leaf_area(pid, g) * (sum(nb_visible_leaves(v,g) for v in g.components(pid) if v in visibles) for pid in plant_ids]
    plant_df['leaf_area'] = [mean_leaf_area(pid, g) for pid in plant_ids]
    plant_df['order_max'] = [
        max(orders[v] for v in g.components(pid) if v in visibles)
        for pid in plant_ids
    ]
    plant_df['nb_ramifications'] = [
        sum(1 for v in g.components(pid)
            if (type_of_crown(v, g) == 3 and v in visibles))
        for pid in plant_ids
    ]
    plant_df['vid'] = plant_ids

    df = pd.DataFrame(plant_df)
    return df
def print_2d_single_p(g, genotype, vid):
    with plot2d_single_p:
        plot2d_single_p.clear_output()
        vids_selected = get_vid_of_genotype(g, genotypes=[genotype])
        g.properties()['order'] = orders(g)
        scene = visu2d.plot2d(g, [vids_selected[vid]],
                              dist=[3] * 3,
                              display=False)
        display3d(scene)
示例#5
0
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 print_2d_median(g, genotype):
    with plot2d_most_central:
        plot2d_most_central.clear_output()
        vids_selected = get_vid_of_genotype(g, genotypes=[genotype])
        g.properties()['order'] = orders(g)
        df = extract_at_plant_scale(g, vids=vids_selected)
        df_median = median_individuals(df, )
        # selection of vid of median individuals
        pids = list(df_median.vid)
        n = len(pids)
        scene = visu2d.plot2d(g, pids, dist=[6] * n, display=False)
        display3d(scene)
示例#7
0
def extract_at_node_scale(g, vids=[], convert=convert):

    if not vids:
        vids = g.vertices(scale=1)

    node_df = OrderedDict()
    visible_modules(g, vids=vids)
    complete_module(g, vids=vids)
    orders = algo.orders(g, scale=2)

    # Define all the rows
    props = [
        'node_id', 'rank', 'branching_type', 'complete',
        'nb_modules_branching', 'nb_branch_crown_branching',
        'nb_extension_crown_branching', 'branching_length', 'Genotype',
        'order', 'date', 'plant'
    ]
    for prop in props:
        node_df[prop] = []

    roots = [
        rid for pid in vids for rid in g.component_roots_at_scale(pid, scale=2)
    ]
    trunks = [
        list(
            chain(*[(v for v in algo.axis(g, m, scale=3)
                     if g.label(v) in ('F', 'f'))
                    for m in apparent_axis(g, r)])) for r in roots
    ]

    for trunk in trunks:
        # Define your schema
        for i, vid in enumerate(trunk):
            node_df['node_id'].append(vid)  #scale=3
            node_df['rank'].append(i + 1)  #scale=3
            node_df['branching_type'].append(my_bt(vid, g))  #scale=2
            node_df['complete'].append(my_complete(vid, g))  #scale=2
            node_df['nb_modules_branching'].append(nb_total_module_tree(
                vid, g))  #scale=2
            node_df['nb_branch_crown_branching'].append(
                nb_branching_tree(vid, g))  #scale=2
            node_df['nb_extension_crown_branching'].append(
                nb_extension_tree(vid, g))  #scale=2
            node_df['branching_length'].append(nb_visible_leaves_tree(vid, g))
            node_df['Genotype'].append(genotype(vid, g))  #scale=1
            node_df['order'].append(orders[g.complex(vid)])  #scale=2
            node_df['plant'].append(plant(vid, g))  #scale=1
            node_df['date'].append(date(vid, g))  #scale=1

    df = pd.DataFrame(node_df)

    return df
示例#8
0
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 print_3d_floral_intensity(g, genotype):
    if g:
        with plot3d_floral_intensity:
            plot3d_floral_intensity.clear_output()
            print('3d floral_intensity ')
            vids_selected = get_vid_of_genotype(g, genotypes=[genotype])
            g.properties()['order'] = orders(g)
            scene = visu3d.plot3d(g,
                                  by=["Sample_date"],
                                  hide_leaves=True,
                                  display=False,
                                  vids=vids_selected)
            display3d(scene)
    else:
        with plot3d_floral_intensity:
            plot3d_floral_intensity.clear_output()
            print('Select a Genotype')
def print_3d_growth_developement(g, genotype):
    if g:
        with plot3d_growth_developement:
            plot3d_growth_developement.clear_output()
            print('3d growth developement')
            vids_selected = get_vid_of_genotype(g, genotypes=[genotype])
            g.properties()['order'] = orders(g)
            scene = visu3d.plot3d(g,
                                  by=["Sample_date"],
                                  hide_leaves=False,
                                  display=False,
                                  vids=vids_selected)
            display3d(scene)
    else:
        with plot3d_growth_developement:
            plot3d_growth_developement.clear_output()
            print('Select a Genotype')
示例#11
0
def extract_at_module_scale(g, vids=[], convert=convert):
    """Compute the properties at module scale of a MTG. 

    :param g: The MTG
    :type g: MTG
    :param vids: list of vids that are included in the extraction at scale 1, defaults to []
    :type vids: list, optional
    :param convert: Dictionary of equivalence of data name from fr to eng , defaults to convert
    :type convert: dict, optional
    :return: A dataframe of computed properties at module scale
    :rtype: DataFrame
    """

    if not vids:
        vids = g.vertices(scale=1)

    orders = algo.orders(g, scale=2)

    module_variables = _module_variables(g)
    visible_modules(g, vids=vids)
    complete_module(g, vids=vids)

    module_ids = [
        v for v in g.property('visible')
        if g.complex_at_scale(v, scale=1) in vids
    ]

    module_df = OrderedDict()
    module_df['Genotype'] = [genotype(mid, g) for mid in module_ids]
    module_df['date'] = [date(mid, g) for mid in module_ids]
    module_df['modality'] = [modality(mid, g) for mid in module_ids]
    module_df['plant'] = [plant(mid, g) for mid in module_ids]
    module_df['order'] = [orders[mid] for mid in module_ids]

    visibles = property(g, 'visible')

    for name in (module_variables):
        f = module_variables[name]
        module_df[name] = [f(mid, g) for mid in module_ids]
    #plant_df['nb_ramifications'] = [sum(1 for v in g.components(pid) if (type_of_crown(v, g)==3 and v in visibles)) for pid in plant_ids]
    module_df['vid'] = module_ids
    module_df['plant_vid'] = [g.complex(v) for v in module_ids]

    df = pd.DataFrame(module_df)
    return df
示例#12
0
def to_dataframe(g, vertices=[], f=None):
    """Convert an MTG into a full dataframe.

    :param g: MTG graph
    :type g: MTG
    :param vertices: define the vertices you want to export, defaults to []
    :type vertices: list, optional
    :param f: v -> dict : function that returns a set of properties for any vertex, defaults to None
    :type f: function, optional
    :return: A dataframe that include all the MTG properties
    :rtype: DataFrame
    """

    # Recompute the properties for each vertices
    if not vertices:
        vertices = g.vertices()

    if f is None:
        f = lambda v: g[v]

    d = dict()
    for v in vertices:
        props_v = f(v)
        for k, value in props_v.items():
            d.setdefault(k, {})[v] = value

    parents = g._parent
    complexes = {
        vid: g.complex(vid)
        for vid in g if g.complex(vid) is not None
    }
    scales = g._scale
    _orders = orders(g)

    d['parent'] = {v: parents.get(v) for v in vertices}
    d['complex'] = {v: complexes.get(v) for v in vertices}
    d['scale'] = {v: scales.get(v) for v in vertices}
    d['order'] = {v: _orders.get(v) for v in vertices}

    dataframe = pd.DataFrame.from_dict(d)
    return dataframe
def to_dataframe(g, vertices=[], f=None):
    """ Convert an MTG into a full dataframe.

    Properties:
      - vertices: define the vertices you want to export
      - f : v -> dict : function that returns a set of properties for any vertex.

    """

    # Recompute the properties for each vertices
    if not vertices:
        vertices = g.vertices()

    if f is None:
        f = lambda v: g[v]

    d = dict()
    for v in vertices:
        props_v = f(v)
        for k, value in props_v.iteritems():
            d.setdefault(k, {})[v] = value

    parents = g._parent
    complexes = {
        vid: g.complex(vid)
        for vid in g if g.complex(vid) is not None
    }
    scales = g._scale
    _orders = orders(g)

    d['parent'] = {v: parents.get(v) for v in vertices}
    d['complex'] = {v: complexes.get(v) for v in vertices}
    d['scale'] = {v: scales.get(v) for v in vertices}
    d['order'] = {v: _orders.get(v) for v in vertices}

    dataframe = pd.DataFrame.from_dict(d)
    return dataframe
示例#14
0
def extract_at_node_scale(g, vids=[], convert=convert):
    """Compute the properties at node scale of a MTG. 

    :param g: The MTG
    :type g: MTG
    :param vids: list of vids that are included in the extraction at scale 1, defaults to []
    :type vids: list, optional
    :param convert: Dictionary of equivalence of data name from fr to eng , defaults to convert
    :type convert: dict, optional
    :return: A dataframe of computed properties at node scale
    :rtype: DataFrame
    """

    if not vids:
        vids = g.vertices(scale=1)

    node_df = OrderedDict()
    visible_modules(g, vids=vids)
    complete_module(g, vids=vids)
    orders = algo.orders(g, scale=2)

    # Define all the rows
    props = [
        'node_id', 'rank', 'branching_type', 'complete',
        'nb_modules_branching', 'nb_branch_crown_branching',
        'nb_extension_crown_branching', 'branching_length', 'stage',
        'Genotype', 'order', 'date', 'plant'
    ]
    for prop in props:
        node_df[prop] = []

    roots = [
        rid for pid in vids for rid in g.component_roots_at_scale(pid, scale=2)
    ]
    trunks = [
        list(
            chain(*[(v for v in algo.axis(g, m, scale=3)
                     if g.label(v) in ('F', 'f'))
                    for m in apparent_axis(g, r)])) for r in roots
    ]

    for trunk in trunks:
        # Define your schema
        for i, vid in enumerate(trunk):
            node_df['node_id'].append(vid)  #scale=3
            node_df['rank'].append(i + 1)  #scale=3
            node_df['branching_type'].append(my_bt(vid, g))  #scale=2
            node_df['complete'].append(my_complete(vid, g))  #scale=2
            node_df['nb_modules_branching'].append(nb_total_module_tree(
                vid, g))  #scale=2
            node_df['nb_branch_crown_branching'].append(
                nb_branching_tree(vid, g))  #scale=2
            node_df['nb_extension_crown_branching'].append(
                nb_extension_tree(vid, g))  #scale=2
            node_df['branching_length'].append(nb_visible_leaves_tree(vid, g))
            node_df['Genotype'].append(genotype(vid, g))  #scale=1
            node_df['order'].append(orders[g.complex(vid)])  #scale=2
            node_df['plant'].append(plant(vid, g))  #scale=1
            node_df['date'].append(date(vid, g))  #scale=1
            node_df['stage'].append(stage(vid, g))  # scale=3

    df = pd.DataFrame(node_df)

    return df
示例#15
0
def load_mtg(fn):
    g = MTG(fn)
    g = transform_date(g)
    g.properties()['order'] = orders(g)

    return g