コード例 #1
0
    def test_ScanLine(self):
        indict1, indict2 = self.get_ScanLine_indices()
        # Only the number of measurements on the last dimension can influence the result.
        indict1["NumberOfMeasurements"] = 3

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        self.standard_init_tests(
            pyscan.initializeScan([indict1, indict2], test_dal))

        expected_positions = [[-3, -3, 0, 0], [-3, -3, 1, 1], [-3, -3, 2, 2],
                              [-2, -2, 0, 0], [-2, -2, 1, 1], [-2, -2, 2, 2],
                              [-1, -1, 0, 0], [-1, -1, 1, 1], [-1, -1, 2, 2],
                              [-0, -0, 0, 0], [-0, -0, 1, 1], [-0, -0, 2, 2]]

        result = pyscan.startScan()
        self.standard_scan_tests(result, test_dal, indict1, indict2,
                                 expected_positions)
        self.standard_line_tests(result, indict1, indict2, expected_positions)

        # Check if the results match with the data collected with the original pyscan.
        self.assertEqual(test_ScanLine_first_KnobReadback,
                         result["KnobReadback"],
                         "KnobReadback format does not match")
        self.assertEqual(test_ScanLine_first_Validation, result["Validation"],
                         "Validation format does not match")
        self.assertEqual(test_ScanLine_first_Observable, result["Observable"],
                         "Observable format does not match")

        # Repeat the same test with multiple measurements.

        indict1, indict2 = self.get_ScanLine_indices()
        # Each measurement (KnobReadback, Observable, Validation) is repeated 4 times.
        indict2["NumberOfMeasurements"] = 4
        # This should not change anything - and we are testing this.
        indict1["NumberOfMeasurements"] = 5

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        self.standard_init_tests(
            pyscan.initializeScan([indict1, indict2], test_dal))
        result = pyscan.startScan()
        self.standard_scan_tests(result, test_dal, indict1, indict2,
                                 expected_positions)
        self.standard_line_tests(result, indict1, indict2, expected_positions)

        # Check if the results match with the data collected with the original pyscan.
        self.assertEqual(test_ScanLine_second_KnobReadback,
                         result["KnobReadback"],
                         "KnobReadback format does not match")
        self.assertEqual(test_ScanLine_second_Validation, result["Validation"],
                         "Validation format does not match")
        self.assertEqual(test_ScanLine_second_Observable, result["Observable"],
                         "Observable format does not match")
コード例 #2
0
    def test_abort(self):
        indict1 = dict()
        indict1['Knob'] = ["1.1"]
        indict1["ScanValues"] = [-3, -2, -1, 0]
        indict1['Observable'] = ["READ1"]
        indict1['Waiting'] = 0.01
        indict1["KnobWaitingExtra"] = 0.3

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        result = pyscan.initializeScan(indict1, test_dal)
        self.standard_init_tests(result)

        def abort_scan():
            sleep(0.1)
            # We might want to wait for the initialization to happen, or just wait for the pause to work.
            n_retry = 0
            while n_retry < 5:
                try:
                    pyscan.abortScan = 1
                except:
                    pass
                n_retry += 1
                # Initialization should not take more than 1 second.
                sleep(0.2)

        threading.Thread(target=abort_scan).start()
        self.assertRaisesRegex(Exception, "aborted", pyscan.startScan)
コード例 #3
0
    def test_Conditions(self):

        indict1, indict2 = self.get_ScanLine_indices()
        # Only the number of measurements on the last dimension can influence the result.
        indict2['Monitor'] = ["PYSCAN:TEST:MONITOR1"]
        indict2['MonitorValue'] = [1]
        indict2['MonitorTolerance'] = [0.01]
        indict2['MonitorAction'] = ["WaitAndAbort"]
        indict2['MonitorTimeout'] = [0.1]

        # This will pass, because every 2 read attempts the monitor will have a valid value.
        test_dal = CurrentMockDal(
            pv_fixed_values={"PYSCAN:TEST:MONITOR1": [0, 1]})
        pyscan = CurrentScan()
        self.standard_init_tests(
            pyscan.initializeScan([indict1, indict2], test_dal))
        result = pyscan.startScan()

        # Correct "ErrorMessage" when successfully completed.
        self.assertEqual(
            result["ErrorMessage"],
            "Measurement finalized (finished/aborted) normally. "
            "Need initialisation before next measurement.", "Scan failed.")

        # This will never pass, but we should wait for the retry attempts in this case.
        test_dal = CurrentMockDal(
            pv_fixed_values={"PYSCAN:TEST:MONITOR1": [0]})
        pyscan = CurrentScan()
        self.standard_init_tests(
            pyscan.initializeScan([indict1, indict2], test_dal))

        # Correct "ErrorMessage" when successfully completed.
        self.assertRaisesRegex(Exception, "Number of maximum read attempts",
                               pyscan.startScan)

        # This will never pass, but the scan has to abort immediately without doing 3 attempts.
        indict2['MonitorAction'] = ["Abort"]
        test_dal = CurrentMockDal(
            pv_fixed_values={"PYSCAN:TEST:MONITOR1": [0]})
        pyscan = CurrentScan()
        self.standard_init_tests(
            pyscan.initializeScan([indict1, indict2], test_dal))

        # Correct "ErrorMessage" when successfully completed.
        self.assertRaisesRegex(Exception, "expected value", pyscan.startScan)
コード例 #4
0
    def test_output_format(self):
        # Test with the old scan, to verify if this is it.
        indict1, indict3 = self.get_ScanLine_indices()
        indict2, indict4 = self.get_ScanSeries_indices()

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        result = pyscan.initializeScan([indict1, indict2, indict3, indict4],
                                       test_dal)

        self.assertEqual(result["Validation"],
                         test_output_format_expected_result,
                         "The pre-allocation was not correct. Oh boy..")
コード例 #5
0
    def test_progress(self):
        indict = {}
        indict['Knob'] = "PYSCAN:TEST:MOTOR1:SET"
        indict['Waiting'] = 0.1
        indict["KnobWaitingExtra"] = 0.3

        indict['Observable'] = "PYSCAN:TEST:OBS1"
        # One percentage step for each scan value.
        indict['ScanValues'] = [0, 1, 2, 3]
        # This should not change the percentages.
        indict['NumberOfMeasurements'] = 2

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()

        # Check if the progress bar works.
        def monitor_scan():
            # make sure the initialization is done:
            while pyscan.ProgDisp.Progress:
                sleep(0.01)

            current_value = 0
            while current_value < 100:
                last_value = pyscan.ProgDisp.Progress
                if last_value > current_value:
                    progress_values.append(pyscan.ProgDisp.Progress)
                    current_value = last_value
            else:
                nonlocal progress_completed
                progress_completed = True

        progress_values = []
        progress_completed = False
        threading.Thread(target=monitor_scan).start()

        pyscan.initializeScan(indict, dal=test_dal)
        outdict = pyscan.startScan()

        # Correct "ErrorMessage" when successfully completed.
        self.assertEqual(
            outdict["ErrorMessage"],
            "Measurement finalized (finished/aborted) normally. "
            "Need initialisation before next measurement.", "Scan failed.")

        # Wait for the progress thread to terminate.
        sleep(0.2)

        self.assertTrue(progress_completed, "Progress bar did not complete.")
        self.assertListEqual(progress_values, [25, 50, 75, 100],
                             "The completed percentage is wrong.")
コード例 #6
0
    def test_simple_scan(self):
        # Test the simplest possible scan.
        indict1 = dict()
        indict1['Knob'] = ["1.1"]
        indict1["ScanValues"] = [-3, -2, -1, 0]
        indict1['Observable'] = ["READ1"]
        indict1['Waiting'] = 0.1

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        result = pyscan.initializeScan(indict1, test_dal)
        self.standard_init_tests(result)
        result = pyscan.startScan()

        # TODO: This is a known difference. Backward compatibility in this case is not guaranteed.
        # # Check if the results match with the data collected with the original pyscan.
        # self.assertEqual(test_SimpleScan_first_KnobReadback, result["KnobReadback"],
        #                  "KnobReadback format does not match")
        # self.assertEqual(test_SimpleScan_first_Validation, result["Validation"],
        #                  "Validation format does not match")
        # self.assertEqual(test_SimpleScan_first_Observable, result["Observable"],
        #                  "Observable format does not match")

        # With multiple measurements.

        indict1 = dict()
        indict1['Knob'] = ["1.1"]
        indict1["ScanValues"] = [-3, -2, -1, 0]
        indict1['Observable'] = ["READ1"]
        indict1['Waiting'] = 0.1
        indict1["NumberOfMeasurements"] = 3

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        result = pyscan.initializeScan(indict1, test_dal)
        self.standard_init_tests(result)
        result = pyscan.startScan()
コード例 #7
0
    def test_abort_paused_scan(self):
        indict1 = dict()
        indict1['Knob'] = ["1.1"]
        indict1["ScanValues"] = [-3, -2, -1, 0]
        indict1['Observable'] = ["READ1"]
        indict1['Waiting'] = 0.01
        indict1["KnobWaitingExtra"] = 0.3
        indict1['StepbackOnPause'] = 0

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        result = pyscan.initializeScan(indict1, test_dal)
        self.standard_init_tests(result)

        def pause_scan():
            # We need to let the scan initialize first, otherwise it overwrites the pauseScan flag.
            sleep(0.1)
            # We might want to wait for the initialization to happen, or just wait for the pause to work.
            n_retry = 0
            while n_retry < 5:
                try:
                    pyscan.pauseScan = 1
                    break
                except:
                    pass
                n_retry += 1
                # Initialization should not take more than 1 second.
                sleep(0.2)
            sleep(1.5)
            pyscan.abortScan = 1

        begin_timestamp = time()
        threading.Thread(target=pause_scan).start()

        self.assertRaisesRegex(Exception, "aborted", pyscan.startScan)
        time_elapsed = time() - begin_timestamp
        self.assertTrue(
            time_elapsed > 1.5,
            "We paused the scan for 1 seconds before aborting, "
            "but this did not reflect in the execution time %f." %
            time_elapsed)
コード例 #8
0
    def test_ScanMixed(self):
        # First dimension is Range scan, second is Series scan.
        indict1, _ = self.get_ScanLine_indices()
        _, indict2 = self.get_ScanSeries_indices()
        # Only the number of measurements on the last dimension can influence the result.
        indict1["NumberOfMeasurements"] = 3

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        self.standard_init_tests(
            pyscan.initializeScan([indict1, indict2], test_dal))

        # First dimension LineScan, second dimension first change one, than another.
        expected_positions = [[-3, -3, 0, "2.2"], [-3, -3, 1, "2.2"],
                              [-3, -3, 2, "2.2"], [-3, -3, "2.1", 0],
                              [-3, -3, "2.1", 1], [-2, -2, 0, "2.2"],
                              [-2, -2, 1, "2.2"], [-2, -2, 2, "2.2"],
                              [-2, -2, "2.1", 0], [-2, -2, "2.1", 1],
                              [-1, -1, 0, "2.2"], [-1, -1, 1, "2.2"],
                              [-1, -1, 2, "2.2"], [-1, -1, "2.1", 0],
                              [-1, -1, "2.1", 1], [-0, -0, 0, "2.2"],
                              [-0, -0, 1, "2.2"], [-0, -0, 2, "2.2"],
                              [-0, -0, "2.1", 0], [-0, -0, "2.1", 1]]

        result = pyscan.startScan()
        self.standard_scan_tests(result, test_dal, indict1, indict2,
                                 expected_positions)

        # Check if the results match with the data collected with the original pyscan.
        self.assertEqual(test_ScanMixed_first_KnobReadback,
                         result["KnobReadback"],
                         "KnobReadback format does not match")
        self.assertEqual(test_ScanMixed_first_Validation, result["Validation"],
                         "Validation format does not match")
        self.assertEqual(test_ScanMixed_first_Observable, result["Observable"],
                         "Observable format does not match")

        # Repeat the same test with multiple measurements.

        indict1, _ = self.get_ScanLine_indices()
        _, indict2 = self.get_ScanSeries_indices()
        # Only the number of measurements on the last dimension can influence the result.
        indict1["NumberOfMeasurements"] = 3
        # Each measurement (KnobReadback, Observable, Validation) is repeated 4 times.
        indict2["NumberOfMeasurements"] = 4

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        self.standard_init_tests(
            pyscan.initializeScan([indict1, indict2], test_dal))

        # Check if the results match with the data collected with the original pyscan.
        self.assertEqual(test_ScanMixed_second_KnobReadback,
                         result["KnobReadback"],
                         "KnobReadback format does not match")
        self.assertEqual(test_ScanMixed_second_Validation,
                         result["Validation"],
                         "Validation format does not match")
        self.assertEqual(test_ScanMixed_second_Observable,
                         result["Observable"],
                         "Observable format does not match")
コード例 #9
0
    def test_ScanSeries(self):
        indict1, indict2 = self.get_ScanSeries_indices()
        # Only the number of measurements on the last dimension can influence the result.
        indict1["NumberOfMeasurements"] = 3

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        self.standard_init_tests(
            pyscan.initializeScan([indict1, indict2], test_dal))

        # Vary one value in its entire range, per axis. Other values are initial positions.
        expected_positions = [[-3, "1.2", 0, "2.2"], [-3, "1.2", 1, "2.2"],
                              [-3, "1.2", 2, "2.2"], [-3, "1.2", "2.1", 0],
                              [-3, "1.2", "2.1", 1], [-2, "1.2", 0, "2.2"],
                              [-2, "1.2", 1, "2.2"], [-2, "1.2", 2, "2.2"],
                              [-2, "1.2", "2.1", 0], [-2, "1.2", "2.1", 1],
                              [-1, "1.2", 0, "2.2"], [-1, "1.2", 1, "2.2"],
                              [-1, "1.2", 2, "2.2"], [-1, "1.2", "2.1", 0],
                              [-1, "1.2", "2.1", 1], [-0, "1.2", 0, "2.2"],
                              [-0, "1.2", 1, "2.2"], [-0, "1.2", 2, "2.2"],
                              [-0, "1.2", "2.1", 0], [-0, "1.2", "2.1", 1],
                              ["1.1", -3, 0, "2.2"], ["1.1", -3, 1, "2.2"],
                              ["1.1", -3, 2, "2.2"], ["1.1", -3, "2.1", 0],
                              ["1.1", -3, "2.1", 1], ["1.1", -2, 0, "2.2"],
                              ["1.1", -2, 1, "2.2"], ["1.1", -2, 2, "2.2"],
                              ["1.1", -2, "2.1", 0], ["1.1", -2, "2.1", 1],
                              ["1.1", -1, 0, "2.2"], ["1.1", -1, 1, "2.2"],
                              ["1.1", -1, 2, "2.2"], ["1.1", -1, "2.1", 0],
                              ["1.1", -1, "2.1", 1], ["1.1", -0, 0, "2.2"],
                              ["1.1", -0, 1, "2.2"], ["1.1", -0, 2, "2.2"],
                              ["1.1", -0, "2.1", 0], ["1.1", -0, "2.1", 1]]

        result = pyscan.startScan()
        self.standard_scan_tests(result, test_dal, indict1, indict2,
                                 expected_positions)
        self.standard_series_tests(result, indict1, indict2,
                                   expected_positions)

        # Check if the results match with the data collected with the original pyscan.
        self.assertEqual(test_ScanSeries_first_KnobReadback,
                         result["KnobReadback"],
                         "KnobReadback format does not match")
        self.assertEqual(test_ScanSeries_first_Validation,
                         result["Validation"],
                         "Validation format does not match")
        self.assertEqual(test_ScanSeries_first_Observable,
                         result["Observable"],
                         "Observable format does not match")

        # Repeat the same test with multiple measurements.

        indict1, indict2 = self.get_ScanSeries_indices()
        # Each measurement (KnobReadback, Observable, Validation) is repeated 4 times.
        indict2["NumberOfMeasurements"] = 2
        # Only the number of measurements on the last dimension can influence the result.
        indict1["NumberOfMeasurements"] = 3

        test_dal = CurrentMockDal()
        pyscan = CurrentScan()
        self.standard_init_tests(
            pyscan.initializeScan([indict1, indict2], test_dal))
        result = pyscan.startScan()
        self.standard_scan_tests(result, test_dal, indict1, indict2,
                                 expected_positions)
        self.standard_series_tests(result, indict1, indict2,
                                   expected_positions)

        # Check if the results match with the data collected with the original pyscan.
        self.assertEqual(test_ScanSeries_second_KnobReadback,
                         result["KnobReadback"],
                         "KnobReadback format does not match")
        self.assertEqual(test_ScanSeries_second_Validation,
                         result["Validation"],
                         "Validation format does not match")
        self.assertEqual(test_ScanSeries_second_Observable,
                         result["Observable"],
                         "Observable format does not match")