def test_validate_dark_varying_exposure_and_expire_time(self): # extend case of test_qualified_dark. Iterate over different exposure_time and expire_time directly dark_scan_list, expire_time = [], 11. self.assertEqual(_validate_dark(0.1, expire_time,dark_scan_list), None) time_now = time.time() dark_scan_list = [] self.assertTrue(os.path.isfile(glbl.dk_yaml)) for i in range(3): dark_def = (str(uuid.uuid1()), 0.1, time_now-1200+600*(i)) dark_scan_list.append(dark_def) # should return None if no valid items are found expire_time = 0. light_cnt_time = 0.1 self.assertEqual(_validate_dark(light_cnt_time, expire_time,dark_scan_list), None) expire_time = 1000. light_cnt_time = 3. self.assertEqual(_validate_dark(light_cnt_time, expire_time,dark_scan_list), None) # find the most recent one dark_uid = dark_scan_list[-1][0] light_cnt_time = 0.1 expire_time = 11. self.assertEqual(_validate_dark(light_cnt_time, expire_time,dark_scan_list), dark_uid) # should still find the most recent one, even though there is more than one valid one dark_uid = dark_scan_list[-1][0] expire_time = 22. self.assertEqual(_validate_dark(light_cnt_time, expire_time,dark_scan_list), dark_uid) # now find one that is in time but lower down the list because it has a different count time for i in range(3): dark_def = (str(uuid.uuid1()), 0.1*(i+1), time_now-1200+600*(i)) dark_scan_list.append(dark_def) test_list = copy.copy(dark_scan_list) dark_uid = dark_scan_list[-2][0] expire_time = 22. light_cnt_time = 0.2 self.assertEqual(_validate_dark(light_cnt_time, expire_time,dark_scan_list), dark_uid)
def test_validate_dark_varying_exposure_and_expire_time(self): # extend case of test_qualified_dark. Iterate over different exposure_time and expire_time directly dark_scan_list, expire_time = [], 11. self.assertEqual(_validate_dark(0.1, expire_time, dark_scan_list), None) time_now = time.time() dark_scan_list = [] self.assertTrue(os.path.isfile(glbl.dk_yaml)) for i in range(3): dark_def = (str(uuid.uuid1()), 0.1, time_now - 1200 + 600 * (i)) dark_scan_list.append(dark_def) # should return None if no valid items are found expire_time = 0. light_cnt_time = 0.1 self.assertEqual( _validate_dark(light_cnt_time, expire_time, dark_scan_list), None) expire_time = 1000. light_cnt_time = 3. self.assertEqual( _validate_dark(light_cnt_time, expire_time, dark_scan_list), None) # find the most recent one dark_uid = dark_scan_list[-1][0] light_cnt_time = 0.1 expire_time = 11. self.assertEqual( _validate_dark(light_cnt_time, expire_time, dark_scan_list), dark_uid) # should still find the most recent one, even though there is more than one valid one dark_uid = dark_scan_list[-1][0] expire_time = 22. self.assertEqual( _validate_dark(light_cnt_time, expire_time, dark_scan_list), dark_uid) # now find one that is in time but lower down the list because it has a different count time for i in range(3): dark_def = (str(uuid.uuid1()), 0.1 * (i + 1), time_now - 1200 + 600 * (i)) dark_scan_list.append(dark_def) test_list = copy.copy(dark_scan_list) dark_uid = dark_scan_list[-2][0] expire_time = 22. light_cnt_time = 0.2 self.assertEqual( _validate_dark(light_cnt_time, expire_time, dark_scan_list), dark_uid)
def test_validate_dark(self): """ test login in this function """ # no dark_dict_list if glbl._dark_dict_list: glbl._dark_dict_list = [] self.assertFalse(glbl._dark_dict_list) rv = _validate_dark() self.assertEqual(rv, None) # initiate dark_dict_list # light cnt time is always 0.5 in mock detector, for now.. dark_dict_list = [] now = time.time() # case1: adjust exposure time for i in range(5): dark_dict_list.append({'uid': str(uuid.uuid4()), 'exposure': (i + 1) * 0.1, 'timestamp': now, 'acq_time': 0.1}) glbl._dark_dict_list = dark_dict_list correct_uid = [el['uid'] for el in dark_dict_list if el['exposure'] == 0.5] self.assertEqual(len(correct_uid), 1) rv = _validate_dark() self.assertEqual(rv, correct_uid[-1]) # case2: adjust expire time dark_dict_list = [] for i in range(5): dark_dict_list.append({'uid': str(uuid.uuid4()), 'exposure': 0.5, 'timestamp': now - (i + 1) * 60, 'acq_time': 0.1}) glbl._dark_dict_list = dark_dict_list correct_uid = [el['uid'] for el in dark_dict_list if el['timestamp'] - time.time() <= (glbl.dk_window * 60 - 0.1)] # large window rv = _validate_dark() self.assertEqual(rv, correct_uid[-1]) # small window rv = _validate_dark(0.1) self.assertEqual(rv, None) # medium window rv = _validate_dark(1.5) correct_uid = dark_dict_list[0]['uid'] self.assertEqual(rv, correct_uid) # case3: adjust acqtime dark_dict_list = [] for i in range(5): dark_dict_list.append({'uid': str(uuid.uuid4()), 'exposure': 0.5, 'timestamp': now, 'acq_time': 0.1 * i}) glbl._dark_dict_list = dark_dict_list correct_uid = [el['uid'] for el in dark_dict_list if el['acq_time'] == glbl.frame_acq_time] rv = _validate_dark() self.assertEqual(len(correct_uid), 1) self.assertEqual(rv, correct_uid[-1]) # case4: with real xrun glbl._dark_dict_list = [] # re-init xrun_uid = self.xrun(0, 0) print(xrun_uid) self.assertEqual(len(xrun_uid), 2) # first one is auto_dark dark_uid = _validate_dark() self.assertEqual(xrun_uid[0], dark_uid) # test sc_dark_field_uid msg_list = [] def msg_rv(msg): msg_list.append(msg) self.xrun.msg_hook = msg_rv self.xrun(0, 0) open_run = [el.kwargs for el in msg_list if el.command == 'open_run'][ 0] self.assertEqual(dark_uid, open_run['sc_dk_field_uid']) # no auto-dark glbl.auto_dark = False new_xrun_uid = self.xrun(0, 0) self.assertEqual(len(new_xrun_uid), 1) # no dark frame self.assertEqual(glbl._dark_dict_list[-1]['uid'], dark_uid) # no update
def test_validate_dark(self): """ test login in this function """ # no dark_dict_list glbl._dark_dict_list = [] self.assertFalse(glbl._dark_dict_list) rv = _validate_dark() self.assertEqual(rv, None) # initiate dark_dict_list dark_dict_list = [] now = time.time() acq_time = 0.1 # case1: adjust exposure time for i in range(5): dark_dict_list.append({'uid': str(uuid.uuid4()), 'exposure': (i + 1) * 0.1, 'timestamp': now, 'acq_time': acq_time}) glbl._dark_dict_list = dark_dict_list rv = _validate_dark() self.assertEqual(rv, dark_dict_list[0].get('uid')) # case2: adjust expire time dark_dict_list = [] for i in range(5): dark_dict_list.append({'uid': str(uuid.uuid4()), 'exposure': 0.1, 'timestamp': now - (i + 1) * 60, 'acq_time': acq_time}) glbl._dark_dict_list = dark_dict_list # large window -> still find the best (freshest) one rv = _validate_dark() self.assertEqual(rv, dark_dict_list[0].get('uid')) # small window -> find None rv = _validate_dark(0.1) self.assertEqual(rv, None) # medium window -> find the first one as it's within 1 min window rv = _validate_dark(1.5) self.assertEqual(rv, dark_dict_list[0].get('uid')) # case3: adjust acqtime dark_dict_list = [] for i in range(5): dark_dict_list.append({'uid': str(uuid.uuid4()), 'exposure': 0.1, 'timestamp': now, 'acq_time': acq_time * (i+1)}) glbl._dark_dict_list = dark_dict_list # leave for future debug #print("dark_dict_list = {}" # .format([(el.get('exposure'), # el.get('timestamp'), # el.get('uid'), # el.get('acq_time'))for el in glbl._dark_dict_list])) rv = _validate_dark() self.assertEqual(rv, dark_dict_list[0].get('uid')) # case4: with real xrun if glbl._dark_dict_list: glbl._dark_dict_list = [] self.assertFalse(glbl._dark_dict_list) xrun_uid = self.xrun({}, 0) print(xrun_uid) self.assertEqual(len(xrun_uid), 2) # first one is auto_dark dark_uid = _validate_dark() self.assertEqual(xrun_uid[0], dark_uid) # test sc_dark_field_uid msg_list = [] def msg_rv(msg): msg_list.append(msg) self.xrun.msg_hook = msg_rv self.xrun(0, 0) open_run = [el.kwargs for el in msg_list if el.command == 'open_run'][0] self.assertEqual(dark_uid, open_run['sc_dk_field_uid']) # no auto-dark glbl.auto_dark = False new_xrun_uid = self.xrun(0, 0) self.assertEqual(len(new_xrun_uid), 1) # no dark frame self.assertEqual(glbl._dark_dict_list[-1]['uid'], dark_uid) # no update
def test_validate_dark(self): """ test login in this function """ # no dark_dict_list if glbl._dark_dict_list: glbl._dark_dict_list = [] self.assertFalse(glbl._dark_dict_list) rv = _validate_dark() self.assertEqual(rv, None) # initiate dark_dict_list # light cnt time is always 0.5 in mock detector, for now.. dark_dict_list = [] now = time.time() # case1: adjust exposure time for i in range(5): dark_dict_list.append({ 'uid': str(uuid.uuid4()), 'exposure': (i + 1) * 0.1, 'timestamp': now, 'acq_time': 0.1 }) glbl._dark_dict_list = dark_dict_list correct_uid = [ el['uid'] for el in dark_dict_list if el['exposure'] == 0.5 ] self.assertEqual(len(correct_uid), 1) rv = _validate_dark() self.assertEqual(rv, correct_uid[-1]) # case2: adjust expire time dark_dict_list = [] for i in range(5): dark_dict_list.append({ 'uid': str(uuid.uuid4()), 'exposure': 0.5, 'timestamp': now - (i + 1) * 60, 'acq_time': 0.1 }) glbl._dark_dict_list = dark_dict_list correct_uid = [ el['uid'] for el in dark_dict_list if el['timestamp'] - time.time() <= (glbl.dk_window * 60 - 0.1) ] # large window rv = _validate_dark() self.assertEqual(rv, correct_uid[-1]) # small window rv = _validate_dark(0.1) self.assertEqual(rv, None) # medium window rv = _validate_dark(1.5) correct_uid = dark_dict_list[0]['uid'] self.assertEqual(rv, correct_uid) # case3: adjust acqtime dark_dict_list = [] for i in range(5): dark_dict_list.append({ 'uid': str(uuid.uuid4()), 'exposure': 0.5, 'timestamp': now, 'acq_time': 0.1 * i }) glbl._dark_dict_list = dark_dict_list correct_uid = [ el['uid'] for el in dark_dict_list if el['acq_time'] == glbl.frame_acq_time ] rv = _validate_dark() self.assertEqual(len(correct_uid), 1) self.assertEqual(rv, correct_uid[-1]) # case4: with real xrun glbl._dark_dict_list = [] # re-init xrun_uid = self.xrun(0, 0) print(xrun_uid) self.assertEqual(len(xrun_uid), 2) # first one is auto_dark dark_uid = _validate_dark() self.assertEqual(xrun_uid[0], dark_uid) # test sc_dark_field_uid msg_list = [] def msg_rv(msg): msg_list.append(msg) self.xrun.msg_hook = msg_rv self.xrun(0, 0) open_run = [el.kwargs for el in msg_list if el.command == 'open_run'][0] self.assertEqual(dark_uid, open_run['sc_dk_field_uid']) # no auto-dark glbl.auto_dark = False new_xrun_uid = self.xrun(0, 0) self.assertEqual(len(new_xrun_uid), 1) # no dark frame self.assertEqual(glbl._dark_dict_list[-1]['uid'], dark_uid) # no update
def test_validate_dark(self): """ test login in this function """ # no dark_dict_list glbl["_dark_dict_list"] = [] rv = _validate_dark() assert rv is None # initiate dark_dict_list dark_dict_list = [] now = time.time() # configure area detector xpd_configuration["area_det"].cam.acquire_time.put(0.1) xpd_configuration["area_det"].images_per_set.put(5) acq_time = xpd_configuration["area_det"].cam.acquire_time.get() num_frame = xpd_configuration["area_det"].images_per_set.get() light_cnt_time = acq_time * num_frame # case1: adjust exposure time for i in range(5): dark_dict_list.append( { "uid": str(uuid.uuid4()), "exposure": (i + 1) * 0.1, "timestamp": now, "acq_time": acq_time, } ) glbl["_dark_dict_list"] = dark_dict_list rv = _validate_dark(glbl["dk_window"]) correct_set = sorted( [ el for el in dark_dict_list if abs(el["exposure"] - light_cnt_time) < acq_time ], key=lambda x: x["exposure"], )[0] print(dark_dict_list) print("correct_set = {}".format(correct_set)) assert rv == correct_set.get("uid") # case2: adjust expire time dark_dict_list = [] for i in range(5): dark_dict_list.append( { "uid": str(uuid.uuid4()), "exposure": light_cnt_time, "timestamp": now - (i + 1) * 60, "acq_time": acq_time, } ) glbl["_dark_dict_list"] = dark_dict_list # large window -> still find the best (freshest) one rv = _validate_dark() assert rv == dark_dict_list[0].get("uid") # small window -> find None rv = _validate_dark(0.1) assert rv is None # medium window -> find the first one as it's within 1 min window rv = _validate_dark(1.5) assert rv == dark_dict_list[0].get("uid") # case3: adjust acqtime dark_dict_list = [] for i in range(5): dark_dict_list.append( { "uid": str(uuid.uuid4()), "exposure": light_cnt_time, "timestamp": now, "acq_time": acq_time * (i + 1), } ) glbl["_dark_dict_list"] = dark_dict_list # leave for future debug # print("dark_dict_list = {}" # .format([(el.get('exposure'), # el.get('timestamp'), # el.get('uid'), # el.get('acq_time'))for el in # glbl['_dark_dict_list']])) rv = _validate_dark() assert rv == dark_dict_list[0].get("uid") # case4: with real xrun if glbl["_dark_dict_list"]: glbl["_dark_dict_list"] = [] xrun_uid = self.xrun({}, 0) print(xrun_uid) assert len(xrun_uid) == 2 # first one is auto_dark dark_uid = _validate_dark() assert xrun_uid[0] == dark_uid # test sc_dark_field_uid msg_list = [] def msg_rv(msg): msg_list.append(msg) self.xrun.msg_hook = msg_rv self.xrun(0, 0) open_run = [el.kwargs for el in msg_list if el.command == "open_run"][ 0 ] assert dark_uid == open_run["sc_dk_field_uid"] # no auto-dark glbl["auto_dark"] = False new_xrun_uid = self.xrun(0, 0) assert len(new_xrun_uid) == 1 # no dark frame assert glbl["_dark_dict_list"][-1]["uid"] == dark_uid # no update