Example #1
0
 def test_unsafe_get_subset_for_channels(self):
     interp = DummyInterpolationStrategy()
     entries = [TableWaveformEntry(0, 0, interp),
                TableWaveformEntry(2.1, -33.2, interp),
                TableWaveformEntry(5.7, 123.4, interp)]
     waveform = TableWaveform('A', entries)
     self.assertIs(waveform.unsafe_get_subset_for_channels({'A'}), waveform)
Example #2
0
    def test_unsafe_sample(self) -> None:
        interp = DummyInterpolationStrategy()
        entries = [
            TableWaveformEntry(0, 0, interp),
            TableWaveformEntry(2.1, -33.2, interp),
            TableWaveformEntry(5.7, 123.4, interp)
        ]
        waveform = TableWaveform('A', entries)
        sample_times = numpy.linspace(.5, 5.5, num=11)

        expected_interp_arguments = [
            ((0, 0), (2.1, -33.2), [0.5, 1.0, 1.5, 2.0]),
            ((2.1, -33.2), (5.7, 123.4), [2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5])
        ]
        expected_result = numpy.copy(sample_times)

        result = waveform.unsafe_sample('A', sample_times)

        self.assertEqual(expected_interp_arguments, interp.call_arguments)
        numpy.testing.assert_equal(expected_result, result)

        output_expected = numpy.empty_like(expected_result)
        output_received = waveform.unsafe_sample('A',
                                                 sample_times,
                                                 output_array=output_expected)
        self.assertIs(output_expected, output_received)
        numpy.testing.assert_equal(expected_result, output_received)
Example #3
0
    def test_simple_properties(self):
        interp = DummyInterpolationStrategy()
        entries = [TableWaveformEntry(0, 0, interp),
                   TableWaveformEntry(2.1, -33.2, interp),
                   TableWaveformEntry(5.7, 123.4, interp)]
        chan = 'A'
        waveform = TableWaveform(chan, entries)

        self.assertEqual(waveform.defined_channels, {chan})
        self.assertIs(waveform.unsafe_get_subset_for_channels({'A'}), waveform)
Example #4
0
    def test_simple_properties(self):
        interp = DummyInterpolationStrategy()
        entries = [TableWaveformEntry(0, 0, interp),
                   TableWaveformEntry(2.1, -33.2, interp),
                   TableWaveformEntry(5.7, 123.4, interp)]
        chan = 'A'
        waveform = TableWaveform.from_table(chan, entries)

        self.assertEqual(waveform.defined_channels, {chan})
        self.assertIs(waveform.unsafe_get_subset_for_channels({'A'}), waveform)
        assert_constant_consistent(self, waveform)

        evaled = eval(repr(waveform))
        self.assertEqual(evaled, waveform)
Example #5
0
    def test_sample(self) -> None:
        interp = DummyInterpolationStrategy()
        entries = [[WaveformTableEntry(0, 0, interp),
                    WaveformTableEntry(2.1, -33.2, interp),
                    WaveformTableEntry(5.7, 123.4, interp)]]
        waveform = TableWaveform(entries)
        sample_times = numpy.linspace(98.5, 103.5, num=11)

        offset = 0.5
        result = waveform.sample(sample_times, offset)
        expected_data = [((0, 0), (2.1, -33.2), [0.5, 1.0, 1.5, 2.0]),
                         ((2.1, -33.2), (5.7, 123.4), [2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5])]
        self.assertEqual(expected_data, interp.call_arguments)
        expected_result = [sample_times - 98]
        self.assertTrue(numpy.all(expected_result == result))
Example #6
0
    def test_num_channels(self) -> None:
        waveform = TableWaveform([])
        self.assertEqual(0, waveform.num_channels)

        interp = DummyInterpolationStrategy()
        entries = [[WaveformTableEntry(0, 0, interp),
                    WaveformTableEntry(5, 1, interp)]]
        waveform = TableWaveform(entries)
        self.assertEqual(1, waveform.num_channels)

        entries = [[WaveformTableEntry(0, 0, interp),
                    WaveformTableEntry(2.1, -33.2, interp),
                    WaveformTableEntry(5.7, 123.4, interp)],
                   [WaveformTableEntry(0, 0, interp),
                    WaveformTableEntry(2.1, -33.2, interp),
                    WaveformTableEntry(5.7, 123.4, interp)]]
        waveform = TableWaveform(entries)
        self.assertEqual(2, waveform.num_channels)
Example #7
0
 def test_repr(self):
     interpolation = DummyInterpolationStrategy()
     self.assertEqual(f"TableWaveformEntry(t={1.}, v={2.}, interp={interpolation})",
                      repr(TableWaveformEntry(t=1., v=2., interp=interpolation)))