示例#1
0
def configure():
    tf.set_random_seed(0)

    # load config
    with open(sys.argv[1]) as config_f:
        config = Struct(**yaml.load(config_f))

    # set up experiment
    config.experiment_dir = os.path.join("experiments/%s" % config.name)
    assert not os.path.exists(config.experiment_dir), \
            "Experiment %s already exists!" % config.experiment_dir
    os.mkdir(config.experiment_dir)

    # set up logging
    log_name = os.path.join(config.experiment_dir, "run.log")
    logging.basicConfig(
        filename=log_name,
        level=logging.DEBUG,
        #logging.basicConfig(stream=sys.stdout, level=logging.DEBUG,
        format='%(asctime)s %(levelname)-8s %(message)s')

    def handler(type, value, tb):
        logging.exception("Uncaught exception: %s", str(value))
        logging.exception("\n".join(traceback.format_exception(
            type, value, tb)))

    sys.excepthook = handler

    logging.info("BEGIN")
    logging.info(str(config))

    return config
示例#2
0
def setup_test():
    global options, directive
    global processed_docstrings, processed_signatures, _warnings

    options = Struct(
        inherited_members=False,
        undoc_members=False,
        private_members=False,
        special_members=False,
        imported_members=False,
        show_inheritance=False,
        noindex=False,
        annotation=None,
        synopsis='',
        platform='',
        deprecated=False,
        members=[],
        member_order='alphabetic',
        exclude_members=set(),
    )

    directive = Struct(
        env=app.builder.env,
        genopt=options,
        result=ViewList(),
        warn=warnfunc,
        filename_set=set(),
    )

    processed_docstrings = []
    processed_signatures = []
    _warnings = []
示例#3
0
    def collide(self, other, kill=False, checkAlive=True):
        """Performs collision detection and calls response methods.

           @param other: The object to check against this one.
           @param kill: If True, calls the kill() method of both objects
               if they collide.
           @param checkAlive: If True, this object is only considered
               to be colliding if the other object is alive.
           @return: The result of calling this object's response methods.
        """
        if self.overlap(other, checkAlive):
            # direction(s) of collision
            _l, _r, _t, _b = False, False, False, False

            # figure out which sides of the sprite are colliding
##            _lrect = Game.Rect(self.rect.left, self.rect.top, 1, self.rect.height-1)
##            _rrect = Game.Rect(self.rect.right-2, self.rect.top, 1, self.rect.height-1)
##            _trect = Game.Rect(self.rect.left, self.rect.top, self.rect.width-1, 1)
##            _brect = Game.Rect(self.rect.left, self.rect.bottom-2, self.rect.width-1, 1)
##
##            _l = _lrect.colliderect(other)
##            _r = _rrect.colliderect(other)
##            _t = _trect.colliderect(other)
##            _b = _brect.colliderect(other)

            # figure out which sides of this object are colliding,
            # based on velocity/position data
            selfvx,selfvy = self.velocity if hasattr(self, 'velocity') else 0,0
            othervx,othervy = other.velocity if hasattr(other, 'velocity') else 0,0
            orect = other.rect if not isinstance(other,Game.Rect) else other

            if selfvx > othervx or (self.x < other.x and self.rect.right > orect.left):
                # this object is approaching from the left
                # so its right edge will be colliding
                _r = True
                
            if selfvx < othervx or (self.x > other.x and self.rect.left < orect.right):
                # this object is approaching from the right
                # so its left edge will be colliding
                _l = True

            if selfvy > othervy or (self.y < other.y and self.rect.bottom > orect.top):
                # this object is approaching from the top
                # so its bottom will be colliding
                _b = True

            if selfvy < othervy or (self.y > other.y and self.rect.top < orect.bottom):
                # this object is approaching from the bottom
                # so its top will be colliding
                _t = True
            

            if kill:
                self.kill()
                other.kill()

            # call this sprite's specific collision response method
            return self.onCollision(other, Struct(left=_l, right=_r, top=_t, bottom=_b))
示例#4
0
 def test_simple_chain(self):
     '''Check that a chain with printout filters works.'''
     chain = FilterChain(
         [IncrementFilter(1),
          IncrementFilter(2),
          IncrementFilter(3)])
     request = Struct(x=0)
     self.assertFalse(chain.handle(request))
     assert_equal(request.x, 6, 'Bad chain processing')
def info(srcs, keys=['N','sz']):
    """
    info = src.info(srcs)  collect source info

    INPUTS
      srcs - list - framesource pipe / plugin chain
      keys - list - keys to collect; default is ['N','sz']

    OUTPUT
      info - struct -requested info
    """
    info = Struct()
    for sc in srcs:
        for key in keys:
            if hasattr(sc, key):
                info.__dict__[key] = getattr(sc,key);

    if 'sz' in keys and len(info.sz) == 2:
       info.sz.append(1) 

    return info
示例#6
0
def fmin_style(sfmin):
    """convert sfmin to style"""
    return Struct(
        is_valid=good(sfmin.is_valid, True),
        has_valid_parameters=good(sfmin.has_valid_parameters, True),
        has_accurate_covar=good(sfmin.has_accurate_covar, True),
        has_posdef_covar=good(sfmin.has_posdef_covar, True),
        has_made_posdef_covar=good(sfmin.has_made_posdef_covar, False),
        hesse_failed=good(sfmin.hesse_failed, False),
        has_covariance=good(sfmin.has_covariance, True),
        is_above_max_edm=good(sfmin.is_above_max_edm, False),
        has_reached_call_limit=caution(sfmin.has_reached_call_limit, False),
    )
示例#7
0
def minos_style(smerr):
    """Convert minos error to style"""
    return Struct(
        is_valid=good(smerr.is_valid, True),
        lower_valid=good(smerr.lower_valid, True),
        upper_valid=good(smerr.upper_valid, True),
        at_lower_limit=good(smerr.at_lower_limit, False),
        at_upper_limit=good(smerr.at_upper_limit, False),
        at_lower_max_fcn=good(smerr.at_lower_max_fcn, False),
        at_upper_max_fcn=good(smerr.at_upper_max_fcn, False),
        lower_new_min=good(smerr.lower_new_min, False),
        upper_new_min=good(smerr.upper_new_min, False),
    )
示例#8
0
    def __init__(self, config, opt_config):
        self.config = config
        self.opt_config = opt_config

        self.models = []
        for cmodel in config.models:
            with open(cmodel.config) as config_f:
                mconfig = Struct(**yaml.load(config_f))
                model = models.build_model(mconfig.model, mconfig.opt)
            model.load(cmodel.weights)
            self.models.append(model)

        self.n_models = len(self.models)

        self.apollo_net = ApolloNet()
示例#9
0
文件: world.py 项目: antonio-cg/pyrge
    def getOutOfBounds(self, border=10):
        """Gets a Struct containing Rects that are just outside the camera boundaries."""
        bounds = self.getBounds()
        oobleft = Game.Rect(bounds.left-border, bounds.top-border,\
                              border,bounds.height+border*2)
        oobright = Game.Rect(bounds.right, bounds.top-border,\
                              border,bounds.height+border*2)
        oobtop = Game.Rect(bounds.left-border, bounds.top-border,\
                              bounds.width+border*2, border)
        oobbottom = Game.Rect(bounds.left-border, bounds.bottom,\
                              bounds.width+border*2, border)
        l = [r.move(-Game.scroll.x, -Game.scroll.y) for r in \
             oobleft, oobright, oobtop, oobbottom]

        return Struct(left=l[0], right=l[1], top=l[2], bottom=l[3])
    def setUp(self):
        '''Load test data and expected results.'''
        unittest.TestCase.setUp(self)

        # Load test data ready from previous phasing stagees
        self.problem = io.read_npz(itu.FAMILY13_STAGE2)
        self.family = self.problem.families()[0]
        self.phaser = phase_core.PhaseDecorator(
            FilterChain([
                trivial_phaser(),
                family_phaser(),
                family_child_comparison_phaser()
            ]))
        self.comparator = ic.ChildComparator(
            Struct(problem=self.problem, params=PhaseParam()), self.family)
示例#11
0
    def at(self, xpos, ypos=None):
        """Gets the tile at a given coordinate.

           @return: A L{Struct} with two attributes:
                - tile : A copy of the tile at a specific location on the map,
                    or None if the given position is outside the boundaries of the map.
                - index : The tile's index on the tilemap's spritesheet, or -1
                    for a blank tile.
        """
        if ypos is None:
            ypos, xpos = divmod(xpos, self.columns)

        if xpos < 0 or ypos < 0 or xpos >= self.columns or ypos >= self.rows:
            _tileid = None
        else:
            _tileid = self.themap[int(ypos)][int(xpos)]

        _tile = self.tiles.get((xpos,ypos),None)
        return Struct(index=_tileid, tile=_tile)
示例#12
0
  def tweak_grd(th0,dth0,ls='r',dashes=None,lw=4.,zorder=5,label=''):
    st = time.clock()
    x_ = np.asarray([0.,z0_,th0,dx_,0.,dth0])
    x__,trjs = step(x_,p=p)
    print '%0.2f sec; dx0 = %0.2f, dx1 = %0.2f' % (time.clock() - st,x_[3],x__[3])

    T,X,O,P = rx.stack(trjs)
    vars = O[0].keys()

    t = np.hstack(T)
    # observations until max compression
    o = Struct(**dict([( v, np.vstack([oo[v] for oo,pp in zip(O,P) if (pp.j is not None) and (pp.j[0] < 0)]) ) for v in vars]))

    z,th = o.q[:,[2,4]].T
    if dashes is None:
      axs['grd'].plot(th,z,ls,lw=lw,zorder=zorder,label=label)
    else:
      axs['grd'].plot(th,z,ls,lw=lw,zorder=zorder,label=label,dashes=dashes)
    axs['grd'].arrow(th[-20],z[-20],np.diff(th[-20:])[0],np.diff(z[-20:])[0],
                     lw=lw,fc='k',head_width=.04,zorder=10)
示例#13
0
文件: relax.py 项目: sburden/sim
def EulerPlanar(t, x, p, hds, h, n, debug=False, Zeno=False):
  """
  trjs = Euler(t, x, p, hds, h, n, debug, Zeno)

  *** UNFINISHED ***

  Compute Euler approximation to hybrid execution assuming 
  guards are coordinate functions
  (thus transition time can be determined exactly)

  Inputs:
  t   - 1 x 2 - time range
  x   - 1 x n - initial state
  p   - Struct - model paramters
  hds - hybrid model
  h   - scalar - Euler integration stepsize
  n   - int - maximum number of hybrid transitions
  debug - flag for printing debugging info
  Zeno - flag for quitting executions with short modes

  Outputs:
  trjs - list of trajectory dicts
  trj - trajectory dict
    .t - times
    .x - states
    .p - parameters
    .hds - hybrid model

  by Sam Burden, Humberto Gonzalez, Ram Vasudevan, Berkeley 2011
  """
  tf = t[1] # store final time

  h0 = h # store given stepsize 

  p.debug = debug # enable model debugging

  t = np.array([t[0]])
  x = x.copy()
  if len(x.shape) == 1:
    x.shape = (1,x.size)

  trj = Struct(t=t,x=x,p=p,hds=hds)
  trjs = []

  # Euler loop
  while trj.t[-1] <= tf and not (trj.p.j == None) and len(trjs) < n:

    # initial data
    t0 = trj.t[-1]
    x0 = trj.x[-1,:]
    p0 = trj.p
    g0 = trj.hds.G(t, x,  p0)
    # vector field
    dx = trj.hds.F(t0, x0, p0)
    # Euler step
    j = trj.p.j
    t = t0 + h
    x = trj.hds.E(t0, x0, p0, h*dx)
    g = trj.hds.G(t,  x,  p0)
    # if guard is triggered
    if g < 0:
      # move state exactly to transition
      s = g0 / trjs.hds.G(t, h*dx, p0)


    # halve step size until trajectory doesn't jump over strip
    k = 0
    kmax = 50
    while (g < -rx) and (k <= kmax):
      if debug:
        print 'RX:  jump over strip #%d' % k
      h  = h/2
      t  = t0 + h
      dx = h*dxdt + np.sqrt(h)*np.random.randn()*dxdw
      x  = trj.hds.E(t, x0, p0, dx)
      g  = trj.hds.G(t, x,p0)
      k += 1

    if (k >= kmax):
      raise RuntimeError,'(euler)  strip iterations exceeded'

    # append state to trj
    trj.t = np.append(trj.t, [t], axis=1)
    trj.x = np.append(trj.x, [x], axis=0)

    if debug:
      print '  :  j = %d  t = %0.3f  x = %s' % (j,t,str(x))

    # if state is on strip
    if (g < 0):

      # spend time on the strip 
      t = t + (rx + g)
      trj.t = np.append(trj.t, [t], axis=1)
      # can't move state without analytical strip
      trj.x = np.append(trj.x, [x], axis=0)

      if debug:
        print 'RX:  j = %d  t = %0.3f  x = %s' % (j,t,str(x))

      # append trj to trjs
      trjs += [trj]
      trj = trj.copy()

      if Zeno and (len(trj.t) <= 4):

        print '(euler)  possible Zeno @ stepsize h = %0.6f' % h0
        print 'RX:  j = %d  t = %0.3f  x = %s' % (j,t,str(x))
        return trjs

      # apply reset to modify trj
      t,x,p = hds.R(t,x,p0)
      if len(x.shape) == 1:
        x.shape = (1,x.size)

      t = np.array([t])
      trj.t = t
      trj.x = x
      trj.p = p

      # re-initialize step size
      h = h0

      if debug:
        print 'RX:  j = %d  t = %0.3f  x = %s' % (j,t,str(x[0,:]))

  trjs += [trj]
  trj = trj.copy()

  return trjs
parameters_syn = {
    'remove_response_flag': False,
    'filter_flag': True,
    'pre_filt': [0.0067, 0.01, 0.02, 0.025],
    'starttime': 0,
    'endtime': 6000,
    'resample_flag': True,
    'sampling_rate': 5,
    'taper_type': "hann",
    'taper_percentage': 0.05,
    'rotate_flag': True,
    'sanity_check': False,
}

paths_obs = Struct({
    'input': '../data/C200912240023A.observed.h5',
    'output': '../data/C200912240023A.processed_observed.h5',
})

paths_syn = Struct({
    'input': '../data/C200912240023A.synthetic.h5',
    'output': '../data/C200912240023A.processed_synthetic.h5',
})


def process_traces(parameters, paths, tag1, tag2):
    """
    Performs bandpass filtering and other data processing operations on 
    ASDF data; writes processed waveforms in a new ASDF file or under a new 
    ASDF tag

    :param parameters: dictionary passed directly to pytomo3d
示例#15
0
文件: relax.py 项目: sburden/sim
def Euler(t, x, p, hds, h, rx, n, debug=False, Zeno=False):
  """
  trjs = Euler(t, x, p, hds, h, rx, n, debug, Zeno)

  Compute Euler approximation to relaxed hybrid execution

  Inputs:
  t   - 1 x 2 - time range
  x   - 1 x n - initial state
  p   - Struct - model paramters
  hds - hybrid model
  h   - scalar - Euler integration stepsize
  rx  - scalar - relaxation parameter
  n   - int - maximum number of hybrid transitions
  debug - flag for printing debugging info
  Zeno - flag for quitting executions with short modes

  Outputs:
  trjs - list of trajectory dicts
  trj - trajectory dict
    .t - times
    .x - states
    .p - parameters
    .hds - hybrid model

  by Sam Burden, Humberto Gonzalez, Ram Vasudevan, Berkeley 2011
  """
  tf = t[1] # store final time

  h0 = h # store given stepsize 

  p.debug = debug # enable model debugging

  t = np.array([t[0]])
  x = x.copy()
  if len(x.shape) == 1:
    x.shape = (1,x.size)

  trj = Struct(t=t,x=x,p=p,hds=hds)
  trjs = []

  # Euler loop
  while trj.t[-1] <= tf and not (trj.p.j == None) and len(trjs) < n:

    # do single Euler step
    t0 = trj.t[-1]
    x0 = trj.x[-1,:]
    p0 = trj.p
    dxdt = trj.hds.F(t0, x0, p0)
    dx = h*dxdt

    j = trj.p.j
    t = t0 + h
    x = trj.hds.E(t0, x0, p0, dx)
    g = trj.hds.G(t,  x,  p0)

    # halve step size until trajectory doesn't jump over strip
    k = 0
    kmax = 50
    while np.any(g < -rx) and (k <= kmax):
      #if debug:
      #  print 'RX:  jump over strip #%d' % k
      h  = h/2.
      t  = t0 + h
      dx = h*dxdt
      x  = trj.hds.E(t0, x0, p0, dx)
      g  = trj.hds.G(t,  x,p0)
      k += 1

    if (k >= kmax):
      raise RuntimeError,'(euler)  strip iterations exceeded'

    # append state to trj
    trj.t = np.append(trj.t, [t], axis=1)
    trj.x = np.append(trj.x, [x], axis=0)

    if debug:
      print '  :  j = %s, h = %0.2e, t = %0.3f, g = %s, x = %s' % (j,h,t,g,str(x))

    # if state is on strip
    if np.any(g < 0):

      # spend time on the strip 
      t = t + (rx + g.min())
      trj.t = np.append(trj.t, [t], axis=1)
      # can't move state without analytical strip
      trj.x = np.append(trj.x, [x], axis=0)

      if debug:
        print 'RX:  j = %s, t = %0.3f, g = %s, x = %s' % (j,t,g,str(x))

      # append trj to trjs
      trjs += [trj]
      trj = trj.copy()

      if Zeno and (len(trj.t) <= 4):

        print '(euler)  possible Zeno @ stepsize h = %0.6f' % h0
        print 'RX:  j = %s  t = %0.3f\nx = %s' % (j,t,str(x))
        return trjs

      # apply reset to modify trj
      t,x,p = hds.R(t,x,p0)
      if len(x.shape) == 1:
        x.shape = (1,x.size)

      t = np.array([t])
      trj.t = t
      trj.x = x
      trj.p = p

      # re-initialize step size
      h = h0

      if debug:
        j = p.j
        g = trj.hds.G(t[0],  x[0],  p)
        print 'RX:  j = %s, t = %0.3f, g = %s, x = %s' % (j,t,g,str(x[0,:]))

  trjs += [trj]
  trj = trj.copy()

  return trjs
示例#16
0
文件: relax.py 项目: sburden/sim
def EulerBisect(t, x, p, hds, h, rx, n, debug=False, Zeno=False):
  """
  trjs = EulerBisect(t, x, p, hds, h, rx, n, debug, Zeno)

  Compute Euler approximation to relaxed hybrid execution

  Inputs:
  t   - 1 x 2 - time range
  x   - 1 x n - initial state
  p   - Struct - model paramters
  hds - hybrid model
  h   - scalar - Euler integration stepsize
  rx  - scalar - relaxation parameter
  n   - int - maximum number of hybrid transitions
  debug - flag for printing debugging info
  Zeno - flag for quitting executions with short modes

  Outputs:
  trjs - list of trajectory dicts
  trj - trajectory dict
    .t - times
    .x - states
    .p - parameters
    .hds - hybrid model

  by Sam Burden, Humberto Gonzalez, Ram Vasudevan, Berkeley 2011
  """
  tf = t[1] # store final time

  h0 = h # store given stepsize 

  p.debug = debug # enable model debugging

  t = np.array([t[0]])
  x = x.copy()
  if len(x.shape) == 1:
    x.shape = (1,x.size)

  trj = Struct(t=t,x=x,p=p,hds=hds)
  trjs = []

  # Euler loop
  while trj.t[-1] <= tf and not (trj.p.j == None) and len(trjs) < n:

    # initial data
    t0 = trj.t[-1]
    x0 = trj.x[-1,:]
    p0 = trj.p
    dx = trj.hds.F(t0, x0, p0)
    # Euler step
    j = trj.p.j
    t = t0 + h
    x = trj.hds.E(t0, x0, p0, h*dx)
    g = trj.hds.G(t,  x,  p0)

    # if transition occurs
    if ( g < -rx ):
      # find step size that lands trajectory on strip using bisection
      h = bisect( lambda s : trj.hds.G(t0+s,trj.hds.E(t0,x0,p0,s*dx),p0),
                  (0.,h), tol=rx )
      # debug
      if np.isnan(h):
        raise RuntimeError,'(euler)  cannot step to strip'
      # Euler step
      t = t0 + h
      x = trj.hds.E(t0, x0, p0, h*dx)
      g = trj.hds.G(t,  x,  p0)

    # append state to trj
    trj.t = np.append(trj.t, [t], axis=1)
    trj.x = np.append(trj.x, [x], axis=0)

    if debug:
      print '  :  j = %d  g = %0.2e  h = %0.2e  t = %0.3f  x = %s' % (j,g,h,t,str(x))

    # if state is on strip
    if (g < 0):

      # spend time on the strip 
      t = t + (rx + g)
      trj.t = np.append(trj.t, [t], axis=1)
      # can't move state without analytical strip
      trj.x = np.append(trj.x, [x], axis=0)

      if debug:
        print 'RX:  j = %d  g = %0.2e  h = %0.2e  t = %0.3f  x = %s' % (j,g,h,t,str(x))

      # append trj to trjs
      trjs += [trj]
      trj = trj.copy()

      if Zeno and (len(trj.t) <= 4):

        print '(euler)  possible Zeno @ stepsize h = %0.6f' % h0
        print 'RX:  j = %d  g = %0.2e  h = %0.2e  t = %0.3f  x = %s' % (j,g,h,t,str(x))
        return trjs

      # apply reset to modify trj
      t,x,p = hds.R(t,x,p0)
      if len(x.shape) == 1:
        x.shape = (1,x.size)

      t = np.array([t])
      trj.t = t
      trj.x = x
      trj.p = p

      # re-initialize step size
      h = h0

      if debug:
        print 'RX:  j = %d  g = %0.2e  h = %0.2e  t = %0.3f  x = %s' % (j,g,h,t,str(x[0,:]))

  trjs += [trj]
  trj = trj.copy()

  return trjs
示例#17
0
import sys
args = sys.argv

assert len(args) > 1, 'specify .cfg file'

sig = 0.
if len(args) > 2:
    sig = 2e-1
    seed = int(args[2])
    np.random.seed(int(seed))
    print 'seed = %d' % seed

op = opt.Opt()
op.pars(fi=args[1], Poly=poly.Poly)
p = Struct(**op.p)


def step(x0_, p=p):
    x_, z_, th_, dx_, dz_, dth_ = x0_

    t0 = p.t0
    x0 = p.poly.unsaggital([x_, z_, th_, dx_, dz_, dth_])
    p0 = p.p0.copy()
    trjs = rx.Euler((t0, np.infty), x0, p0, p.poly, p.h, p.eps, p.n, p.debug)

    x1 = trjs[-1].x[-1]
    x, y, z, thx, thy, thz, dx, dy, dz, dthx, dthy, dthz = x1
    assert np.allclose([y, thx, thz, dy, dthx, dthz],
                       np.zeros(6)), "saggital dynamics"
示例#18
0
def seq(x_,
        p=p,
        fn='',
        xlim=None,
        props=dict(position=position,
                   offv=550,
                   text=text,
                   pad_inches=0.,
                   light=0.,
                   time=False,
                   fn='',
                   plots=['sch'],
                   exts=exts,
                   alpha=0,
                   offz=0,
                   clf=True,
                   ylim=(-0.1, 1.45),
                   fill=fill)):
    x__, trjs = step(x_, p=p)

    props = props.copy()

    T, X, O, P = rx.stack(trjs)
    vars = O[0].keys()
    o = Struct(**dict([(v, np.vstack([oo[v] for oo in O])) for v in vars]))

    if len(trjs) == 7:
        trjs.pop(5)
        trjs.pop(1)

    n = len(trjs) / 2
    offx = -trjs[n].p.foot[:, 0].mean()

    # enclose whole trajectory in figure
    #props.update(xlim=.7*trjs[0].p.lamb[0]*np.asarray([-1.,+1.])+[trjs[0].x[0,0],trjs[-1].x[0,0]])
    if xlim is None:
        xlim = (.7 * trjs[0].p.lamb[0] * np.asarray([-1., +1.]) +
                [trjs[0].x[0, 0], trjs[-1].x[0, 0]] + offx)
    props.update(xlim=xlim, offx=offx)
    figs, axs = p.poly.sch(trjs[n].t[0], trjs[n].x[0], trjs[n].p, **props)
    props.update(figs=figs,
                 axs=axs,
                 clf=False,
                 alpha=1,
                 offz=0,
                 lw=6,
                 time=True)

    for k, trj in enumerate(trjs):
        #props.update(alpha=float(k+1)/len(trjs))
        if k + 1 == len(trjs):
            props.update(fn=di + fn)
        props.update(offz=10 * k,
                     light=.9 * (1. - float(k + 1) / len(trjs)),
                     offt=+1 - 2 * (k == n))
        p.poly.sch(trj.t[0] - trjs[n].t[0], trj.x[0], trj.p, **props)
        #axs['sch'].plot(trj.x[:,0]+offx,trj.x[:,2],color=[.6,.6,.6],lw=6,zorder=1)

    axs['sch'].plot(o.q[:, 0] + offx,
                    o.q[:, 2],
                    color=.3 * np.ones(3),
                    lw=4,
                    zorder=10 * (k + 1))
    axs['sch'].arrow(o.q[-1, 0] + offx,
                     o.q[-1, 2],
                     0.10,
                     0.,
                     head_width=0.06,
                     lw=4,
                     color=.3 * np.ones(3),
                     zorder=10 * (k + 1))
    plt.draw()
    return trjs, figs, axs, props
示例#19
0
    def __init__(self,
                 uri='',
                 bindAddress='localhost:5001',
                 downloadPath='.',
                 idleTimeout=-1,
                 keepComplete=False,
                 keepIncomplete=False,
                 keepFiles=False,
                 showAllStats=False,
                 showOverallProgress=False,
                 showFilesProgress=False,
                 showPiecesProgress=False,
                 debugAlerts=False,
                 exitOnFinish=False,
                 resumeFile='',
                 stateFile='',
                 userAgent=USER_AGENT,
                 dhtRouters='',
                 trackers='',
                 listenPort=6881,
                 torrentConnectBoost=50,
                 connectionSpeed=50,
                 peerConnectTimeout=15,
                 requestTimeout=20,
                 maxDownloadRate=-1,
                 maxUploadRate=-1,
                 connectionsLimit=200,
                 encryption=1,
                 minReconnectTime=60,
                 maxFailCount=3,
                 noSparseFile=False,
                 randomPort=False,
                 enableScrape=False,
                 enableDHT=True,
                 enableLSD=True,
                 enableUPNP=True,
                 enableNATPMP=True,
                 enableUTP=True,
                 enableTCP=True):
        self.torrentHandle = None
        self.forceShutdown = False
        self.session = None
        self.magnet = False

        self.config = Struct()
        self.config.uri = uri
        self.config.bindAddress = bindAddress
        self.config.downloadPath = downloadPath
        self.config.idleTimeout = idleTimeout
        self.config.keepComplete = keepComplete
        self.config.keepIncomplete = keepIncomplete
        self.config.keepFiles = keepFiles
        self.config.showAllStats = showAllStats
        self.config.showOverallProgress = showOverallProgress
        self.config.showFilesProgress = showFilesProgress
        self.config.showPiecesProgress = showPiecesProgress
        self.config.debugAlerts = debugAlerts
        self.config.exitOnFinish = exitOnFinish
        self.config.resumeFile = resumeFile
        self.config.stateFile = stateFile
        self.config.userAgent = userAgent
        self.config.dhtRouters = dhtRouters
        self.config.trackers = trackers
        self.config.listenPort = listenPort
        self.config.torrentConnectBoost = torrentConnectBoost
        self.config.connectionSpeed = connectionSpeed
        self.config.peerConnectTimeout = peerConnectTimeout
        self.config.requestTimeout = requestTimeout
        self.config.maxDownloadRate = maxDownloadRate
        self.config.maxUploadRate = maxUploadRate
        self.config.connectionsLimit = connectionsLimit
        self.config.encryption = encryption
        self.config.minReconnectTime = minReconnectTime
        self.config.maxFailCount = maxFailCount
        self.config.noSparseFile = noSparseFile
        self.config.randomPort = randomPort
        self.config.enableScrape = enableScrape
        self.config.enableDHT = enableDHT
        self.config.enableLSD = enableLSD
        self.config.enableUPNP = enableUPNP
        self.config.enableNATPMP = enableNATPMP
        self.config.enableUTP = enableUTP
        self.config.enableTCP = enableTCP
        if self.config.uri == '':
            raise Exception("uri is empty string")
        if self.config.uri.startswith('magnet:'):
            self.magnet = True
        if self.config.resumeFile is None: self.config.resumeFile = ''
        if self.config.resumeFile != '' and not self.config.keepFiles:
            raise Exception(
                'Не должно быть файла восстановления, если мы не храним файлы')
示例#20
0
class Globals(object):
    """Useful game-specific values.

    This class holds a number of useful values, such as the time taken
    in the current frame, the currently-pressed keys, and a pointer to the game world.
    It also imports many of the most important pygame objects, so you can create,
    for example, a Rect object by using Game.Rect instead of pygame.Rect, meaning that
    you don't need to use "import pygame" in your own game.

    @cvar Rect: The pygame Rect object.
    @cvar Surface: The pygame Surface object.
    @cvar Draw: The pygame draw module.
    @cvar Sprite: The pygame sprite module.
    @cvar PixelArray: The pygame PixelArray object.
    @cvar Font: The pygame font module.
    @cvar Mask: The pygame mask module.
    @cvar Image: The pygame image module.
    @cvar Transform: The pygame transform module.
    @cvar Constants: The pygame locals module, holding named constants
        representing key codes, event types, display flags, etc.
    @cvar events: A Struct whose attributes point to the pygame events
        of the same name. (Example: event_types.KEYUP == pygame.KEYUP)
    """
    @staticmethod
    def color(name):
        """Create a Pygame Color object from a color name.

           @param name: The name of a color. The valid color names can be found in
           pygame.color.THECOLORS.
        """
        return pygame.Color(name)

    @staticmethod
    def rgb(r, g, b, a=255):
        """Create a Pygame Color object from RGB or RGBA values.

           @param r: The red value of the desired color.
           @param g: The green value of the color.
           @param b: The blue value of the color.
           @param a: The alpha value (transparency) of the color. Default is 255,
               or fully opaque.
        """
        return pygame.Color(r, g, b, a)

    @staticmethod
    def randomcolor():
        """Get a random named color."""
        from random import choice
        from pygame import color
        return choice(color.THECOLORS.values())

    @staticmethod
    def timer(evttype, milliseconds=0):
        """Set an event timer.

           This method will post recurring events of the given type after a
           specified amount of time. This is a repeating timer, so events will
           be posted until the timer is disabled (by calling this method with
           C{milliseconds} set to 0) or the program ends.

           @param evttype: The type of event to post. Event types are listed in
           the L{events} structure.
           @param milliseconds: The time between each event, or 0 to disable
           this timer.
        """
        pygame.time.set_timer(evttype, milliseconds)

    # A rectangle object (NOTE: pygame Rects only support integer coordinates)
    Rect = pygame.Rect

    # A surface/image object
    Surface = pygame.Surface

    # Drawing functions
    # TODO: options for regular draw vs. gfxdraw
    Draw = pygame.draw

    # The pygame sprite library
    Sprite = pygame.sprite

    # An array interface to the individual pixels of a surface
    # TODO: maybe detect if NumPy is installed and use SurfArray instead?
    PixelArray = pygame.PixelArray

    # The font module (access to font objects, system fonts, etc.)
    Font = pygame.font

    # A 2D bitmask that can be used for pixel-level collision detection
    Mask = pygame.mask

    # Functions for loading/saving images
    Image = pygame.image

    # Functions for transforming (scaling, rotating, etc.) surfaces
    Transform = pygame.transform

    # Constants is just a synonym for "pygame.locals", which keeps all of the
    # various constants like keycodes, event types, and surface flags
    Constants = pygame.locals

    # helpful structs

    # Event types
    # Right now, we simply copy pygame's events into a Struct.
    # Later, we might use the USEREVENTs to do something.
    events = Struct(QUIT=pygame.QUIT,
                    ACTIVEEVENT=pygame.ACTIVEEVENT,
                    KEYDOWN=pygame.KEYDOWN,
                    KEYUP=pygame.KEYUP,
                    MOUSEMOTION=pygame.MOUSEMOTION,
                    MOUSEBUTTONUP=pygame.MOUSEBUTTONUP,
                    MOUSEBUTTONDOWN=pygame.MOUSEBUTTONDOWN,
                    JOYAXISMOTION=pygame.JOYAXISMOTION,
                    JOYBALLMOTION=pygame.JOYBALLMOTION,
                    JOYHATMOTION=pygame.JOYHATMOTION,
                    JOYBUTTONUP=pygame.JOYBUTTONUP,
                    JOYBUTTONDOWN=pygame.JOYBUTTONDOWN,
                    VIDEORESIZE=pygame.VIDEORESIZE,
                    VIDEOEXPOSE=pygame.VIDEOEXPOSE,
                    USEREVENT=pygame.USEREVENT)
示例#21
0
    "c_3a": 1.0,
    "c_3b": 2.0,
    "c_4a": 3.0,
    "c_4b": 10.0,
    "resolution_strategy": "interval_scheduling",
}

parameters_by_channel = {
    'BHR': flexwin_parameters,
    'BHT': flexwin_parameters,
    'BHZ': flexwin_parameters,
}

paths = Struct({
    'obs': '../data/C200912240023A.processed_observed.h5',
    'syn': '../data/C200912240023A.processed_synthetic.h5',
    'output': '../data/C200912240023A.windows.json',
    'log': '../data/C200912240023A.windows.log',
})

merge_flag = False


def select_windows(parameters, paths, merge_flag, obs_tag, syn_tag):
    """
    Selects windows by comparing observed and synthetic traces;
    writes results to a json file

    :param parameters: dictionary passed directly to pyflex.Config
    :param paths.obs: ASDF observed data filename
    :param paths.syn: ASDF synthetic data filename
    :param paths.output: windows will be written to a JSON file with this name
import shutil

import pytomo3d.adjoint
import pyasdf
import pyadjoint

from os.path import join
from util import dirname, read_json, Struct, zip_catch
from util import add_adjoint_source_waveforms, add_adjoint_source_auxiliary_data

paths = Struct({
    'input': [
        '../data/C200912240023A.adjoint_sources.h5',
    ],
    #'../data/C200912240023A.processed_adjoint_40_100.h5',
    #'../data/C200912240023A.processed_adjoint_90_250.h5']
    'weights': [
        '../data/C200912240023A.weights.json',
    ],
    #'../data/C200912240023A.weights_sw.h5',
    'output': '../data/C200912240023A.adjoint_sources_sum.h5',
})


def combine_adjoint_sources(paths, tag, rotate=True, auxiliary_data=False):
    """ 
    Sums adjoint sources from different ASDF files in a linear combination with
    user-supplied weights. Can be useful, for example, if previous data 
    processing, window selection, and misfit measurements steps were carried out
    separately for different pass bands (e.g. long period, short period) or 
    different phases (e.g. body waves, surface waves).
    'interp_delta': 0.1425,
    'interp_npts': 42000,
    'sum_over_comp_flag': False,
    'weight_flag': False,
    'filter_flag': True,
    'pre_filt': [0.0067, 0.01, 0.02, 0.025],
    'taper_type': "hann",
    'taper_percentage': 0.05,
    'add_missing_comp_flag': False,
    'rotate_flag': False,
}

paths = Struct({
    'obs': '../data/C200912240023A.processed_observed.h5',
    'syn': '../data/C200912240023A.processed_synthetic.h5',
    'windows': '../data/C200912240023A.windows.json',
    'misfit': '../data/C200912240023A.misfit.json',
    'adjoint_sources': '../data/C200912240023A.adjoint_sources.h5',
})


def write_adjoint_traces(misfit_type, misfit_parameters, filter_parameters,
                         paths, obs_tag, syn_tag):
    """
    Makes misfit measurements using observed and synthetic data;
    writes out misfit values and corresponding "adjoint sources"

    :param misfit_type: type of data misfit function, 
         e.g. waveform_difference, multitaper_misfit
    :param misfit_parameters: dictionary passed directly to pyadjoint.Config
    :param paths.obs: ASDF observed data filename