def test_from_array(self) -> None: times = numpy.array([0, 1, 3]) voltages = numpy.array([5, 0, 5]) pulse = TablePulseTemplate.from_array(times, voltages) entries = [] for (time, voltage) in zip(times, voltages): entries.append((time, voltage, HoldInterpolationStrategy())) self.assertEqual(entries, pulse.entries)
def test_from_array_1D(self) -> None: times = numpy.array([0, 1, 3]) voltages = numpy.array([5, 0, 5]) pulse = TablePulseTemplate.from_array(times, voltages) entries = [[]] for (time, voltage) in zip(times, voltages): entries[0].append(TableEntry(time, voltage, HoldInterpolationStrategy())) self.assertEqual(entries, pulse.entries)
def test_from_array_multi(self) -> None: times = numpy.array([0, 1, 3]) voltages = numpy.array([[1,2,3], [2,3,4]]).T # todo: why transposed?? pulse = TablePulseTemplate.from_array(times, voltages) entries = [[],[]] for i, channel in enumerate(voltages.T): for (time, voltage) in zip(times, channel): entries[i].append(TableEntry(time, voltage, HoldInterpolationStrategy())) self.assertEqual(entries, pulse.entries)
def test_from_array_multi_one_voltage(self) -> None: times = numpy.array([[0, 1, 3], [2, 3, 4]]) voltages = numpy.array([1, 2, 3]) pulse = TablePulseTemplate.from_array(times, voltages, [0, 1]) entries = { i: [ TableEntry(time, voltage, HoldInterpolationStrategy()) for (time, voltage) in zip(times[i, :], voltages) ] for i in range(2) } self.assertEqual(entries, pulse.entries)
def test_from_array_exceptions(self): with self.assertRaises(ValueError): TablePulseTemplate.from_array(numpy.arange(0), numpy.arange(1), [0]) with self.assertRaises(ValueError): TablePulseTemplate.from_array(numpy.arange(1), numpy.arange(0), [0]) with self.assertRaises(ValueError): TablePulseTemplate.from_array( numpy.array(numpy.ndindex((1, 2, 1))), numpy.arange(2), [0]) with self.assertRaises(ValueError): TablePulseTemplate.from_array(numpy.zeros(3), numpy.zeros( (3, 2, 3)), [3, 4, 5]) with self.assertRaises(ValueError): TablePulseTemplate.from_array(numpy.zeros((4, 2)), numpy.zeros((3, 4)), [3, 4, 5]) with self.assertRaises(ValueError): TablePulseTemplate.from_array(numpy.zeros((3, 2)), numpy.array(numpy.ndindex((4, 6))), [3, 4, 5]) with self.assertRaises(ValueError): TablePulseTemplate.from_array(numpy.zeros((3, 5)), numpy.array(numpy.ndindex((3, 6))), [3, 4, 5])