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)
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()) if all(channel_mapping[channel] is None for channel in self.defined_channels): return None 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 self.duration.evaluate_numeric(**parameters) == 0: return None waveforms = [ TableWaveform(*ch_instantiated) for ch_instantiated in instantiated ] if len(waveforms) == 1: return waveforms.pop() else: return MultiChannelWaveform(waveforms)
def test_duration(self) -> None: entries = [ TableWaveformEntry(0, 0, HoldInterpolationStrategy()), TableWaveformEntry(5, 1, HoldInterpolationStrategy()) ] waveform = TableWaveform('A', entries) self.assertEqual(5, waveform.duration)
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)
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)
def test_few_entries(self) -> None: with self.assertRaises(ValueError): TableWaveform('A', [[]]) with self.assertRaises(ValueError): TableWaveform( 'A', [TableWaveformEntry(0, 0, HoldInterpolationStrategy())])
def test_duration_no_entries_exception(self) -> None: with self.assertRaises(ValueError): waveform = TableWaveform('A', []) self.assertEqual(0, waveform.duration)