Beispiel #1
0
from eos import Go
import fit
magic = Go(
    x_i=0.4,             # Initial position of projectile / cm'
    x_f=4.0,             # Final/muzzle position of projectile /cm'
    m=100.0,             # Mass of projectile / g
    area=1e-4,           # Projectile cross section in m^2
    newton2dyne=1e5,     # dynes per newton
    var=1.0e-0,          # Variance attributed to v measurements
    n_t=500,             # Number of ts for t2v spline
    t_min=-5.0e-6,       # Range of times for t2v spline
    t_max=110.0e-6,      # Range of times for t2v spline
    cm2km=1.0e5,         # For conversion from cm/sec to km/sec
    n_t_sim=1000,        # len(vt), simulated velocity time pairs
           )
magic.add(D_frac=fit.magic.D_frac) # Fractional finite difference for dv/df
class Gun:
    '''Represents an imagined experiment and actual simulations.

    Section 2 of the document ../juq.tex describes the imagined
    experiment.

    Units: cgs

    Methods:

    f(x)          Force in dynes on projectile
    
    E(x)          Energy

    x_dot(x)      Velocity
Beispiel #2
0
from eos import Go
import fit
magic = Go(
    x_i=0.4,  # Initial position of projectile / cm'
    x_f=4.0,  # Final/muzzle position of projectile /cm'
    m=100.0,  # Mass of projectile / g
    area=1e-4,  # Projectile cross section in m^2
    newton2dyne=1e5,  # dynes per newton
    var=1.0e-0,  # Variance attributed to v measurements
    n_t=500,  # Number of ts for t2v spline
    t_min=-5.0e-6,  # Range of times for t2v spline
    t_max=110.0e-6,  # Range of times for t2v spline
    cm2km=1.0e5,  # For conversion from cm/sec to km/sec
    n_t_sim=1000,  # len(vt), simulated velocity time pairs
)
magic.add(D_frac=fit.magic.D_frac)  # Fractional finite difference for dv/df


class Gun:
    '''Represents an imagined experiment and actual simulations.

    Section 2 of the document ../juq.tex describes the imagined
    experiment.

    Units: cgs

    Methods:

    f(x)          Force in dynes on projectile
    
    E(x)          Energy
Beispiel #3
0
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