def test_multiple_conditions(self): config.bs_connection_mode = "pull" config.bs_default_host = "localhost" config.bs_default_port = 9999 positioner = StaticPositioner(5) initialization = [action_set_epics_pv("PYSCAN:TEST:VALID1", 778)] readables = [bs_property("CAMERA1:X")] conditions = [ bs_condition("CAMERA1:VALID", 10, operation=ConditionComparison.EQUAL), bs_condition("CAMERA1:VALID", 11, operation=ConditionComparison.LOWER), epics_condition("PYSCAN:TEST:VALID1", 778, operation=ConditionComparison.LOWER_OR_EQUAL), epics_condition("PYSCAN:TEST:VALID1", 779, operation=ConditionComparison.LOWER) ] result = scan(positioner=positioner, readables=readables, conditions=conditions, initialization=initialization, settings=scan_settings(measurement_interval=0.25, n_measurements=1)) self.assertTrue(all(x[0] == i + 1 for i, x in enumerate(result)), "The result is wrong.")
def test_same_condition_multiple_times(self): config.bs_connection_mode = "pull" config.bs_default_host = "localhost" config.bs_default_port = 9999 positioner = StaticPositioner(5) readables = [bs_property("CAMERA1:X")] conditions = [ bs_condition("CAMERA1:VALID", 10, operation=ConditionComparison.EQUAL), bs_condition("CAMERA1:VALID", 10, operation=ConditionComparison.EQUAL) ] result = scan(positioner=positioner, readables=readables, conditions=conditions, settings=scan_settings(measurement_interval=0.25, n_measurements=1)) self.assertTrue(all(x[0] == i + 1 for i, x in enumerate(result)), "The result is wrong.")
def test_bsread_positioner_scan_condition(self): # DO NOT INCLUDE IN README - default. config.bs_connection_mode = "pull" config.bs_default_host = "localhost" config.bs_default_port = 9999 config.bs_default_missing_property_value = Exception config.scan_acquisition_retry_limit = 30 config.scan_acquisition_retry_delay = 0 # Lets acquire 10 messages from the stream. n_messages = 5 positioner = BsreadPositioner(n_messages) # Read camera X and Y value. readables = [bs_property("CAMERA1:X")] conditions = [bs_condition("BEAM_OK", 1, action=ConditionAction.Retry)] start_time = time.time() # The result will have 10 consecutive, valid, messages from the stream. result = scan(positioner=positioner, readables=readables, conditions=conditions) stop_time = time.time() # It should take around 5 second if the retry delay is used. self.assertTrue(stop_time - start_time < 6) self.assertEqual(n_messages, len(result)) for index in range(n_messages): self.assertEqual(result[index][0], (index + 1) * 20)
def test_scanning_bsread_stream_with_conditions(self): # DO NOT INCLUDE IN README - default. config.bs_connection_mode = "pull" config.bs_default_host = "localhost" config.bs_default_port = 9999 config.bs_default_missing_property_value = Exception # Do a max of 10 retries before aborting. # config.scan_acquisition_retry_limit = 10 # No delay between retries as we are using a bsread source - this limits our retry rate. # config.scan_acquisition_retry_delay = 0 # Lets acquire 10 messages from the stream. n_messages = 10 positioner = BsreadPositioner(n_messages) # Read camera X and Y value. readables = [bs_property("CAMERA1:X"), bs_property("CAMERA1:Y")] # Stream message is valid if "CAMERA1:VALID1" equals 1. # In case this message is not valid, retry with the next message (10 times, as defined above). conditions = bs_condition("CAMERA1:VALID", 10, action=ConditionAction.Retry) # The result will have 10 consecutive, valid, messages from the stream. result = scan(positioner=positioner, readables=readables, conditions=conditions) self.assertEqual(n_messages, len(result))
def test_mixed_sources(self): config.bs_connection_mode = "pull" config.bs_default_host = "localhost" config.bs_default_port = 9999 positions = [[1, 1], [2, 2], [3, 3], [4, 4]] positioner = VectorPositioner(positions) writables = [ epics_pv("PYSCAN:TEST:MOTOR1:SET", "PYSCAN:TEST:MOTOR1:GET"), epics_pv("PYSCAN:TEST:MOTOR2:SET", "PYSCAN:TEST:MOTOR2:GET") ] readables = [ bs_property("CAMERA1:X"), bs_property("CAMERA1:Y"), epics_pv("PYSCAN:TEST:OBS1") ] conditions = [ epics_condition("PYSCAN:TEST:VALID1", 10), bs_condition("CAMERA1:VALID", 10) ] initialization = [ action_set_epics_pv("PYSCAN:TEST:PRE1:SET", 1, "PYSCAN:TEST:PRE1:GET") ] finalization = [ action_set_epics_pv("PYSCAN:TEST:PRE1:SET", 0, "PYSCAN:TEST:PRE1:GET"), action_restore(writables) ] result = scan(positioner=positioner, readables=readables, writables=writables, conditions=conditions, initialization=initialization, finalization=finalization, settings=scan_settings(measurement_interval=0.25, n_measurements=1)) self.assertEqual(len(result), len(positions), "Not the expected number of results.") # The first 2 attributes are from bs_read, they should be equal to the pulse ID processed. self.assertTrue(all(x[0] == x[1] and x[2] == 1 for x in result), "The result is wrong.")