Esempio n. 1
0
def day_night_twin_run_no_obs_error(start, end, obs, f_name, its=1000):
    d = dc.DalecDataTwin(start, end, obs, err_scale=0.0)
    m = mc.DalecModel(d)
    assim_results, xa = m.find_min_tnc_cvt(d.xb,
                                           f_name + '_assim_res',
                                           maxits=its)
    d2 = dc.DalecDataTwin(start, 2013, obs)
    # Plot 4dvar time series
    ax, fig = p.plot_4dvar_twin('nee', d2, xa=xa)
    fig.savefig(f_name + '_nee.pdf', bbox_inches='tight')
    ax, fig = p.plot_4dvar_twin('nee_day', d2, xa=xa)
    fig.savefig(f_name + '_need.pdf', bbox_inches='tight')
    ax, fig = p.plot_4dvar_twin('nee_night', d2, xa=xa)
    fig.savefig(f_name + '_neen.pdf', bbox_inches='tight')
    ax, fig = p.plot_4dvar_twin('lai', d2, xa=xa)
    fig.savefig(f_name + '_lai.pdf', bbox_inches='tight')

    # Plot scatter plots of obs
    ax, fig = p.plot_scatter_twin('nee', xa, d2, len(d.I), 'f')
    fig.savefig(f_name + '_nee_scat.pdf', bbox_inches='tight')
    ax, fig = p.plot_scatter_twin('nee_day', xa, d2, len(d.I), 'f')
    fig.savefig(f_name + '_need_scat.pdf', bbox_inches='tight')
    ax, fig = p.plot_scatter_twin('nee_night', xa, d2, len(d.I), 'f')
    fig.savefig(f_name + '_neen_scat.pdf', bbox_inches='tight')
    ax, fig = p.plot_scatter_twin('lai', xa, d2, len(d.I), 'f')
    fig.savefig(f_name + '_lai_scat.pdf', bbox_inches='tight')

    # Plot error in analysis and background
    ax, fig = p.plottwinerr(d.x_truth, d.xb, xa)
    fig.savefig(f_name + '_twin_err.pdf', bbox_inches='tight')
    return 'all experimented'
Esempio n. 2
0
def day_night_twin_run(start, end, obs, f_name, obs_loc):
    d = dc.DalecDataTwin(start,
                         end,
                         obs,
                         nc_file='../../alice_holt_data/ah_data_daily_test.nc')
    pik_obs = pickle.load(open(obs_loc, 'r'))
    d.ob_dict = pik_obs
    m = mc.DalecModel(d)
    assim_results, xa = m.find_min_tnc_cvt(d.xb, f_name + '_assim_res')
    d2 = dc.DalecDataTwin(start, 2013, obs)
    # Plot 4dvar time series
    ax, fig = p.plot_4dvar_twin('nee', d2, xa=xa)
    fig.savefig(f_name + '_nee.pdf', bbox_inches='tight')
    ax, fig = p.plot_4dvar_twin('nee_day', d2, xa=xa)
    fig.savefig(f_name + '_need.pdf', bbox_inches='tight')
    ax, fig = p.plot_4dvar_twin('nee_night', d2, xa=xa)
    fig.savefig(f_name + '_neen.pdf', bbox_inches='tight')
    ax, fig = p.plot_4dvar_twin('lai', d2, xa=xa)
    fig.savefig(f_name + '_lai.pdf', bbox_inches='tight')

    # Plot scatter plots of obs
    ax, fig = p.plot_scatter_twin('nee', xa, d2, len(d.I), 'f')
    fig.savefig(f_name + '_nee_scat.pdf', bbox_inches='tight')
    ax, fig = p.plot_scatter_twin('nee_day', xa, d2, len(d.I), 'f')
    fig.savefig(f_name + '_need_scat.pdf', bbox_inches='tight')
    ax, fig = p.plot_scatter_twin('nee_night', xa, d2, len(d.I), 'f')
    fig.savefig(f_name + '_neen_scat.pdf', bbox_inches='tight')
    ax, fig = p.plot_scatter_twin('lai', xa, d2, len(d.I), 'f')
    fig.savefig(f_name + '_lai_scat.pdf', bbox_inches='tight')

    # Plot error in analysis and background
    ax, fig = p.plottwinerr(d.x_truth, d.xb, xa)
    fig.savefig(f_name + '_twin_err.pdf', bbox_inches='tight')
    return 'all experimented'
Esempio n. 3
0
def plotcostone_ens(vect=1, sizee=20):
    """Using test_cost plots convergance of cost fn gradient for decreasing
    value of alpha.
    """
    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')
    power = np.arange(1, 14, 1)
    xlist = [10**(-x) for x in power]
    d = dC.DalecDataTwin(
        1999,
        2010,
        'nee',
        nc_file='../../alice_holt_data/ah_data_daily_test_nee3.nc',
        scale_nee=0)
    m = mc.DalecModel(d, size_ens=sizee)
    tstlist = [test_cost_ens(m, x, vect) for x in xlist]
    ax.semilogx(xlist, tstlist, 'k', marker='x', mew=1, ms=8)
    #ax.semilogx(xlist, tstlist, 'k', 'x')
    plt.xlabel(r'$\alpha$')
    plt.ylabel(r'$f(\alpha)$')
    #plt.title('test of the gradient of the cost function')
    print tstlist
    return ax, fig
Esempio n. 4
0
def test_cost_cvt(alph=1e-8, vect=0):
    """Test for cost and gradcost functions.
    """
    d = dC.DalecDataTwin(
        1999,
        2000,
        'nee',
        nc_file='../../alice_holt_data/ah_data_daily_test_nee3.nc',
        scale_nee=1)
    m = mc.DalecModel(d, size_ens=1)
    pvals = d.edinburgh_mean
    zvals = m.pvals2zvals(pvals)
    gradj = m.gradcost_cvt(zvals)
    print gradj.shape
    if vect == 0:
        h = zvals * (np.linalg.norm(zvals))**(-1)
    elif vect == 1:
        h = gradj * (np.linalg.norm(gradj))**(-1)
    elif vect == 2:
        h = np.ones(23) * (np.sqrt(23)**-1)
    j = m.cost_cvt(zvals)
    jalph = m.cost_cvt(zvals + alph * h)
    print jalph - j
    print np.dot(alph * h, gradj)
    print(jalph - j) / (np.dot(alph * h, gradj))
    return abs(jalph - j) / (np.dot(alph * h, gradj))
Esempio n. 5
0
def twin_exps(exp, f_name):
    if not os.path.exists(f_name):
        os.makedirs(f_name)
    if exp == 'a':
        obs = 'nee_day_east, nee_night_east'
        lab = '/twin_a'
        ob_dic = pickle.load(open('twin_obs_a025'))
    elif exp == 'b':
        obs = 'nee_day_east, nee_night_east, lai_east, clma'
        ob_dic = pickle.load(open('twin_obs_b025'))
        lab = '/twin_b'
    elif exp == 'c':
        obs = 'nee_day_east, nee_night_east, lai_east, clma, c_woo_east'
        ob_dic = pickle.load(open('twin_obs_c025'))
        lab = '/twin_c'
    d = dc.DalecDataTwin(
        2015,
        2016,
        obs,
        nc_file='../../alice_holt_data/ah_data_daily_test_nee2.nc',
        scale_nee=1,
        err_scale=0.25)
    d.ob_dict = ob_dic
    m = mc.DalecModel(d)
    m.rmatrix = r_mat_corr(m.yerroblist,
                           m.ytimestep,
                           m.y_strlst,
                           m.rmatrix,
                           corr=0.3,
                           tau=2.)[1]
    # run DA scheme
    xa = m.find_min_tnc_cvt(d.xb, f_name + lab)
    ax, fig = p.plottwinerr(d.x_truth, d.xb, xa[1])
    fig.savefig(f_name + lab + 'twin_err.pdf')
    ax, fig = p.plot_twinerr_red(d.x_truth, d.xb, xa[1])
    fig.savefig(f_name + lab + 'twin_err_red.pdf')
    ax, fig = p.plot_twin_err(d.x_truth, d.xb, xa[1])
    fig.savefig(f_name + lab + 'twin_err2.pdf', bbox_inches='tight')
    return xa