Esempio n. 1
0
 def __init__(self):
     self.target = [stick.Stick(random.randint(1,constantes.maxheight)) for _ in range(constantes.sticknum)]
     # self.target = [stick.Stick(
     # i*constantes.heightmulti+constantes.addedheight)
     # for i in range(constantes.sticknum)]
     # random.shuffle(self.target)
     self.progress = 0
Esempio n. 2
0
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)
Esempio n. 3
0
if __name__ == '__main__':
    import doctest
    doctest.testmod()

    import sys
    port = None
    port = sys.argv[1:] and sys.argv[1] or False
    serial_num = sys.argv[2:] and sys.argv[2] or False
    if not port or not serial_num:
        print "usage:\n%s <port> <serial>, eg /dev/ttyUSB0 208850" % sys.argv[0]
        sys.exit(1)
    import link
    import stick
    import session
    from pprint import pformat
    logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
    log.info(
        "howdy! I'm going to take a look at your pump and grab lots of info.")
    stick = stick.Stick(link.Link(port, timeout=.400))
    stick.open()
    session = session.Pump(stick, serial_num)
    log.info(pformat(stick.interface_stats()))
    log.info('PUMP MODEL: %s' % session.read_model())
    do_commands(session)
    log.info(pformat(stick.interface_stats()))
    #get_pages(session)
    #log.info(pformat(stick.interface_stats( )))
    log.info("howdy! we downloaded a lot of pump info successfully.")
    # stick.open( )
Esempio n. 4
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