Exemple #1
0
  def from_json(data):
    """Given a JSON-encoded message, build an object.

    """
    d = json.loads(data)
    sbp = SBP.from_json_dict(d)
    return MsgSettingsReadByIndex(sbp)
Exemple #2
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgEphemerisOld(sbp)
Exemple #3
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgNapDeviceDna(sbp)
Exemple #4
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgStmFlashUnlockSector(sbp)
Exemple #5
0
    def from_json(s):
        """Given a JSON-encoded string s, build a message object.

    """
        d = json.loads(s)
        sbp = SBP.from_json_dict(d)
        return MsgPrint(sbp)
Exemple #6
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgSettingsReadByIndex(sbp)
Exemple #7
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgFlashProgram(sbp)
Exemple #8
0
def assert_package(test_filename, pkg_name):
    """
  Runs unit tests for message bindings by reading a YAML unit test
  specification, parsing a raw packet for each test, and then
  asserting that SBP messages and parsed payloads have their intended
  values.

  Parameters
  ----------
  test_filename : str
    Filepath to unit test specifications
  pkg_name : str
    Name of package to test

  """
    with open(test_filename, 'r') as f:
        pkg = yaml.load(f.read())
        _assert_sane_package(pkg_name, pkg)
        for test_case in pkg['tests']:
            sbp = SBP.unpack(base64.standard_b64decode(
                test_case['raw_packet']))
            _assert_sbp(sbp, test_case['sbp'])
            _assert_msg(dispatch(sbp), test_case['msg'])
            _assert_msg_roundtrip(dispatch(sbp), test_case['raw_packet'])
            _assert_msg_roundtrip_json(dispatch(sbp), test_case['raw_json'])
            _assert_materialization(test_case['msg'], sbp,
                                    test_case['raw_json'])
Exemple #9
0
  def from_json(data):
    """Given a JSON-encoded message, build an object.

    """
    d = json.loads(data)
    sbp = SBP.from_json_dict(d)
    return MsgBootloaderHandshake(sbp)
Exemple #10
0
def assert_package(test_filename, pkg_name):
  """
  Runs unit tests for message bindings by reading a YAML unit test
  specification, parsing a raw packet for each test, and then
  asserting that SBP messages and parsed payloads have their intended
  values.

  Parameters
  ----------
  test_filename : str
    Filepath to unit test specifications
  pkg_name : str
    Name of package to test

  """
  with open(test_filename, 'r') as f:
    pkg = yaml.load(f.read())
    _assert_sane_package(pkg_name, pkg)
    for test_case in pkg['tests']:
      sbp = SBP.unpack(base64.standard_b64decode(test_case['raw_packet']))
      _assert_sbp(sbp, test_case['sbp'])
      _assert_msg(dispatch(sbp), test_case['msg'])
      _assert_msg_roundtrip(dispatch(sbp), test_case['raw_packet'])
      _assert_msg_roundtrip_json(dispatch(sbp), test_case['raw_json'])
      _assert_materialization(test_case['msg'], sbp, test_case['raw_json'])
Exemple #11
0
  def from_json(data):
    """Given a JSON-encoded message, build an object.

    """
    d = json.loads(data)
    sbp = SBP.from_json_dict(d)
    return MsgM25FlashWriteStatus(sbp)
Exemple #12
0
  def from_json(data):
    """Given a JSON-encoded message, build an object.

    """
    d = json.loads(data)
    sbp = SBP.from_json_dict(d)
    return MsgStmFlashUnlockSector(sbp)
Exemple #13
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgBootloaderHandshake(sbp)
Exemple #14
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgM25FlashWriteStatus(sbp)
Exemple #15
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgBaselineNED(sbp)
Exemple #16
0
  def from_json(data):
    """Given a JSON-encoded message, build an object.

    """
    d = json.loads(data)
    sbp = SBP.from_json_dict(d)
    return MsgIarState(sbp)
Exemple #17
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgFileioReadDir(sbp)
Exemple #18
0
  def from_json(s):
    """Given a JSON-encoded string s, build a message object.

    """
    d = json.loads(s)
    sbp = SBP.from_json_dict(d)
    return MsgTrackingState(sbp)
Exemple #19
0
    def from_json(s):
        """Given a JSON-encoded string s, build a message object.

    """
        d = json.loads(s)
        sbp = SBP.from_json_dict(d)
        return MsgStmFlashUnlockSector(sbp)
Exemple #20
0
def test_available_messages():
  """
  Simple example with a limited dispatch table.

  """
  table = {acq.SBP_MSG_ACQ_RESULT: acq.MsgAcqResult,
           log.SBP_MSG_PRINT: log.MsgPrint}
  msg = SBP(msg_type=0x15, sender=1219, length=13,
            payload='\x92$yA\x00\x00\xbcC\x81\xc1\xf9\xc5\x1d')
  # TODO (Buro): Replace this message constructor once generated SBP
  # can support kwargs for constructor, instead of requiring SBP
  # object.
  assert dispatch(msg, table) == acq.MsgAcqResult(msg)
  msg = SBP(msg_type=0xB0, sender=1219, length=4, payload='v1.2', crc=0xCE01)
  with pytest.raises(InvalidSBPMessageType) as exc_info:
    dispatch(msg, table)
  assert str(exc_info.value).find("No message found for msg_type id 176*")
    def __init__(self,
                 n_classes,
                 n_units=None,
                 mask=None,
                 name='vgg',
                 reuse=None):
        super(VGG, self).__init__()
        n_units = [64, 64, 128, 128, 256, 256, 256,
                512, 512, 512, 512, 512, 512, 512, 512] \
                        if n_units is None else n_units
        self.mask = mask
        self.n_classes = n_classes

        def create_block(l, n_in, n_out):
            self.base.append(
                Conv(n_in, n_out, 3, name='conv' + str(l), padding='SAME'))
            self.base.append(BatchNorm(n_out, name='bn' + str(l)))
            self.bbd.append(
                BBDropout(n_out, name='bbd' + str(l), a_uc_init=2.0))
            self.dbbd.append(DBBDropout(n_out, name='dbbd' + str(l)))
            self.vib.append(VIB(n_out, name='vib' + str(l)))
            self.sbp.append(SBP(n_out, name='sbp' + str(l)))
            self.gend.append(GenDropout(n_out, name='gend' + str(l)))

        with tf.variable_scope(name, reuse=reuse):
            create_block(1, 3, n_units[0])
            for i in range(1, 13):
                create_block(i + 1, n_units[i - 1], n_units[i])

            self.bbd.append(BBDropout(n_units[13], name='bbd14'))
            self.dbbd.append(DBBDropout(n_units[13], name='dbbd14'))
            self.vib.append(VIB(n_units[13], name='vib14'))
            self.sbp.append(SBP(n_units[13], name='sbp14'))
            self.gend.append(GenDropout(n_units[13], name='gend14'))

            self.base.append(Dense(n_units[13], n_units[14], name='dense14'))
            self.base.append(BatchNorm(n_units[14], name='bn14'))

            self.bbd.append(BBDropout(n_units[14], name='bbd15'))
            self.dbbd.append(DBBDropout(n_units[14], name='dbbd15'))
            self.vib.append(VIB(n_units[14], name='vib15'))
            self.sbp.append(SBP(n_units[14], name='sbp15'))
            self.gend.append(GenDropout(n_units[14], name='gen15'))

            self.base.append(Dense(n_units[14], n_classes, name='dense15'))
Exemple #22
0
def test_handler_callbacks():
    handler = Handler(None, None)
    global_counter1 = TestCallbackCounter()
    global_counter2 = TestCallbackCounter()
    msg_type_counter1 = TestCallbackCounter()
    msg_type_counter2 = TestCallbackCounter()
    handler.add_callback(global_counter1)
    handler.add_callback(global_counter2)
    handler.add_callback(global_counter2)
    handler.add_callback(msg_type_counter1, 0x55)
    handler.add_callback(msg_type_counter1, 0x55)
    handler.add_callback(msg_type_counter2, 0x66)
    handler.call(SBP(0x11, None, None, None, None))
    handler.call(SBP(0x55, None, None, None, None))
    assert global_counter1.value == 2
    assert global_counter2.value == 2
    assert msg_type_counter1.value == 1
    assert msg_type_counter2.value == 0
 def create_block(l, n_in, n_out):
     self.base.append(
         Conv(n_in, n_out, 3, name='conv' + str(l), padding='SAME'))
     self.base.append(BatchNorm(n_out, name='bn' + str(l)))
     self.bbd.append(
         BBDropout(n_out, name='bbd' + str(l), a_uc_init=2.0))
     self.dbbd.append(DBBDropout(n_out, name='dbbd' + str(l)))
     self.vib.append(VIB(n_out, name='vib' + str(l)))
     self.sbp.append(SBP(n_out, name='sbp' + str(l)))
     self.gend.append(GenDropout(n_out, name='gend' + str(l)))
Exemple #24
0
def test_listener_thread_ok():
    sema = TestCallbackSemaphore()
    listener_thread = ReceiveThread(lambda: SBP(True, None, None, None, None),
                                    sema)
    listener_thread.start()
    assert listener_thread.is_alive()
    until(lambda: sema.sema.acquire(False))
    listener_thread.stop()
    until(lambda: listener_thread.is_alive())
    until(lambda: sema.sema.acquire(False))
Exemple #25
0
def test_available_messages():
  """
  Simple example with a limited dispatch table.

  """
  table = {acq.SBP_MSG_ACQ_RESULT: acq.MsgAcqResult,
           log.SBP_MSG_PRINT: log.MsgPrint}
  msg = SBP(msg_type=0x15, sender=1219, length=13,
            payload='\x92$yA\x00\x00\xbcC\x81\xc1\xf9\xc5\x1d')
  # TODO (Buro): Replace this message constructor once generated SBP
  # can support kwargs for constructor, instead of requiring SBP
  # object.
  assert dispatch(msg, table) == acq.MsgAcqResult(msg)
  msg = SBP(msg_type=0xB0, sender=1219, length=4, payload='v1.2', crc=0xCE01)
  with warnings.catch_warnings(record=True) as w:
    dispatch(msg, table)
    warnings.simplefilter("always")
    assert len(w) == 1
    assert issubclass(w[0].category, RuntimeWarning)
    assert str(w[0].message).find("No message found for msg_type id 176 for msg*")
Exemple #26
0
def test_listener_thread_ok():
    counter = TestCallbackCounter()
    listener_thread = ReceiveThread(lambda: SBP(True, None, None, None, None),
                                    counter)
    listener_thread.start()
    assert listener_thread.is_alive()
    assert counter.value > 0
    listener_thread.stop()
    while listener_thread.is_alive():
        pass
    value = counter.value
    assert counter.value == value
 def __init__(self, n_units=None, mask=None, thres=1e-3,
         name='lenet_fc', reuse=None):
     super(LeNetFC, self).__init__()
     n_units = [784, 500, 300] if n_units is None else n_units
     self.mask = mask
     with tf.variable_scope(name, reuse=reuse):
         for i in range(3):
             self.base.append(Dense(n_units[i],
                 (10 if i==2 else n_units[i+1]), name='dense'+str(i+1)))
             self.vib.append(VIB(n_units[i], name='vib'+str(i+1)))
             self.bbd.append(BBDropout(n_units[i], name='bbd'+str(i+1)))
             self.dbbd.append(DBBDropout(n_units[i], name='dbbd'+str(i+1)))
             self.sbp.append(SBP(n_units[i], name='sbp'+str(i+1)))
             self.gend.append(GenDropout(n_units[i], name='gend'+str(i+1)))
 def __init__(self, n_units=None, mask=None,
         name='lenet_conv', reuse=None):
     n_units = [20, 50, 800, 500] if n_units is None else n_units
     self.mask = mask
     super(LeNetConv, self).__init__()
     with tf.variable_scope(name, reuse=reuse):
         self.base.append(Conv(1, n_units[0], 5, name='conv1'))
         self.base.append(Conv(n_units[0], n_units[1], 5, name='conv2'))
         self.base.append(Dense(n_units[2], n_units[3], name='dense3'))
         self.base.append(Dense(n_units[3], 10, name='dense4'))
         for i in range(4):
             self.bbd.append(BBDropout(n_units[i], name='bbd'+str(i+1)))
             self.dbbd.append(DBBDropout(n_units[i], name='dbbd'+str(i+1)))
             self.vib.append(VIB(n_units[i], name='vib'+str(i+1)))
             self.sbp.append(SBP(n_units[i], name='sbp'+str(i+1)))
             self.gend.append(GenDropout(n_units[i], name='gend'+str(i+1)))
Exemple #29
0
                pos2 = temp

            [tail, lever, alpha, Etof,
             dist] = GetLeverAlpha(pos1, pos2, tof, E1)
            coneMat[indexOverall, 0:3] = pos1
            coneMat[indexOverall, 3:6] = pos2
            coneMat[indexOverall, 6] = alpha
            flightPaths[indexOverall, :3] = tail
            flightPaths[indexOverall, 3:6] = lever
            flightPaths[indexOverall, 6] = alpha

            energies[indexOverall, :] = [E1, Etof, tof, dist]

        tempfile = 'results\\glassConesTemp.p'
        np.savetxt(tempfile, coneMat[eventsWritten:eventsWritten + j])
        SBP(tempfile)
        pair = str(b1) + '-' + str(b2)
        plt.title(pair + ', ' + str(numPairDoubles) + ' cones')
        plt.savefig('results\\' + pair + 'image.png')

        eventsWritten += numPairDoubles

# Write to imaging outfile
write = True
if write:
    print('Writing to file...')
    f = open(outfile, 'w')
    np.savetxt(f, coneMat)
f.close()

print('Projecting...')