def test_dark_in_prun_cannot_find_a_valid_dark(self):
     # case 2: can't find a qualified dark and test if md got updated
     time_now = time.time()
     self.bt.set_wavelength(0.18448)
     # build the dark yml
     dark_scan_list = []
     dark_uid = str(uuid.uuid4())
     dark_uid2 = str(uuid.uuid4())
     dark_scan_list.append((dark_uid, 0.3, time_now-2000))
     dark_scan_list.append((dark_uid2, 0.1, time_now-200))
     with open (glbl.dk_yaml, 'w') as f:
         yaml.dump(dark_scan_list, f)
     test_list = _read_dark_yaml()
     self.assertEqual(test_list,dark_scan_list)
     # none with the right exposure
     scanplan = ScanPlan('ct', {'exposure':0.01}, shutter=False)
     prun(self.sa, scanplan)
     self.assertTrue('sc_dk_field_uid' in glbl.xpdRE.call_args_list[-1][1])
     self.assertFalse(glbl.xpdRE.call_args_list[-1][1]['sc_dk_field_uid'] == dark_uid2)
     # Second one has the right exposure time but expires
     glbl.dk_window = 1.
     scanplan = ScanPlan('ct', {'exposure':0.1}, shutter=False)
     prun(self.sa, scanplan)
     self.assertTrue('sc_dk_field_uid' in glbl.xpdRE.call_args_list[-1][1])
     self.assertFalse(glbl.xpdRE.call_args_list[-1][1]['sc_dk_field_uid'] == dark_uid2)
Example #2
0
 def test_dark_in_prun_cannot_find_a_valid_dark(self):
     # case 2: can't find a qualified dark and test if md got updated
     time_now = time.time()
     self.bt.set_wavelength(0.18448)
     # build the dark yml
     dark_scan_list = []
     dark_uid = str(uuid.uuid4())
     dark_uid2 = str(uuid.uuid4())
     dark_scan_list.append((dark_uid, 0.3, time_now - 2000))
     dark_scan_list.append((dark_uid2, 0.1, time_now - 200))
     with open(glbl.dk_yaml, 'w') as f:
         yaml.dump(dark_scan_list, f)
     test_list = _read_dark_yaml()
     self.assertEqual(test_list, dark_scan_list)
     # none with the right exposure
     scanplan = ScanPlan('ct', {'exposure': 0.01}, shutter=False)
     prun(self.sa, scanplan)
     self.assertTrue('sc_dk_field_uid' in glbl.xpdRE.call_args_list[-1][1])
     self.assertFalse(
         glbl.xpdRE.call_args_list[-1][1]['sc_dk_field_uid'] == dark_uid2)
     # Second one has the right exposure time but expires
     glbl.dk_window = 1.
     scanplan = ScanPlan('ct', {'exposure': 0.1}, shutter=False)
     prun(self.sa, scanplan)
     self.assertTrue('sc_dk_field_uid' in glbl.xpdRE.call_args_list[-1][1])
     self.assertFalse(
         glbl.xpdRE.call_args_list[-1][1]['sc_dk_field_uid'] == dark_uid2)
Example #3
0
    def test_prun_with_bleusky_plan(self):
        cc = Count([det], 2)
        self.sp = ScanPlan('bluesky', {'bluesky_plan': cc}, shutter=False)
        self.sc = Scan(self.sa, self.sp)
        self.assertEqual(self.sc.sp, self.sp)
        cfg_f_name = 'srxconfig.cfg'
        cfg_src = os.path.join(os.path.dirname(__file__),
                               cfg_f_name)  # __file__ gives relative path
        cfg_dst = os.path.join(glbl.config_base, cfg_f_name)
        shutil.copy(cfg_src, cfg_dst)
        # sp_params should be id to object
        self.assertEqual(id(cc), self.sp.md['sp_params']['bluesky_plan'])

        # case 1: bluesky plan object exist in current name space
        prun(self.sa, self.sp)
        # is xpdRE used?
        self.assertTrue(glbl.xpdRE.called)
        # is md updated?
        self.assertFalse(glbl.xpdRE.call_args_list[-1][1] == self.sc.md)
        # is prun passed eventually?
        self.assertTrue('sc_isprun' in glbl.xpdRE.call_args_list[-1][1])
        # is auto_dark executed? -> No as we don't support
        self.assertFalse('sc_dk_field_uid' in glbl.xpdRE.call_args_list[-1][1])
        # is calibration loaded?
        self.assertTrue(cfg_f_name in glbl.xpdRE.call_args_list[-1][1]
                        ['sc_calibration_file_name'])
        # is 'blusky_plan' appears in sp_params ?
        self.assertTrue(
            'bluesky_plan' in glbl.xpdRE.call_args_list[-1][1]['sp_params'])
        # is  ScanPlan.md remain unchanged after scan?
        self.assertFalse('sc_isprun' in self.sp.md)

        # case 2: bluesky plan object doesn't exist in current name spaece
        del cc
        self.assertRaises(NameError, lambda: prun(self.sa, self, sp))
Example #4
0
 def test_new_prun_no_auto_dark_but_auto_calibration(self):
     self.sp = ScanPlan('ct', {
         'exposure': 0.1,
         'dk_window': 32767
     },
                        shutter=False)
     self.sc = Scan(self.sa, self.sp)
     self.assertEqual(self.sc.sp, self.sp)
     cfg_f_name = 'srxconfig.cfg'
     cfg_src = os.path.join(os.path.dirname(__file__),
                            cfg_f_name)  # __file__ gives relative path
     cfg_dst = os.path.join(glbl.config_base, cfg_f_name)
     shutil.copy(cfg_src, cfg_dst)
     prun(self.sa, self.sp, auto_dark=False)
     # is xpdRE used?
     self.assertTrue(glbl.xpdRE.called)
     # is md updated?
     self.assertFalse(glbl.xpdRE.call_args_list[-1][1] == self.sc.md)
     # is prun passed eventually?
     self.assertTrue('sc_isprun' in glbl.xpdRE.call_args_list[-1][1])
     # is auto_dark executed? -> No
     self.assertFalse('sc_dk_field_uid' in glbl.xpdRE.call_args_list[-1][1])
     # is calibration loaded?
     self.assertTrue(cfg_f_name in glbl.xpdRE.call_args_list[-1][1]
                     ['sc_calibration_file_name'])
     # is  ScanPlan.md remain unchanged after scan?
     self.assertFalse('sc_isprun' in self.sp.md)
Example #5
0
    def test_dark_in_prun_can_find_a_valid_dark(self):
        # case 1: find a qualified dark and test if md got updated
        time_now = time.time()
        self.bt.set_wavelength(0.18448)
        light_cnt_time = 0.01

        dark_scan_list = []
        dark_uid = str(uuid.uuid4())
        dark_scan_list.append((dark_uid, light_cnt_time, time_now-600))
        with open (glbl.dk_yaml, 'w') as f:
            yaml.dump(dark_scan_list, f)
        test_list = _read_dark_yaml()
        self.assertEqual(test_list,dark_scan_list)
        scanplan = ScanPlan('ctTest', 'ct', {'exposure':light_cnt_time}, shutter=False)
        prun(self.sa, scanplan)
        self.assertEqual(scanplan.md['sp_params']['dk_field_uid'], dark_uid)
Example #6
0
    def test_dark_in_prun_can_find_a_valid_dark(self):
        # case 1: find a qualified dark and test if md got updated
        time_now = time.time()
        self.bt.set_wavelength(0.18448)
        light_cnt_time = 0.01

        dark_scan_list = []
        dark_uid = str(uuid.uuid4())
        dark_scan_list.append((dark_uid, light_cnt_time, time_now - 600))
        with open(glbl.dk_yaml, 'w') as f:
            yaml.dump(dark_scan_list, f)
        test_list = _read_dark_yaml()
        self.assertEqual(test_list, dark_scan_list)
        scanplan = ScanPlan('ct', {'exposure': light_cnt_time}, shutter=False)
        prun(self.sa, scanplan)
        self.assertTrue('sc_dk_field_uid' in glbl.xpdRE.call_args_list[-1][1])
        self.assertTrue(
            glbl.xpdRE.call_args_list[-1][1]['sc_dk_field_uid'] == dark_uid)
Example #7
0
 def test_scan_calss(self):
     self.sp = ScanPlan('unittest_ScanPlan', 'ct', {'exposure':1.0}, shutter = False)
     self.sc = Scan(self.sa, self.sp)
     sp_md_copy = copy.deepcopy(self.sp.md)
     # alternating md in sc and see if md in ScanPlan remains unchanged
     self.sc.md.update({'changes':True})
     self.assertEqual(self.sp.md, sp_md_copy)
     self.assertFalse('changes' in self.sp.md)
     self.assertTrue(self.sc.md['changes'], True)
     # test with prun
     prun(self.sa, self.sp)
     #self.assertTrue('sc_isprun' in self.sc.md) # can't test it as Scan class only lives inside prun
     self.assertFalse('sc_isprun' in self.sp.md)
     # test with dark
     dark(self.sa, self.sp)
     #self.assertTrue('sc_isdark' in self.sc.md)
     self.assertFalse('sc_isdark' in self.sp.md)
     #self.assertTrue('sc_dark_uid' in self.sc.md)
     self.assertFalse('sc_dark_uid' in self.sp.md)
Example #8
0
    def test_dark_in_prun_cannot_find_a_valid_dark(self):
        # case 2: can't find a qualified dark and test if md got updated
        time_now = time.time()
        self.bt.set_wavelength(0.18448)
        # build the dark yml
        dark_scan_list = []
        dark_uid = str(uuid.uuid4())
        dark_uid2 = str(uuid.uuid4())
        dark_scan_list.append((dark_uid, 0.3, time_now-2000))
        dark_scan_list.append((dark_uid2, 0.3, time_now-200))
        with open (glbl.dk_yaml, 'w') as f:
            yaml.dump(dark_scan_list, f)
        test_list = _read_dark_yaml()
        self.assertEqual(test_list,dark_scan_list)

        # none with the right exposure
        scanplan = ScanPlan('ctTest', 'ct', {'exposure':0.01}, shutter=False)
        prun(self.sa, scanplan)
        self.assertNotEqual(scanplan.md['sp_params']['dk_field_uid'], dark_uid)
        # Second one has the right right exposure time
        glbl.dk_window = 1.
        scanplan = ScanPlan('ctTest', 'ct', {'exposure':0.01}, shutter=False)
        prun(self.sa, scanplan)
        self.assertNotEqual(scanplan.md['sp_params']['dk_field_uid'], dark_uid2)