Beispiel #1
0
 def test_utc_seek(self):
     signal_id = 3
     expected = self._utc_gen(signal_id)
     expected = expected[len(expected) // 2:, :]
     with Reader(self._path) as r:
         r.utc(signal_id, expected[0, 0], self._on_utc)
     np.testing.assert_equal(expected, self.utc)
Beispiel #2
0
    def test_fsr_f32(self):
        data = np.arange(110000, dtype=np.float32)
        with Writer(self._path) as w:
            w.source_def(source_id=1,
                         name='name',
                         vendor='vendor',
                         model='model',
                         version='version',
                         serial_number='serial_number')
            w.signal_def(3,
                         source_id=1,
                         sample_rate=1000000,
                         name='current',
                         units='A')
            w.fsr(3, 0, data)

        with Reader(self._path) as r:
            self.assertEqual(2, len(r.sources))
            self.assertEqual([0, 1], sorted(r.sources.keys()))
            s = r.sources[1]
            self.assertEqual(1, s.source_id)
            self.assertEqual('name', s.name)
            self.assertEqual('vendor', s.vendor)
            self.assertEqual('model', s.model)
            self.assertEqual('version', s.version)
            self.assertEqual('serial_number', s.serial_number)

            self.assertEqual(2, len(r.signals))
            self.assertEqual([0, 3], sorted(r.signals.keys()))
            s = r.signals[3]
            self.assertEqual(3, s.signal_id)
            self.assertEqual(1, s.source_id)
            self.assertEqual(0, s.signal_type)
            self.assertEqual(1000000, s.sample_rate)
            self.assertEqual(83200, s.samples_per_data)
            self.assertEqual(104, s.sample_decimate_factor)
            self.assertEqual(20000, s.entries_per_summary)
            self.assertEqual(100, s.summary_decimate_factor)
            self.assertEqual(100, s.annotation_decimate_factor)
            self.assertEqual(100, s.utc_decimate_factor)
            self.assertEqual('current', s.name)
            self.assertEqual('A', s.units)
            self.assertEqual(len(data), s.length)

            np.testing.assert_allclose(data, r.fsr(3, 0, len(data)))
            stats = r.fsr_statistics(3, 0, len(data), 1)
            np.testing.assert_allclose(np.mean(data, dtype=np.float64),
                                       stats[0, SummaryFSR.MEAN])
            np.testing.assert_allclose(np.min(data), stats[0, SummaryFSR.MIN])
            np.testing.assert_allclose(np.max(data), stats[0, SummaryFSR.MAX])
            np.testing.assert_allclose(np.std(data, ddof=1),
                                       stats[0, SummaryFSR.STD],
                                       rtol=1e-6)
Beispiel #3
0
 def test_user_data(self):
     data = [
         (1, b'user binary'),
         (2, 'user string'),
         (3, {
             'user': '******'
         }),
     ]
     with Writer(self._path) as w:
         for d in data:
             w.user_data(*d)
     with Reader(self._path) as r:
         r.user_data(self._on_user_data)
     self.assertEqual(data, self.user_data)
Beispiel #4
0
    def test_fsr_u1(self):
        data = np.zeros(1024, dtype=np.uint8)
        data[1::2] = 1
        src = np.packbits(data, bitorder='little')

        with Writer(self._path) as w:
            w.source_def(source_id=1,
                         name='name',
                         vendor='vendor',
                         model='model',
                         version='version',
                         serial_number='serial_number')
            w.signal_def(3,
                         source_id=1,
                         data_type=DataType.U1,
                         sample_rate=1000000,
                         name='current',
                         units='A')
            w.fsr(3, 0, src)

        with Reader(self._path) as r:
            self.assertEqual(2, len(r.sources))
            self.assertEqual([0, 1], sorted(r.sources.keys()))
            self.assertEqual(1, r.sources[1].source_id)
            self.assertEqual(2, len(r.signals))
            s = r.signals[3]
            self.assertEqual(DataType.U1, r.signals[3].data_type)
            self.assertEqual(len(data), s.length)

            dst = r.fsr(3, 0, s.length)
            dst_data = np.unpackbits(dst, count=s.length, bitorder='little')
            np.testing.assert_allclose(data, dst_data)

            stats = r.fsr_statistics(3, 0, s.length, 1)
            np.testing.assert_allclose(np.mean(data), stats[0,
                                                            SummaryFSR.MEAN])
            np.testing.assert_allclose(np.min(data), stats[0, SummaryFSR.MIN])
            np.testing.assert_allclose(np.max(data), stats[0, SummaryFSR.MAX])
            np.testing.assert_allclose(np.std(data, ddof=1),
                                       stats[0, SummaryFSR.STD],
                                       rtol=1e-6)
Beispiel #5
0
 def test_source_with_none_strs(self):
     with Writer(self._path) as w:
         w.source_def(source_id=1,
                      name='name',
                      vendor='vendor',
                      model='',
                      version=None,
                      serial_number='serial_number')
         w.signal_def(3,
                      source_id=1,
                      sample_rate=1000000,
                      name='current',
                      units='A')
     with Reader(self._path) as r:
         self.assertEqual(2, len(r.sources))
         self.assertEqual([0, 1], sorted(r.sources.keys()))
         s = r.sources[1]
         self.assertEqual(1, s.source_id)
         self.assertEqual('name', s.name)
         self.assertEqual('', s.model)
         self.assertEqual('', s.version)
Beispiel #6
0
 def test_utc(self):
     signal_id = 3
     expected = self._utc_gen(signal_id)
     with Reader(self._path) as r:
         r.utc(signal_id, 0, self._on_utc)
     np.testing.assert_equal(expected, self.utc)
Beispiel #7
0
 def test_annotation_seek(self):
     signal_id = 3
     expected = self._annotation_gen(signal_id)
     with Reader(self._path) as r:
         r.annotations(signal_id, expected[2][0], self._on_annotations)
     self.assertEqual(expected[2:], self.annotations)