示例#1
0
    def test_from_table(self):
        expected = ConstantWaveform(0.1, 0.2, 'A')

        for interp in (HoldInterpolationStrategy(), JumpInterpolationStrategy(), LinearInterpolationStrategy()):
            wf = TableWaveform.from_table('A',
                                          [TableWaveformEntry(0.0, 0.2, interp),
                                           TableWaveformEntry(0.1, 0.2, interp)])
            self.assertEqual(expected, wf)
示例#2
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)
示例#3
0
    def build_waveform(self,
                       parameters: Dict[str, numbers.Real],
                       channel_mapping: Dict[ChannelID, Optional[ChannelID]]) -> Optional[Union[TableWaveform,
                                                                                                MultiChannelWaveform]]:
        self.validate_parameter_constraints(parameters, volatile=set())

        instantiated = [(channel_mapping[channel], instantiated_channel)
                        for channel, instantiated_channel in self.get_entries_instantiated(parameters).items()
                        if channel_mapping[channel] is not None]

        if not instantiated:
            return None

        if self.duration.evaluate_numeric(**parameters) == 0:
            return None

        waveforms = [TableWaveform.from_table(*ch_instantiated)
                     for ch_instantiated in instantiated]

        return MultiChannelWaveform.from_parallel(waveforms)
示例#4
0
 def test_few_entries(self) -> None:
     with self.assertRaises(ValueError):
         TableWaveform.from_table('A', [])
     with self.assertRaises(ValueError):
         TableWaveform.from_table('A', [TableWaveformEntry(0, 0, HoldInterpolationStrategy())])
示例#5
0
 def test_duration_no_entries_exception(self) -> None:
     with self.assertRaises(ValueError):
         TableWaveform.from_table('A', [])
示例#6
0
 def test_duration(self) -> None:
     entries = [TableWaveformEntry(0, 0, HoldInterpolationStrategy()),
                TableWaveformEntry(5, 1, HoldInterpolationStrategy())]
     waveform = TableWaveform.from_table('A', entries)
     self.assertEqual(5, waveform.duration)