示例#1
0
def plot_obs_east_west(ob, xa_east, xa_west, d_e, d_w):
    """Plots a specified observation using obs eqn in obs module. Takes an
    observation string, a dataClass (dC) and a start and finish point.
    """
    sns.set_context(rc={'lines.linewidth': .8, 'lines.markersize': 6})
    fig, ax = plt.subplots(nrows=1, ncols=1)
    me = mc.DalecModel(d_e)
    mw = mc.DalecModel(d_w)
    mod_lst_e = me.mod_list(xa_east)
    obs_lst_e = me.oblist(ob, mod_lst_e)
    mod_lst_w = mw.mod_list(xa_west)
    obs_lst_w = mw.oblist(ob, mod_lst_w)

    palette = sns.color_palette("colorblind", 11)

    ax.plot(d_e.dates, obs_lst_e, color=palette[0], label='East')
    ax.plot(d_w.dates, obs_lst_w, color=palette[2], label='West')
    if ob in d_e.ob_dict.keys():
        ax.plot(d_e.dates,
                d_e.ob_dict[ob],
                'o',
                color=palette[0],
                markeredgecolor='black',
                markeredgewidth=0.5)
        ax.plot(d_w.dates,
                d_w.ob_dict[ob],
                'o',
                color=palette[2],
                markeredgecolor='black',
                markeredgewidth=0.5)
    plt.legend()
    ax.set_xlabel('Date')
    ax.set_ylabel(ob)
    plt.gcf().autofmt_xdate()
    return ax, fig
示例#2
0
def plot_scatter_twin(ob, pvals, dC, awindl, bfa='a'):
    """Plots scatter plot of obs vs model predicted values. Takes an initial
    parameter set, a dataClass (must have only desired ob for comparison
    specified in dC), assimilation window length and whether a comparison of
    background 'b', forecast 'f' or analysis 'a' is desired.
    """
    sns.set_context('poster',
                    font_scale=1.5,
                    rc={
                        'lines.linewidth': 1.,
                        'lines.markersize': 6.
                    })
    fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(10, 10))
    sns.set_style('ticks')
    palette = sns.color_palette("colorblind", 11)
    m = mc.DalecModel(dC)
    mod_lst = m.mod_list(pvals)
    mod_lst_truth = m.mod_list(dC.x_truth)
    obs_lst = m.oblist(ob, mod_lst)
    y_obs = m.oblist(ob, mod_lst_truth)
    plt_ob_lst = (y_obs / y_obs) * obs_lst
    if bfa == 'b' or bfa == 'a':
        selection = xrange(0, awindl)
    elif bfa == 'f':
        selection = xrange(awindl, len(obs_lst))
    else:
        raise Exception('Please check function input for bfa variable')
    ob_lst = plt_ob_lst[selection][np.isnan(y_obs[selection]) != True]
    y_obs = y_obs[selection][np.isnan(y_obs[selection]) != True]

    one_one = np.arange(int(min(min(y_obs), min(ob_lst))),
                        int(max(max(y_obs), max(ob_lst))))
    plt.plot(one_one, one_one, color=palette[0])
    print int(min(min(y_obs), min(ob_lst))), int(max(max(y_obs), max(ob_lst)))

    ax.plot(y_obs, ob_lst, 'o', color=palette[1])
    error = np.sqrt(np.sum((y_obs - ob_lst)**2) / len(y_obs))
    yhx = np.mean(y_obs - ob_lst)
    mod_obs_bar = np.mean(ob_lst)
    std_mod_obs = np.nanstd(ob_lst)
    obs_bar = np.mean(y_obs)
    std_obs = np.std(y_obs)
    rms = np.sqrt(
        np.sum([((ob_lst[x] - mod_obs_bar) - (y_obs[x] - obs_bar))**2
                for x in range(len(y_obs))]) / len(y_obs))
    corr_coef = (np.sum([((ob_lst[x]-mod_obs_bar)*(y_obs[x]-obs_bar)) for x in range(len(y_obs))]) / len(y_obs)) / \
                (std_mod_obs*std_obs)

    plt.xlabel(ob.upper() + r' observations (g C m$^{-2}$ day$^{-1}$)')
    plt.ylabel(ob.upper() + ' model (g C m$^{-2}$ day$^{-1}$)')
    plt.title('mean(y-hx)=%.2f, rms=%.2f, corr_coef=%.2f' %
              (yhx, rms, corr_coef))
    print bfa + '_error=%f, mean(y-hx)=%f, rms=%f, corr_coef=%f' % (
        error, yhx, rms, corr_coef)
    #plt.xlim((-20, 15))
    #plt.ylim((-20, 15))
    return ax, fig
示例#3
0
def plot_4dvar_twin(ob,
                    dC,
                    xb=None,
                    xa=None,
                    erbars=1,
                    awindl=None,
                    obdict_a=None):
    """Plots a model predicted observation value for two initial states (xb,xa)
    and also the actual observations taken of the physical quantity. Takes a ob
    string, two initial states (xb,xa), a dataClass and a start and finish
    time step.
    """
    sns.set_context(rc={'lines.linewidth': .8, 'lines.markersize': 6})
    fig, ax = plt.subplots(nrows=1, ncols=1)
    palette = sns.color_palette("colorblind", 11)
    m = mc.DalecModel(dC)
    mod_lst = m.mod_list(dC.x_truth)
    obs_lst = m.oblist(ob, mod_lst)
    ax.plot(dC.dates, obs_lst, color=palette[3])
    if xb != None:
        mod_lst = m.mod_list(xb)
        obs_lst = m.oblist(ob, mod_lst)
        ax.plot(dC.dates, obs_lst, ':', color=palette[0])
    if xa != None:
        mod_lst = m.mod_list(xa)
        obs_lst = m.oblist(ob, mod_lst)
        ax.plot(dC.dates, obs_lst, color=palette[1])

    mod_lst = m.mod_list(dC.x_truth)
    obs_lst = m.oblist(ob, mod_lst)
    ax.plot(dC.dates, obs_lst, '--', color=palette[3])

    # ob_dict = obdict_a
    # ob_err_dict = dC.ob_err_dict
    # if ob in ob_dict.keys():
    #    if erbars == True:
    #        ax.errorbar(dC.dates, ob_dict[ob], yerr=ob_err_dict[ob],
    #                     fmt='o', label=ob+'_o', color=palette[2], alpha=0.7)
    #    else:
    #        ax.plot(dC.dates, ob_dict[ob], 'o', label=ob+'_o', color=palette[2])
    if obdict_a != None:
        ax.plot(dC.dates[0:len(obdict_a[ob])],
                obdict_a[ob],
                'o',
                color=palette[2])

    if awindl != None:
        ax.axvline(x=dC.dates[awindl], color='k', ls='dashed')

    ax.set_xlabel('Year')
    ax.set_ylabel(ob)
    plt.gcf().autofmt_xdate()

    return ax, fig
示例#4
0
def plot_gpp_sensitivity_ceff():
    sns.set_context(rc={'lines.linewidth': .8, 'lines.markersize': 6})
    fig, ax = plt.subplots(nrows=1, ncols=1)
    palette = sns.color_palette("colorblind", 11)
    d = dc.DalecDataTwin(1999, 2000, '')
    m = mc.DalecModel(d)
    m.x = 200
    gpp = []
    ceff_list = np.arange(10., 100.)
    for ceff in ceff_list:
        gpp.append(m.acm(180., 60., ceff, d.acm))

    ax.plot(ceff_list, gpp, color=palette[0])
    ax.set_xlabel('Canopy efficiency parameter')
    ax.set_ylabel('GPP (g C m-2 day-1)')
    return ax, fig
示例#5
0
def plot_gpp_sensitivity_lai():
    sns.set_context(rc={'lines.linewidth': .8, 'lines.markersize': 6})
    fig, ax = plt.subplots(nrows=1, ncols=1)
    palette = sns.color_palette("colorblind", 11)
    d = dc.DalecDataTwin(1999, 2000, '')
    m = mc.DalecModel(d)
    m.x = 200
    gpp = []
    cf_list = np.arange(60., 600.)
    for cf in cf_list:
        gpp.append(m.acm(cf, 60., d.edinburgh_mean[10], d.acm))

    ax.plot(cf_list / 60., gpp, color=palette[0])
    ax.set_xlabel('LAI')
    ax.set_ylabel('GPP (g C m-2 day-1)')
    return ax, fig
示例#6
0
def plot_obs(ob, pvals, dC):
    """Plots a specified observation using obs eqn in obs module. Takes an
    observation string, a dataClass (dC) and a start and finish point.
    """
    sns.set_context(rc={'lines.linewidth': 0.8, 'lines.markersize': 6})
    fig, ax = plt.subplots(nrows=1, ncols=1)
    m = mc.DalecModel(dC)
    mod_lst = m.mod_list(pvals)
    obs_lst = m.oblist(ob, mod_lst)

    palette = sns.color_palette("colorblind", 11)

    ax.plot(dC.dates, obs_lst, color=palette[0])
    ax.set_xlabel('Year')
    ax.set_ylabel(ob)
    plt.gcf().autofmt_xdate()
    return ax, fig
示例#7
0
def plot_phi(pvals, dC):
    """Plots phi_onset and phi_fall fns controlling leaf on and leaf off. Takes
    a parameter set (pvals) and a dataClass (dC).
    """
    sns.set_context(rc={'lines.linewidth': .8, 'lines.markersize': 6})
    fig, ax = plt.subplots(nrows=1, ncols=1)
    m = mc.DalecModel(dC)
    mod_lst = m.mod_list(pvals)
    phi_on = m.oblist('phi_onset', mod_lst)
    phi_off = m.oblist('phi_fall', mod_lst)

    palette = sns.color_palette("colorblind", 11)

    ax.plot(dC.dates, phi_on, color=palette[0], label='phi_onset')
    ax.plot(dC.dates, phi_off, color=palette[2], label='phi_fall')
    plt.legend()
    ax.set_xlabel('Year')
    ax.set_ylabel('Rate of leaf on/leaf off')
    plt.gcf().autofmt_xdate()
    return ax, fig