示例#1
0
 def setUp(self):
     self.base_dir = glbl.base
     self.home_dir = os.path.join(self.base_dir, 'xpdUser')
     self.config_dir = os.path.join(self.base_dir, 'xpdConfig')
     self.PI_name = 'Billinge '
     self.saf_num = 300000  # must be 30000 for proper load of config yaml => don't change
     self.wavelength = 0.1812
     self.experimenters = [('van der Banerjee', 'S0ham', 1),
                           ('Terban ', ' Max', 2)]
     # make xpdUser dir. That is required for simulation
     os.makedirs(self.home_dir, exist_ok=True)
     self.bt = _start_beamtime(self.PI_name, self.saf_num,
                               self.experimenters,
                               wavelength=self.wavelength)
     xlf = '300000_sample.xlsx'
     src = os.path.join(os.path.dirname(__file__), xlf)
     shutil.copyfile(src, os.path.join(glbl.import_dir, xlf))
     import_sample_info(self.saf_num, self.bt)
     self.sp = ScanPlan(self.bt, ct, 5)
     glbl.shutter_control = True
     self.xrun = CustomizedRunEngine(self.bt)
     open_collection('unittest')
     # simulation objects
     glbl.area_det = SimulatedPE1C('pe1c', {'pe1_image': lambda: 5})
     glbl.temp_controller = be.motor
     glbl.shutter = be.Mover('motor', {'motor': lambda x: x}, {'x': 0})
示例#2
0
 def setUp(self):
     self.base_dir = glbl.base
     self.home_dir = os.path.join(self.base_dir, 'xpdUser')
     self.config_dir = os.path.join(self.base_dir, 'xpdConfig')
     self.PI_name = 'Billinge '
     self.saf_num = 300000  # must be 30000 for proper load of config yaml => don't change
     self.wavelength = 0.1812
     self.experimenters = [('van der Banerjee', 'S0ham', 1),
                           ('Terban ', ' Max', 2)]
     # make xpdUser dir. That is required for simulation
     os.makedirs(self.home_dir, exist_ok=True)
     # set simulation objects
     glbl.area_det = SimulatedPE1C('pe1c', {'pe1_image': lambda: 5})
     print("AT SETUP: numbe_of_sets = {}, images_per_set = {}, "
           "acquire_time ={}"
           .format(glbl.area_det.number_of_sets.get(),
                   glbl.area_det.images_per_set.get(),
                   glbl.area_det.cam.acquire_time.get()))
     glbl.temp_controller = cs700
     glbl.shutter = shctl1
     self.bt = _start_beamtime(self.PI_name, self.saf_num,
                               self.experimenters,
                               wavelength=self.wavelength)
     xlf = '300000_sample.xlsx'
     src = os.path.join(os.path.dirname(__file__), xlf)
     shutil.copyfile(src, os.path.join(glbl.import_dir, xlf))
     import_sample_info(self.saf_num, self.bt)
     self.xrun = CustomizedRunEngine(self.bt)
     open_collection('unittest')
示例#3
0
文件: conftest.py 项目: st3107/xpdAcq
def bt(home_dir):
    # start a beamtime
    pi = "Billinge "
    saf_num = 300000
    wavelength = xpd_wavelength
    experimenters = [["van der Banerjee", "S0ham", 1], ["Terban ", " Max", 2]]
    # copying example longterm config file
    os.makedirs(glbl_dict["xpdconfig"], exist_ok=True)
    pytest_dir = rs_fn("xpdacq", "tests/")
    config = "XPD_beamline_config.yml"
    configsrc = os.path.join(pytest_dir, config)
    shutil.copyfile(configsrc, glbl_dict["blconfig_path"])
    assert os.path.isfile(glbl_dict["blconfig_path"])
    bt = _start_beamtime(pi,
                         saf_num,
                         experimenters,
                         wavelength=wavelength,
                         test=True)
    # spreadsheet
    xlf = "300000_sample.xlsx"
    src = os.path.join(pytest_dir, xlf)
    shutil.copyfile(src, os.path.join(glbl_dict["import_dir"], xlf))
    import_sample_info(saf_num, bt)
    yield bt
    # when we are done with the glbl delete the folders.
    shutil.rmtree(glbl_dict["home"])
示例#4
0
 def setUp(self):
     self.base_dir = glbl.base
     self.home_dir = os.path.join(self.base_dir, 'xpdUser')
     self.config_dir = os.path.join(self.base_dir, 'xpdConfig')
     self.PI_name = 'Billinge '
     self.saf_num = 300000  # must be 30000 for proper load of config yaml => don't change
     self.wavelength = 0.1812
     self.experimenters = [('van der Banerjee', 'S0ham', 1),
                           ('Terban ', ' Max', 2)]
     # make xpdUser dir. That is required for simulation
     os.makedirs(self.home_dir, exist_ok=True)
     self.bt = _start_beamtime(self.PI_name,
                               self.saf_num,
                               self.experimenters,
                               wavelength=self.wavelength)
     xlf = '300000_sample.xlsx'
     src = os.path.join(os.path.dirname(__file__), xlf)
     shutil.copyfile(src, os.path.join(glbl.import_dir, xlf))
     import_sample_info(self.saf_num, self.bt)
     self.sp = ScanPlan(self.bt, ct, 5)
     glbl.shutter_control = True
     self.xrun = CustomizedRunEngine(self.bt)
     open_collection('unittest')
     # simulation objects
     glbl.area_det = SimulatedPE1C('pe1c', {'pe1_image': lambda: 5})
     glbl.temp_controller = be.motor
     glbl.shutter = be.Mover('motor', {'motor': lambda x: x}, {'x': 0})
示例#5
0
 def setUp(self):
     self.base_dir = Path(glbl["base"])
     self.home_dir = Path(glbl["home_dir"])
     self.config_dir = Path(glbl["xpdconfig"])
     self.PI_name = "Billinge "
     # must be 30000 for proper load of config yaml => don't change
     self.saf_num = 300000
     self.wavelength = 0.1812
     self.experimenters = [
         ("van der Banerjee", "S0ham", 1),
         ("Terban ", " Max", 2),
     ]
     # make xpdUser dir. That is required for simulation
     if self.home_dir.is_dir():
         shutil.rmtree(self.home_dir)
     self.home_dir.mkdir()
     # set simulation objects
     db = databroker.v1.temp()
     configure_device(
         area_det=pe1c,
         temp_controller=cs700,
         shutter=shctl1,
         db=db,
         filter_bank=fb,
     )
     if self.config_dir.is_dir():
         shutil.rmtree(self.config_dir)
     self.config_dir.mkdir()
     pytest_dir = Path(rs_fn("xpdacq", "tests/"))
     config = "XPD_beamline_config.yml"
     configsrc = pytest_dir.joinpath(config)
     shutil.copyfile(configsrc, glbl["blconfig_path"])
     self.bt = _start_beamtime(
         self.PI_name,
         self.saf_num,
         self.experimenters,
         wavelength=self.wavelength,
         test=True,
     )
     xlf = "300000_sample.xlsx"
     src = os.path.join(os.path.dirname(__file__), xlf)
     shutil.copyfile(src, os.path.join(glbl["import_dir"], xlf))
     import_sample_info(self.saf_num, self.bt)
     self.xrun = CustomizedRunEngine({})
     self.xrun.beamtime = self.bt
     # link mds
     self.xrun.subscribe(db.v1.insert, "all")
     # grad init_exp_hash_uid
     self.init_exp_hash_uid = glbl["exp_hash_uid"]
示例#6
0
    def test_import_sample_info(self):
        # no bt, default argument will fail
        self.assertRaises(FileNotFoundError, lambda: import_sample_info())
        # make bt but no spreadsheet
        self.bt = _start_beamtime(self.PI_name,
                                  self.saf_num,
                                  self.experimenters,
                                  wavelength=self.wavelength)
        # expect FileNotFoundError as no spreadsheet
        self.assertRaises(FileNotFoundError, lambda: import_sample_info())
        # copy spreadsheet
        xlf = '300000_sample.xlsx'
        src = os.path.join(os.path.dirname(__file__), xlf)
        shutil.copyfile(src, os.path.join(glbl.import_dir, xlf))

        # expect to pass with default argument
        import_sample_info()
        # check imported sample metadata
        for sample in self.bt.samples:
            # Sample is a ChainMap with self.maps[1] == bt
            self.assertEqual(sample.maps[1], self.bt)

        # expect to pass with explicit argument
        import_sample_info(300000, self.bt)
        # check imported sample metadata
        for sample in self.bt.samples:
            # Sample is a ChainMap with self.maps[1] == bt
            self.assertEqual(sample.maps[1], self.bt)

        # expect ValueError with inconsistent SAF_num between bt and input
        self.bt['bt_safN'] = 300179
        self.assertTrue(os.path.isfile(os.path.join(glbl.import_dir, xlf)))
        self.assertRaises(ValueError, lambda: import_sample_info(300000))

        # expct TypeError with incorrect beamtime
        self.assertRaises(TypeError, lambda: import_sample_info(bt=set()))