def test_fill_and_multiple_streams(db, RE, tmpdir, hw): from ophyd import sim RE.subscribe(db.insert) detfs1 = sim.SynSignalWithRegistry(name='detfs1', func=lambda: np.ones((5, 5)), reg=db.reg, save_path=str(tmpdir.mkdir('a'))) detfs2 = sim.SynSignalWithRegistry(name='detfs2', func=lambda: np.ones((5, 5)), reg=db.reg, save_path=str(tmpdir.mkdir('b'))) # In each event stream, put one 'fillable' (external-writing) # detector and one simple detector. primary_dets = [detfs1, hw.det1] baseline_dets = [detfs2, hw.det2] uid, = RE( stage_wrapper(baseline_wrapper(count(primary_dets), baseline_dets), baseline_dets)) db.reg.register_handler('NPY_SEQ', sim.NumpySeqHandler) h = db[uid] list(h.documents(stream_name=ALL, fill=False)) list(h.documents(stream_name=ALL, fill=True))
def insert_imgs( RE, reg, n, shape, save_dir, detector_name="pe1_image", **kwargs ): """ Insert images into mds and fs for testing Parameters ---------- RE: bluesky.run_engine.RunEngine instance reg: Registry instance n: int Number of images to take shape: tuple of ints The shape of the resulting images save_dir Returns ------- """ # Create detectors dark_det = sim.SynSignalWithRegistry( name=detector_name, func=lambda: (np.random.random(shape) * 65535).astype("uint16"), reg=reg, save_path=save_dir, ) light_det = sim.SynSignalWithRegistry( name=detector_name, func=lambda: (np.random.random(shape) * 65535).astype("uint16"), reg=reg, save_path=save_dir, ) beamtime_uid = str(uuid4()) base_md = dict( beamtime_uid=beamtime_uid, calibration_md=pyFAI_calib, bt_wavelength=0.1847, folder_tag_list=["sample_name"], **kwargs ) # Insert the dark images dark_md = base_md.copy() dark_md.update(name="test-dark", is_dark=True) dark_uid = RE(count([dark_det], num=1), **dark_md) # Insert the light images light_md = base_md.copy() light_md.update(name="test", sc_dk_field_uid=dark_uid) uid = RE(count([light_det], num=n), **light_md) return uid
def test_export(broker_factory, RE, hw): from ophyd import sim db1 = broker_factory() db2 = broker_factory() RE.subscribe(db1.insert) # test mds only uid, = RE(count([hw.det])) db1.export(db1[uid], db2) assert db2[uid] == db1[uid] assert list(db2.get_events(db2[uid])) == list(db1.get_events(db1[uid])) # test file copying if not hasattr(db1.reg, 'copy_files'): raise pytest.skip("This Registry does not implement copy_files.") dir1 = tempfile.mkdtemp() dir2 = tempfile.mkdtemp() detfs = sim.SynSignalWithRegistry(name='detfs', func=lambda: np.ones((5, 5)), save_path=dir1) uid, = RE(count([detfs])) db1.reg.register_handler('NPY_SEQ', sim.NumpySeqHandler) db2.reg.register_handler('NPY_SEQ', sim.NumpySeqHandler) (from_path, to_path), = db1.export(db1[uid], db2, new_root=dir2) assert os.path.dirname(from_path) == dir1 assert os.path.dirname(to_path) == dir2 assert db2[uid] == db1[uid] image1, = db1.get_images(db1[uid], 'detfs') image2, = db2.get_images(db2[uid], 'detfs')
def test_add_cam(): device = sim.SynSignalWithRegistry(name='yolo') det = add_fake_cam(device) assert hasattr(det, 'images_per_set') assert hasattr(det, 'number_of_sets') assert hasattr(det, 'cam') assert hasattr(det.cam, 'acquire_time') assert hasattr(det.cam, 'acquire')
def insert_imgs(RE, reg, n, shape, save_dir=tempfile.mkdtemp(), **kwargs): """ Insert images into mds and fs for testing Parameters ---------- RE: bluesky.run_engine.RunEngine instance reg: Registry instance n: int Number of images to take shape: tuple of ints The shape of the resulting images save_dir Returns ------- """ # Create detectors dark_det = sim.SynSignalWithRegistry(name='pe1_image', func=lambda: np.random.random(shape), reg=reg) light_det = sim.SynSignalWithRegistry(name='pe1_image', func=lambda: np.random.random(shape), reg=reg) beamtime_uid = str(uuid4()) base_md = dict(beamtime_uid=beamtime_uid, calibration_md=pyFAI_calib, bt_wavelength=0.1847, **kwargs) # Insert the dark images dark_md = base_md.copy() dark_md.update(name='test-dark', is_dark=True) dark_uid = RE(count([dark_det], num=1), **dark_md) # Insert the light images light_md = base_md.copy() light_md.update(name='test', sc_dk_field_uid=dark_uid) uid = RE(count([light_det], num=n), **light_md) return uid
def det_factory(cycle=None, img_gen_func=img_gen, data_key="pe1_image", *args, **kwargs): """Build a simulated detector yielding input image sequence Parameters ---------- cycle: cycler.Cycler, optional The iterable like object to cycle through the images. Default to output images in (2048, 2048) dimension with Gaussian(0, 1) noise. img_gen_func : callable, optional function to return image sequence will be output from this detector. The function signature is expected to be ``f(cycler, *args, **kwargs)``. Default to ``xpdsim.img_gen`` function where simulated shutter and noise can be included. data_key : str, optional data key will be shown in Descriptor. Default to ``'pe1_image'``. args : extra arguments will be passed to ``img_gen_func``. kwargs : extra keyword arguments will be passed to ``img_gen_func``. Returns ------- det: SimulatedPE1C instance The detector See also -------- ``xpdsim.img_gen`` """ det = sim.SynSignalWithRegistry( name=data_key, func=lambda: img_gen_func(cycle, *args, **kwargs), save_path=mkdtemp(prefix="xpdsim"), ) return add_fake_cam(det)
def test_export_size_smoke(broker_factory, RE, tmpdir): from ophyd import sim db1 = broker_factory() RE.subscribe(db1.insert) # test file copying if not hasattr(db1.fs, 'copy_files'): raise pytest.skip("This Registry does not implement copy_files.") detfs = sim.SynSignalWithRegistry(name='detfs', func=lambda: np.ones((5, 5)), save_path=str(tmpdir.mkdir('a'))) uid, = RE(count([detfs])) db1.reg.register_handler('NPY_SEQ', sim.NumpySeqHandler) size = db1.export_size(db1[uid]) assert size > 0.