Esempio n. 1
0
def plot_figure_8():
    """Generates figure 8 of the paper. This figure shows a snapshot at solar midday of leaf temperature distribution
    across three virtual canopies.
    """
    training_color = {'gdc': 'blue', 'vsp': 'red', 'lyre': 'green'}

    obs_date = datetime(
        2009,
        7,
        29,
        14,
        00,
        0,
    )

    fig, axs = pyplot.subplots(nrows=3,
                               ncols=2,
                               sharex=True,
                               figsize=(6.69, 6),
                               gridspec_kw={'width_ratios': [0.8, 0.2]})

    for i, training in enumerate(('vsp', 'gdc', 'lyre')):
        pth = example_pth / 'virtual_canopies' / training

        g, _ = mtg_load(
            str(pth) + '/output/', 'mtg%s' % obs_date.strftime('%Y%m%d%H%M%S'))

        axs[i, 0] = display.property_map(g,
                                         'Tlc',
                                         color=training_color[training],
                                         ax=axs[i, 0])
        axs[i, 0].set(ylim=(0, 250))
        axs[i, 0].legend([training], prop={'size': 11})
        axs[i, 0].xaxis.labelpad = 5

        axs[i, 1].boxplot(g.property('Tlc').values(), vert=False, sym='')

    # some layout
    [ax.set_xlabel('') for ax in axs[:2, 0]]

    for ax in axs[:, 1]:
        ax.tick_params(axis='y', which='both', labelleft='off')
        ax.set_xticklabels(range(32, 42), rotation=90)

    axs[2, 1].set_xlabel('$\mathregular{T_{leaf}\/[^{\circ}C]}$')

    fig.tight_layout()

    fig.savefig('fig_8.png', dpi=600.)
    pyplot.close(fig)
Esempio n. 2
0
def plot_figure_12():
    """Generates figure 12 of the paper. This figure compares, leaf-to-leaf, simulated to observed leaf and leaf-to-air
    temperature.
    """

    fig, axs = pyplot.subplots(ncols=3, figsize=(6.69, 2.7))
    [ax.grid() for ax in axs]

    daily_temp_obs = np.array([])
    daily_temp_sim = np.array([])
    daily_temp_air = np.array([])

    for iax, training in enumerate(('vsp_ww_grapevine', 'vsp_ws_grapevine')):

        pth = example_pth / training

        # set dates ************************
        beg_date = datetime(
            2009,
            7,
            29,
            00,
            00,
            0,
        )
        end_date = datetime(
            2009,
            8,
            1,
            23,
            00,
            0,
        )
        datet = pd.date_range(beg_date, end_date, freq='H')

        # read observations
        obs = pd.read_csv(pth / 'temp.obs',
                          sep=';',
                          decimal='.',
                          index_col='date')
        obs.index = [datetime.strptime(s, "%d/%m/%Y %H:%M") for s in obs.index]

        # read simulations
        sims = pd.read_csv(pth / 'output' / 'time_series.output',
                           sep=';',
                           decimal='.',
                           index_col='time')
        sims.index = [
            datetime.strptime(s, "%Y-%m-%d %H:%M:%S") for s in sims.index
        ]
        sims.index = pd.DatetimeIndex(sims.index)

        # plot simulated temperature magnitude
        med_sim = np.array([])
        q_1_sim = np.array([])
        q_3_sim = np.array([])
        for date in datet:
            g, _ = mtg_load(
                str(pth) + '/output/', 'mtg%s' % date.strftime('%Y%m%d%H%M%S'))
            leaf_temp_sim = g.property('Tlc').values()
            q_1_sim = np.append(q_1_sim, min(leaf_temp_sim))
            q_3_sim = np.append(q_3_sim, max(leaf_temp_sim))
            med_sim = np.append(med_sim, np.median(leaf_temp_sim))
            print(date)

        # get observed temperature magnitude
        med_obs = np.array([])
        q1_obs = np.array([])
        q3_obs = np.array([])
        for row, date in enumerate(datet):
            pos = date.toordinal() + date.hour / 24.
            leaf_temp_obs = obs.loc[
                date, ['Tleaf%d' % d for d in (2, 3, 4, 5, 6, 8, 9, 10)]]
            leaf_temp_obs = leaf_temp_obs[~np.isnan(leaf_temp_obs)]
            q1_obs = np.append(q1_obs, min(leaf_temp_obs))
            q3_obs = np.append(q3_obs, max(leaf_temp_obs))
            med_obs = np.append(med_obs, np.median(leaf_temp_obs))
            print(date)

        # read meteo data
        meteo_df = pd.read_csv(pth / 'meteo.input',
                               sep=';',
                               decimal='.',
                               index_col='time')
        meteo_df.index = pd.DatetimeIndex(meteo_df.index)

        air_temperature = meteo_df.loc[datet, 'Tac']

        daily_temp_obs = np.append(daily_temp_obs, q1_obs)
        daily_temp_obs = np.append(daily_temp_obs, q3_obs)

        daily_temp_sim = np.append(daily_temp_sim, q_1_sim)
        daily_temp_sim = np.append(daily_temp_sim, q_3_sim)

        daily_temp_air = np.append(daily_temp_air, air_temperature)
        daily_temp_air = np.append(daily_temp_air, air_temperature)

        # minimum temperature
        axs[0].plot(q1_obs - air_temperature,
                    q_1_sim - air_temperature, ['b^', 'r^'][iax],
                    label=['WW', 'WD'][iax])
        # maximum temperature
        axs[0].plot(q3_obs - air_temperature,
                    q_3_sim - air_temperature, ['bo', 'ro'][iax],
                    label=['WW', 'WD'][iax])

        axs[1].plot(q1_obs,
                    q_1_sim, ['b^', 'r^'][iax],
                    label=['WW', 'WD'][iax])
        axs[1].plot(q3_obs,
                    q_3_sim, ['bo', 'ro'][iax],
                    label=['WW', 'WD'][iax])

        axs[2].plot(q3_obs - q1_obs,
                    q_3_sim - q_1_sim, ['bs', 'rs'][iax],
                    label=['WW', 'WD'][iax])

    # some layout
    axs[0].plot((-8, 12), (-8, 12), 'k--')
    axs[0].set(xlabel='$\mathregular{T_{leaf, obs}-T_{air}\/[^\circ C]}$',
               ylabel='$\mathregular{T_{leaf, sim}-T_{air}\/[^\circ C]}$',
               xlim=(-8, 12),
               ylim=(-8, 12))

    axs[1].plot((10, 45), (10, 45), 'k--')
    axs[1].set(xlabel='$\mathregular{T_{leaf, obs}\/[^\circ C]}$',
               ylabel='$\mathregular{T_{leaf, sim}\/[^\circ C]}$')
    axs[1].xaxis.set_major_locator(ticker.MultipleLocator(20))

    axs[2].plot((-2, 14), (-2, 14), 'k--')
    axs[2].set(xlabel='$\mathregular{\Delta T_{leaf, obs}\/[^\circ C]}$',
               ylabel='$\mathregular{\Delta T_{leaf, sim}\/[^\circ C]}$')
    axs[2].xaxis.set_major_locator(ticker.IndexLocator(base=2, offset=2))
    axs[2].xaxis.set_major_locator(ticker.MultipleLocator(5))

    for i in range(3):
        if i == 0:
            x, y = daily_temp_obs - daily_temp_air, daily_temp_sim - daily_temp_air
        elif i == 1:
            x, y = daily_temp_obs, daily_temp_sim
        else:
            x = np.array([])
            x = np.append(x, daily_temp_obs[96:2 * 96] - daily_temp_obs[:96])
            x = np.append(
                x,
                daily_temp_obs[3 * 96:4 * 96] - daily_temp_obs[2 * 96:3 * 96])
            y = np.array([])
            y = np.append(y, daily_temp_sim[96:2 * 96] - daily_temp_sim[:96])
            y = np.append(
                y,
                daily_temp_sim[3 * 96:4 * 96] - daily_temp_sim[2 * 96:3 * 96])

        diff_y_x = (y - x)[~np.isnan(y - x)]
        bias = (diff_y_x).mean()
        rmse = np.sqrt((diff_y_x**2).mean())

        axs[i].text(0.05,
                    -0.6,
                    '$\mathregular{MBE\/=\/%.3f}$' % bias,
                    transform=axs[i].transAxes,
                    fontdict={'size': 11})
        axs[i].text(0.05,
                    -0.7,
                    '$\mathregular{RMSE\/=\/%.1f}$' % rmse,
                    transform=axs[i].transAxes,
                    fontdict={'size': 11})

        axs[i].text(0.05,
                    0.875, ['(a)', '(b)', '(c)'][i],
                    transform=axs[i].transAxes,
                    fontdict={'size': 11})

    fig.tight_layout()
    fig.subplots_adjust(bottom=0.4)
    fig.savefig('fig_12.png', dpi=600.)
    pyplot.close(fig)
Esempio n. 3
0
def plot_figure_11():
    """Generates figure 11 of the paper. This figure compares simulated to observed leaf temperatures.
    """
    fig, axs = pyplot.subplots(nrows=2,
                               ncols=2,
                               sharey='row',
                               figsize=(6.69, 6))

    for iax, training in enumerate(('vsp_ww_grapevine', 'vsp_ws_grapevine')):
        pth = example_pth / training
        axs[0, iax].grid()
        axs[1, iax].grid()

        # set dates ************************
        beg_date = datetime(
            2009,
            7,
            29,
            00,
            00,
            0,
        )
        end_date = datetime(
            2009,
            8,
            1,
            23,
            00,
            0,
        )
        datet = pd.date_range(beg_date, end_date, freq='H')

        # read observations
        obs = pd.read_csv(pth / 'temp.obs',
                          sep=';',
                          decimal='.',
                          index_col='date')
        obs.index = [datetime.strptime(s, "%d/%m/%Y %H:%M") for s in obs.index]

        # read simulations
        sims = pd.read_csv(pth / 'output' / 'time_series.output',
                           sep=';',
                           decimal='.',
                           index_col='time')
        sims.index = [
            datetime.strptime(s, "%Y-%m-%d %H:%M:%S") for s in sims.index
        ]
        sims.index = pd.DatetimeIndex(sims.index)

        # plot median simulated leaf temperature
        axs[0, iax].plot(sims['Tleaf'],
                         '-k',
                         label='$\mathregular{T_{leaf}}$',
                         linewidth=1)

        # plot simulated temperature magnitude
        med_sim = np.array([])
        q1_sim = np.array([])
        q3_sim = np.array([])
        for date in datet:
            g, _ = mtg_load(
                str(pth) + '/output/', 'mtg%s' % date.strftime('%Y%m%d%H%M%S'))
            leaf_temp_sim = g.property('Tlc').values()
            q1_sim = np.append(q1_sim, min(leaf_temp_sim))
            q3_sim = np.append(q3_sim, max(leaf_temp_sim))
            med_sim = np.append(med_sim, np.median(leaf_temp_sim))
            print(date)
        axs[0, iax].fill_between(datet,
                                 q1_sim,
                                 q3_sim,
                                 color='red',
                                 alpha=0.5,
                                 zorder=0)

        # plot observed temperature magnitude
        med_obs = np.array([])
        q1_obs = np.array([])
        q3_obs = np.array([])
        for row, date in enumerate(datet):
            pos = date.toordinal() + date.hour / 24.
            leaf_temp_obs = obs.loc[
                date, ['Tleaf%d' % d for d in (2, 3, 4, 5, 6, 8, 9, 10)]]
            leaf_temp_obs = leaf_temp_obs[~np.isnan(leaf_temp_obs)]
            axs[0, iax].boxplot(leaf_temp_obs, positions=[pos], widths=0.01)
            q1_obs = np.append(q1_obs, min(leaf_temp_obs))
            q3_obs = np.append(q3_obs, max(leaf_temp_obs))
            med_obs = np.append(med_obs, np.median(leaf_temp_obs))
            print(date)

        # compare obs to sim temperature on 1:1 plot
        axs[1, iax].plot((10, 50), (10, 50), 'k--')
        axs[1, iax].errorbar(x=med_obs,
                             y=med_sim,
                             xerr=(np.nan_to_num(med_obs - q1_obs),
                                   np.nan_to_num(q3_obs - med_obs)),
                             yerr=(np.nan_to_num(med_sim - q1_sim),
                                   np.nan_to_num(q3_sim - med_sim)),
                             fmt='ro',
                             ecolor='0.5',
                             capthick=1)

        # plot MBE and RMSE results on it
        diff_obs_sim = (med_sim - med_obs)[~np.isnan(med_sim - med_obs)]
        bias = diff_obs_sim.mean()
        rmse = np.sqrt(diff_obs_sim**2).mean()

        axs[1, iax].text(0.50,
                         0.20,
                         '$\mathregular{MBE\/=\/%.3f}$' % bias,
                         transform=axs[1, iax].transAxes,
                         fontdict={'size': 11})
        axs[1, iax].text(0.50,
                         0.10,
                         '$\mathregular{RMSE\/=\/%.1f}$' % rmse,
                         transform=axs[1, iax].transAxes,
                         fontdict={'size': 11})

    # some layout

    axs[0, 0].set_ylabel('$\mathregular{Temperature\/[^{\circ}C]}$')
    axs[1, 0].set_ylabel('$\mathregular{T_{leaf, sim}\/[^{\circ}C]}$')

    for ax_upper, ax_lower in zip(axs[0, :], axs[1, :]):
        ax_upper.set(xlim=(beg_date, end_date), ylim=(5, 50), xlabel='')
        ax_upper.set_xticklabels(datet, rotation=45)
        ax_upper.xaxis.set_major_locator(dates.DayLocator())
        ax_upper.xaxis.set_major_formatter(dates.DateFormatter('%-d %b'))
        ax_lower.set(xlim=(10, 50),
                     ylim=(10, 50),
                     xlabel='$\mathregular{T_{leaf, obs}\/[^{\circ}C]}$')

    for iax, ax in enumerate(axs.flatten()):
        ax.text(0.05,
                0.875, ('(a)', '(c)', '(b)', '(d)')[iax],
                transform=ax.transAxes,
                fontdict={'size': 11})

    fig.tight_layout()
    fig.savefig('fig_11.png', dpi=600.)
    pyplot.close(fig)
Esempio n. 4
0
def plot_figure_10():
    """Generates figure 10 of the paper. This figure compares, simulated to observed stomatal conductance rates.
    """

    beg_date = datetime(
        2012,
        8,
        1,
        00,
        00,
        0,
    )
    end_date = datetime(
        2012,
        8,
        3,
        00,
        00,
        0,
    )
    datet = pd.date_range(beg_date, end_date, freq='D')

    fig, axs = pyplot.subplots(nrows=3,
                               ncols=3,
                               sharex='all',
                               sharey='all',
                               figsize=(6.69, 6))

    for it, training in enumerate(
        ('gdc_can1_grapevine', 'gdc_can2_grapevine', 'gdc_can3_grapevine')):

        pth = example_pth / training

        for i_day, date in enumerate(datet):
            ax = axs[it, i_day]
            obs_date = date + pd.Timedelta(hours=13)
            g, _ = mtg_load(
                str(pth) + '/output/',
                'mtg%s' % obs_date.strftime('%Y%m%d%H%M%S'))
            ax = display.property_map(g,
                                      'gs',
                                      ax=ax,
                                      prop2='Eabs',
                                      color='grey',
                                      colormap='autumn',
                                      add_color_bar=False)

            obs_df = pd.read_csv(pth / 'var.obs', sep=';', index_col='date')
            obs_df.index = pd.DatetimeIndex(obs_df.index)
            gs_leaf = obs_df.loc[date, 'gs'] / 1000.
            ax.add_patch(
                patches.Rectangle((max(gs_leaf), 50),
                                  min(gs_leaf) - max(gs_leaf),
                                  250,
                                  color='0.8',
                                  zorder=-1))
            if i_day == 0:
                ax.text(0.05,
                        0.075,
                        'Canopy%d' % (it + 1),
                        transform=ax.transAxes,
                        fontdict={'size': 11})

            if it == 0:
                ax.text(0.675,
                        0.825,
                        obs_date.strftime('%-d %b'),
                        transform=ax.transAxes,
                        fontdict={'size': 11})

    [axi.set_xticklabels(axi.get_xticks(), rotation=90) for axi in axs[2]]

    for ax, axi in enumerate(axs):
        if ax < 2:
            [axi[i_day].set_xlabel('') for i_day in range(3)]
        [axi[i_day].set_ylabel('') for i_day in (1, 2)]
        [axi[i_day].legend_.remove() for i_day in range(3)]

    fig.tight_layout()

    fig.subplots_adjust(bottom=0.3)
    cbar_ax = fig.add_axes([0.395, 0.1, 0.30, 0.04])
    norm = colors.Normalize(0, vmax=2000)
    cbar = colorbar.ColorbarBase(cbar_ax,
                                 cmap='autumn',
                                 orientation='horizontal',
                                 norm=norm)
    cbar.ax.set_xticklabels(cbar.ax.get_xticklabels(), rotation=90)
    cbar.set_label('$\mathregular{PPFD\/[\mu mol\/m^{-2}_{leaf}\/s^{-1}]}$',
                   labelpad=-20,
                   x=-0.4)

    fig.savefig('fig_10.png', dpi=600.)
    pyplot.close(fig)