def make_opt(precondition=False): import gun import stick import eos nominal_eos = eos.Spline_eos(eos.Nominal(), precondition=precondition) experiment = { 'gun': gun.Gun(nominal_eos), 'stick': stick.Stick(nominal_eos), } data = {'gun': gun.data(), 'stick': stick.data()} return Opt(nominal_eos, experiment, data)
def make_opt(precondition=False): import gun import stick import eos nominal_eos = eos.Spline_eos(eos.Nominal(), precondition=precondition) experiment = { 'gun':gun.Gun(nominal_eos), 'stick':stick.Stick(nominal_eos), } data = { 'gun':gun.data(), 'stick':stick.data() } return Opt(nominal_eos, experiment, data)
def tx_stick(exp, nom, plt): import stick from fit import Opt fig = plt.figure('tx_stick', figsize=fig_y_size(5.0)) opt = Opt( nom.eos, {'stick':nom.stick}, {'stick':exp.stick_data}) cs,costs = opt.fit(max_iter=10) print('stick costs={0}'.format(costs)) opt_t = stick.data(opt.eos) x = nom.stick.x / 10 #cm ax = fig.add_subplot(1,1,1) ax.plot(x, nom.stick_data*1e6, label='nom') ax.plot(x, exp.stick_data*1e6, 'r+', label='exp') ax.plot(x, opt_t*1e6, label='fit') ax.set_xlabel(r'$x/{\rm cm}$') ax.set_ylabel(r'$t/\mu{\rm sec}$') ax.legend(loc='lower right') fig.subplots_adjust(bottom=0.15) # Make more space for label return fig
def main(argv=None): import argparse import os import os.path if argv is None: # Usual case argv = sys.argv[1:] parser = argparse.ArgumentParser(description='Make plots for notes.pdf') parser.add_argument('--show', action='store_true') parser.add_argument('--fig_dir', type=str, default='figs', help= 'Directory of figures') # Plot requests h_format = lambda s:'File for figure of {0}'.format(s) parser.add_argument('--tx_stick', type=str, help=h_format('t(x)')) parser.add_argument('--C_gun', type=str, help=h_format('d c_v/ d c_p')) parser.add_argument('--vt_gun', type=str, help=h_format('v(t)')) parser.add_argument('--BC_gun', type=str, help=h_format('d v(t)/ d c_p')) parser.add_argument('--opt_result', type=str, help=h_format( 'one optimization step')) parser.add_argument('--big_d', type=str, help=h_format( 'finite difference derivative with 9 subplots')) parser.add_argument('--fve_gun', type=str, help=h_format( 'force, velocity and sequence of errors')) args = parser.parse_args(argv) params = {'axes.labelsize': 18, # Plotting parameters for latex 'font.size': 15, 'legend.fontsize': 15, 'text.usetex': True, 'font.family':'serif', 'font.serif':'Computer Modern Roman', 'xtick.labelsize': 15, 'ytick.labelsize': 15} mpl.rcParams.update(params) if args.show: mpl.rcParams['text.usetex'] = False else: mpl.use('PDF') import matplotlib.pyplot as plt # must be after mpl.use if not os.path.exists(args.fig_dir): os.mkdir(args.fig_dir) # Do quick calculations to create exp and nom import eos import gun import stick t=np.linspace(0, gun.magic.t_max, gun.magic.n_t_sim) exp = Go(eos=eos.Experiment()) nom = Go(eos=eos.Spline_eos(eos.Nominal(), precondition=True)) for go in (exp, nom): go.add(t=t, gun=gun.Gun(go.eos), stick=stick.Stick(go.eos)) go.add(x=np.linspace(go.gun.x_i, go.gun.x_f, 500)) go.add(t2v=go.gun.fit_t2v()) go.add(v=go.t2v(t)) go.add(vt=(go.v, go.t)) go.add(stick_data=stick.data(go.eos)) C=nom.gun.fit_C() B,ep = nom.gun.fit_B_ep(exp.vt) nom.add(C=C, B=B, ep=ep, BC=np.dot(B,C)) # Make requested plots do_show = args.show for key in args.__dict__: if key not in plot_dict: continue if args.__dict__[key] == None: continue print('work on %s'%(key,)) fig = plot_dict[key](exp, nom, plt) file_name = getattr(args, key) if file_name == 'show': do_show = True else: fig.savefig(os.path.join(args.fig_dir, file_name), format='pdf') if do_show: plt.show() return 0