Beispiel #1
0
    def exec_general(self, data_1, data_2, fill_value=None):
        tabor_segments = [TaborSegment(d1, d2) for d1, d2 in zip(data_1, data_2)]
        expected_length = (sum(segment.num_points for segment in tabor_segments) + 16 * (len(tabor_segments) - 1)) * 2

        result = make_combined_wave(tabor_segments, fill_value=fill_value)
        self.assertEqual(len(result), expected_length)

        validate_result(tabor_segments, result, fill_value=fill_value)

        destination_array = np.empty(expected_length, dtype=np.uint16)
        result = make_combined_wave(tabor_segments, fill_value=fill_value, destination_array=destination_array)
        validate_result(tabor_segments, result, fill_value=fill_value)
        self.assertEqual(destination_array.__array_interface__['data'], result.__array_interface__['data'],
                         'Data was copied')
Beispiel #2
0
    def test_invalid_segment_length(self):
        gen = itertools.count()
        data_1 = [np.fromiter(gen, count=32, dtype=np.uint16),
                  np.fromiter(gen, count=15, dtype=np.uint16),
                  np.fromiter(gen, count=192, dtype=np.uint16)]

        data_2 = [np.fromiter(gen, count=32, dtype=np.uint16),
                  np.fromiter(gen, count=16, dtype=np.uint16),
                  np.fromiter(gen, count=193, dtype=np.uint16)]

        tabor_segments = [TaborSegment(d, d) for d in data_1]
        with self.assertRaises(ValueError):
            make_combined_wave(tabor_segments)

        tabor_segments = [TaborSegment(d, d) for d in data_2]
        with self.assertRaises(ValueError):
            make_combined_wave(tabor_segments)
Beispiel #3
0
    def exec_general(self, data_1, data_2, fill_value=None):
        tabor_segments = [TaborSegment(d1, d2) for d1, d2 in zip(data_1, data_2)]
        expected_length = (sum(segment.num_points for segment in tabor_segments) + 16 * (len(tabor_segments) - 1)) * 2

        offset = 0
        pyte_result = 15000*np.ones(expected_length, dtype=np.uint16)
        for i, segment in enumerate(tabor_segments):
            offset = pytabor.make_combined_wave(segment[0], segment[1],
                                                dest_array=pyte_result, dest_array_offset=offset,
                                                add_idle_pts=i > 0)
        self.assertEqual(expected_length, offset)

        result = make_combined_wave(tabor_segments, fill_value=15000)
        np.testing.assert_equal(pyte_result, result)

        dest_array = 15000*np.ones(expected_length, dtype=np.uint16)
        result = make_combined_wave(tabor_segments, destination_array=dest_array)
        np.testing.assert_equal(pyte_result, result)
        # test that the destination array data is not copied
        self.assertEqual(dest_array.__array_interface__['data'],
                         result.__array_interface__['data'])

        with self.assertRaises(ValueError):
            make_combined_wave(tabor_segments, destination_array=np.ones(16))
Beispiel #4
0
    def _amend_segments(self, segments: List[TaborSegment]) -> np.ndarray:
        new_lengths = np.asarray([s.num_points for s in segments],
                                 dtype=np.uint32)

        wf_data = make_combined_wave(segments)
        trac_len = len(wf_data) // 2

        segment_index = len(self._segment_capacity)
        first_segment_number = segment_index + 1
        self.device.send_cmd(':TRAC:DEF {},{}'.format(first_segment_number,
                                                      trac_len))
        self.device.send_cmd(':TRAC:SEL {}'.format(first_segment_number))
        self.device.send_cmd(':TRAC:MODE COMB')
        self.device.send_binary_data(pref=':TRAC:DATA', bin_dat=wf_data)

        old_to_update = np.count_nonzero(
            self._segment_capacity != self._segment_lengths)
        segment_capacity = np.concatenate(
            (self._segment_capacity, new_lengths))
        segment_lengths = np.concatenate((self._segment_lengths, new_lengths))
        segment_references = np.concatenate(
            (self._segment_references, np.ones(len(segments), dtype=int)))
        segment_hashes = np.concatenate(
            (self._segment_hashes, [hash(s) for s in segments]))
        if len(segments) < old_to_update:
            for i, segment in enumerate(segments):
                current_segment_number = first_segment_number + i
                self.device.send_cmd(':TRAC:DEF {},{}'.format(
                    current_segment_number, segment.num_points))
        else:
            # flush the capacity
            self.device.download_segment_lengths(segment_capacity)

            # update non fitting lengths
            for i in np.flatnonzero(segment_capacity != segment_lengths):
                self.device.send_cmd(':TRAC:DEF {},{}'.format(
                    i + 1, segment_lengths[i]))

        self._segment_capacity = segment_capacity
        self._segment_lengths = segment_lengths
        self._segment_hashes = segment_hashes
        self._segment_references = segment_references

        return segment_index + np.arange(len(segments), dtype=np.int64)
Beispiel #5
0
    def test_empty_segment_list(self):
        combined = make_combined_wave([])

        self.assertIsInstance(combined, np.ndarray)
        self.assertIs(combined.dtype, np.dtype('uint16'))
        self.assertEqual(len(combined), 0)
Beispiel #6
0
 def get_as_binary(self) -> np.ndarray:
     assert not (self[0] is None or self[1] is None)
     return make_combined_wave([self])