Ejemplo n.º 1
0
def PlantGL(scene):
    fn = tempfile.mktemp(suffix=".png")
    Viewer.frameGL.setBgColor(255, 255, 255)
    Viewer.animation(True)
    Viewer.display(scene)
    Viewer.saveSnapshot(fn, "png")
    img = Image(fn)
    os.unlink(fn)
    return img
Ejemplo n.º 2
0
def color_MTG_Nitrogen(g, df, t, SCREENSHOT_DIRPATH):
    def color_map(N):
        if 0 <= N <= 0.5:  # TODO: organe senescent (prendre prop)
            vid_colors = [150, 100, 0]
        elif 0.5 < N < 5:  # Fvertes
            vid_colors = [int(255 - N * 51), int(255 - N * 20), 50]
        else:
            vid_colors = [0, 155, 0]
        return vid_colors

    def calculate_Total_Organic_Nitrogen(amino_acids, proteins, Nstruct):
        """Total amount of organic N (amino acids + proteins + Nstruct).

        :param float amino_acids: Amount of amino acids (µmol N)
        :param float proteins: Amount of proteins (µmol N)
        :param float Nstruct: Structural N mass (g)

        :return: Total amount of organic N (mg)
        :rtype: float
        """
        return (amino_acids + proteins) * 14E-3 + Nstruct * 1E3

    colors = {}

    groups_df = df.groupby(['plant', 'axis', 'metamer', 'organ', 'element'])
    for vid in g.components_at_scale(g.root, scale=5):
        pid = int(g.index(g.complex_at_scale(vid, scale=1)))
        axid = g.property('label')[g.complex_at_scale(vid, scale=2)]
        mid = int(g.index(g.complex_at_scale(vid, scale=3)))
        org = g.property('label')[g.complex_at_scale(vid, scale=4)]
        elid = g.property('label')[vid]
        id_map = (pid, axid, mid, org, elid)
        if id_map in groups_df.groups.keys():
            N = (g.property('proteins')[vid] *
                 14E-3) / groups_df.get_group(id_map)['mstruct'].iloc[0]
            # N = (calculate_Total_Organic_Nitrogen(g.property('amino_acids')[vid], g.property('proteins')[vid], g.property('Nstruct')[vid])) / g.property('mstruct')[vid]
            colors[vid] = color_map(N)
        else:
            g.property('geometry')[vid] = None

    # plantgl
    s = to_plantgl(g, colors=colors)[0]
    Viewer.add(s)
    Viewer.camera.setPosition(Vector3(83.883, 12.3239, 93.4706))
    Viewer.camera.lookAt(Vector3(0., 0, 50))
    Viewer.saveSnapshot(
        os.path.join(SCREENSHOT_DIRPATH, 'Day_{}.png'.format(t / 24 + 1)))