def plotcost_ens_inc(vect=1): """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('whitegrid') power=np.arange(1,10,1) xlist = [10**(-x) for x in power] jj = fdj.FourDEnVar(assim=True) #jj.output_dir="output/ens_run500" tstlist = [abs(test_cost_ens_inc(jj, x, vect)-1) for x in xlist] ax.loglog(xlist, tstlist, 'k', marker='x', mew=1, ms=8) #font = {'size' : 24} #matplotlib.rc('font', **font) plt.xlabel(r'$\eta$') plt.ylabel(r'$|f(\eta) - 1|$') #plt.title('test of the gradient of the cost function') print tstlist #plt.show() return ax, fig
def save_plots(xa_ens_pickle, out_dir): """ Function saving plots from data assimilatoin experiment output :param xa_ens_pickle: location of pickled posterior ensemble arr (str) :param out_dir: directory to save plots in (str) :return: string confirming plots have been saved (str) """ dat_xt = nc.Dataset('output/background/xb0.daily.nc', 'r') jda = fourdenvar.FourDEnVar() obs = es.obs_fn() date = nc.num2date(dat_xt.variables['time'][:], dat_xt.variables['time'].units) xb_dir = es.output_directory + '/ensemble' + str(es.seed_value) xa_dir = es.output_directory + '/ensemble_xa_' + str(es.seed_value) #plot SM fig, ax = plot_twin_spread(date[:], 'smcl', xb_dir, xa_dir, ob_times=obs['sm_times'], obs=obs['sm_obs'], err=obs['sm_err'], ylab=r'Soil Moisture (m$^{3}$ m$^{-3}$)') fig.savefig(out_dir + '/sm.png', bbox_inches='tight') xb_dir2 = es.output_directory + '/background_tst' xa_dir2 = es.output_directory + '/analysis_med' fig, ax = calc_cosmos_stats(date[:], xb_dir2, xa_dir2) fig.savefig(out_dir + '/cosmos_median.png', bbox_inches='tight') #plot distribution #true_params = {'alpha_io': 5.5e-02, 'neff_io': 5.7e-04, 'fd_io': 9.6e-03, 'mu_io': 2.0e-02, 'nu_io': 4.0e+00, # 'gamma_io': 1.76e+01, 'delta_io':-3.3e-01} xa_ens = pickle.load(open(xa_ens_pickle, 'rb')) p_keys = [ 'oneovernminusone', 'oneoveralpha', 'satcon', 'vsat', 'vcrit', 'vwilt', 'hcap', 'hcon' ] fig, ax = plot_mult_dist(xa_ens, jda.xbs, p_keys) fig.savefig(out_dir + '/distributions.png', bbox_inches='tight') return 'plots saved!'
:return: string confirming if the ensemble has been run (str) """ print 'Running ensemble' mp.freeze_support() with poolcontext(processes=es.num_processes) as pool: res = pool.map( partial(ens_member_run, seed_val=seed_val, params=params, xa=xa), enumerate(x_ens)) pool.close() pool.join() return 'Ensemble has been run' if __name__ == "__main__": # instantiate JULES data assimilation class jda = fourdenvar.FourDEnVar(seed_val=int(sys.argv[1])) seed_val = int(sys.argv[1]) params = jda.p_keys # if 'run_xb' is in system arguments then run JULES with prior parameters if 'run_xb' in sys.argv: nml_dir = 'output_seed' + str(seed_val) + '_xb/' if not os.path.exists(nml_dir): os.makedirs(nml_dir) for file in glob.glob(es.nml_directory + '/*.nml'): sh.copy(file, nml_dir) rj = rjda.RunJulesDa(params=params, values=jda.xb, nml_dir=nml_dir) rj.run_jules_dic(output_name='xb' + str(jda.seed_val), out_dir=es.output_directory + '/background/') sh.rmtree(nml_dir) # remove any old output in folders old_outs = glob.glob(es.output_directory + '/ensemble' + str(seed_val) +
def save_plots(xa_ens_pickle, out_dir): """ Function saving plots from data assimilatoin experiment output :param xa_ens_pickle: location of pickled posterior ensemble arr (str) :param out_dir: directory to save plots in (str) :return: string confirming plots have been saved (str) """ dat_xt = nc.Dataset('output/model_truth/mod_truth.daily.nc', 'r') jda = fourdenvar.FourDEnVar() obs = es.obs_fn() date = nc.num2date(dat_xt.variables['time'][:], dat_xt.variables['time'].units) xb_dir = es.output_directory + '/ensemble' + str(es.seed_value) xa_dir = es.output_directory + '/ensemble_xa_' + str(es.seed_value) #plot GPP fig, ax = plot_twin_spread( date[:], 'gpp', xb_dir, xa_dir, xt_var=1000 * 60 * 60 * 24 * dat_xt.variables['gpp'][:, 7, 0, 0], ob_pos=obs['gpp_pos'], obs=obs['gpp_obs'], err=obs['gpp_err'], ylab=r'Gross Primary Productivity (g C m$^{-2}$ day$^{-1}$)') fig.savefig(out_dir + '/gpp.png', bbox_inches='tight') #plot LAI fig, ax = plot_twin_spread(date[:], 'lai', xb_dir, xa_dir, xt_var=dat_xt.variables['lai'][:, 7, 0, 0], ob_pos=obs['lai_pos'], obs=obs['lai_obs'], err=obs['lai_err'], ylab=r'Leaf Area Index (m$^{2}$ m$^{-2}$)') fig.savefig(out_dir + '/lai.png', bbox_inches='tight') #plot Canht fig, ax = plot_twin_spread(date[:], 'canht', xb_dir, xa_dir, xt_var=dat_xt.variables['canht'][:, 7, 0, 0], ob_pos=obs['canht_pos'], obs=obs['canht_obs'], err=obs['canht_err'], ylab=r'Canopy Height (m)') fig.savefig(out_dir + '/canht.png', bbox_inches='tight') #plot harvestable material fig, ax = plot_twin_spread(date[:], 'cropharvc', xb_dir, xa_dir, xt_var=dat_xt.variables['cropharvc'][:, 2, 0, 0], ylab=r'Harvestable Material (kg C m$^{-2}$)', lvl_idx=2) fig.savefig(out_dir + '/harvc.png', bbox_inches='tight') #plot distribution true_params = { 'alpha_io': 5.5e-02, 'neff_io': 5.7e-04, 'fd_io': 9.6e-03, 'mu_io': 2.0e-02, 'nu_io': 4.0e+00, 'gamma_io': 1.76e+01, 'delta_io': -3.3e-01 } xa_ens = pickle.load(open(xa_ens_pickle, 'rb')) fig, ax = plot_mult_dist(xa_ens, jda.xbs, jda.p_keys, true_params) fig.savefig(out_dir + '/distributions.png', bbox_inches='tight') return 'plots saved!'