示例#1
0
    def test_register_measurement_windows(self):
        raw_card = dummy_modules.dummy_atsaverage.core.AlazarCard()
        card = AlazarCard(raw_card)

        self.assertIs(card.card, raw_card)

        card.register_mask_for_channel('A', 3, 'auto')
        card.register_mask_for_channel('B', 1, 'auto')

        card.config = dummy_modules.dummy_atsaverage.config.ScanlineConfiguration()

        card.register_measurement_windows('empty', dict())

        begins = np.arange(100)*176.5
        lengths = np.ones(100)*10*np.pi
        card.register_measurement_windows('otto', dict(A=(begins, lengths)))

        self.assertEqual(set(card._registered_programs.keys()), {'empty', 'otto'})
        self.assertEqual(card._registered_programs['empty'].masks(lambda x: x), [])

        [(result_begins, result_lengths)] = card._registered_programs['otto'].masks(lambda _, b, l: (b, l))
        expected_begins = np.rint(begins / 10).astype(dtype=np.uint64)
        np.testing.assert_equal(result_begins, expected_begins)

        # pi ist genau 3
        np.testing.assert_equal(result_lengths if isinstance(result_lengths, np.ndarray) else result_lengths.as_ndarray(), 3)
示例#2
0
    def test_arm_operation(self):
        raw_card = dummy_modules.dummy_atsaverage.core.AlazarCard()
        card = AlazarCard(raw_card)

        card.register_mask_for_channel('A', 3, 'auto')
        card.register_mask_for_channel('B', 1, 'auto')

        card.register_operations('otto', [])

        card.default_config = dummy_modules.dummy_atsaverage.config.ScanlineConfiguration(
        )

        with self.assertRaisesRegex(RuntimeError, 'No operations'):
            card.arm_program('otto')

        card.register_operations('otto', ['asd'])

        with self.assertRaisesRegex(RuntimeError, "No masks"):
            card.arm_program('otto')

        begins = np.arange(100) * 176.5
        lengths = np.ones(100) * 10 * np.pi
        card.register_measurement_windows('otto', dict(A=(begins, lengths)))

        card.default_config.totalRecordSize = 17

        with self.assertRaisesRegex(
                ValueError, "total record size is smaller than needed"):
            card.arm_program('otto')

        card.default_config.totalRecordSize = 0

        with mock.patch.object(
                card.card, 'applyConfiguration') as mock_applyConfiguration:
            with mock.patch.object(
                    card.card, 'startAcquisition') as mock_startAcquisition:
                card.arm_program('otto')

                mock_applyConfiguration.assert_called_once_with(
                    card.current_config, True)
                mock_startAcquisition.assert_called_once_with(1)

                mock_applyConfiguration.reset_mock()
                mock_startAcquisition.reset_mock()
                card.arm_program('otto')

                mock_applyConfiguration.assert_not_called()
                mock_startAcquisition.assert_called_once_with(1)
示例#3
0
    def test_make_mask(self):
        card = AlazarCard(None)
        card.register_mask_for_channel('M', 3, 'auto')

        begins = np.arange(15, dtype=np.uint64)*16
        lengths = 1+np.arange(15, dtype=np.uint64)

        with self.assertRaises(KeyError):
            card._make_mask('N', begins, lengths)

        with self.assertRaises(ValueError):
            card._make_mask('M', begins, lengths*3)

        mask = card._make_mask('M', begins, lengths)
        self.assertEqual(mask.identifier, 'M')
        np.testing.assert_equal(mask.begin, begins)
        np.testing.assert_equal(mask.length, lengths)
        self.assertEqual(mask.channel, 3)
示例#4
0
    def test_arm_operation(self):
        raw_card = dummy_modules.dummy_atsaverage.core.AlazarCard()
        card = AlazarCard(raw_card)

        card.register_mask_for_channel('A', 3, 'auto')
        card.register_mask_for_channel('B', 1, 'auto')

        card.register_operations('otto', [])

        card.config = dummy_modules.dummy_atsaverage.config.ScanlineConfiguration(
        )

        with self.assertRaises(RuntimeError):
            card.arm_program('otto')

        card.register_operations('otto', ['asd'])

        with self.assertRaises(RuntimeError):
            card.arm_program('otto')

        begins = np.arange(100) * 176.5
        lengths = np.ones(100) * 10 * np.pi
        card.register_measurement_windows('otto', dict(A=(begins, lengths)))

        card.config.totalRecordSize = 17

        with self.assertRaises(ValueError):
            card.arm_program('otto')

        card.config.totalRecordSize = 0
        card.arm_program('otto')

        self.assertEqual(card.config._apply_calls, [(raw_card, True)])
        self.assertEqual(card.card._startAcquisition_calls, [1])

        card.arm_program('otto')
        self.assertEqual(card.config._apply_calls, [(raw_card, True)])
        self.assertEqual(card.card._startAcquisition_calls, [1, 1])
示例#5
0
    def test_add_mask_prototype(self):
        card = AlazarCard(None)

        card.register_mask_for_channel('M', 3, 'auto')
        self.assertEqual(card._mask_prototypes, dict(M=(3, 'auto')))

        with self.assertRaises(ValueError):
            card.register_mask_for_channel('M', 'A', 'auto')

        with self.assertRaises(NotImplementedError):
            card.register_mask_for_channel('M', 1, 'periodic')