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)
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)
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)
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())])
def test_duration_no_entries_exception(self) -> None: with self.assertRaises(ValueError): TableWaveform.from_table('A', [])
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)