Exemplo n.º 1
0
    def _generate_data_func(plan, ignore=None):
        '''Generates data to be used for testing of suitcase.*.export(..)
        functions

        Parameters
        ----------
        plan : the plan to use to generate the test data

        Returns
        -------
        collector : list
            A list of (name, doc) tuple pairs generated by the run engine.
        ignore : list, optional
            list of the pytest.fixture parameter 'values' to ignore.
        '''
        if ignore is None:
            ignore = []

        # define the output lists and an internal list.
        collector = []
        event_list = []

        # define the collector function depending on the event_type
        if event_type(ignore) == 'event':

            def collect(name, doc):
                collector.append((name, doc))
                if name == 'event':
                    event_list.append(doc)
        elif event_type(ignore) == 'event_page':

            def collect(name, doc):
                if name == 'event':
                    event_list.append(doc)
                elif name == 'stop':
                    collector.append(
                        ('event_page',
                         event_model.pack_event_page(*event_list)))
                    collector.append((name, doc))
                else:
                    collector.append((name, doc))
        elif event_type(ignore) == 'bulk_events':

            def collect(name, doc):
                if name == 'event':
                    event_list.append(doc)
                elif name == 'stop':
                    collector.append(('bulk_events', {'primary': event_list}))
                    collector.append((name, doc))
                else:
                    collector.append((name, doc))
        else:
            raise UnknownEventType('Unknown event_type kwarg passed to '
                                   'suitcase.utils.events_data')

        # collect the documents
        RE.subscribe(collect)
        RE(plan(detector_list(ignore)))

        return collector
Exemplo n.º 2
0
def exp_db(ltdb, tmp_dir, img_size, fresh_RE):
    db2 = ltdb
    reg = db2.reg
    reg.register_handler("NPY_SEQ", NumpySeqHandler)
    RE = fresh_RE
    RE.subscribe(db2.insert)
    bt_uid = str(uuid.uuid4())

    insert_imgs(
        RE,
        reg,
        2,
        img_size,
        tmp_dir,
        bt_safN=0,
        pi_name="chris",
        sample_name="kapton",
        sample_composition="C",
        start_uid1=True,
        bt_uid=bt_uid,
        composition_string="C",
    )
    insert_imgs(
        RE,
        reg,
        2,
        img_size,
        tmp_dir,
        pi_name="tim",
        bt_safN=1,
        sample_name="Au",
        bkgd_sample_name="kapton",
        sample_composition="Au",
        start_uid2=True,
        bt_uid=bt_uid,
        composition_string="Au",
        detector_name="pe2_image",
    )
    insert_imgs(
        RE,
        reg,
        2,
        img_size,
        tmp_dir,
        pi_name="chris",
        bt_safN=2,
        sample_name="Au",
        bkgd_sample_name="kapton",
        sample_composition="Au",
        start_uid3=True,
        bt_uid=bt_uid,
        composition_string="Au",
    )
    yield db2
Exemplo n.º 3
0
def exp_db(ltdb, tmp_dir, img_size, fresh_RE):
    db2 = ltdb
    reg = db2.reg
    reg.register_handler("NPY_SEQ", NumpySeqHandler)
    RE = fresh_RE
    RE.subscribe(db2.insert)
    bt_uid = str(uuid.uuid4())

    insert_imgs(
        RE,
        reg,
        2,
        img_size,
        tmp_dir,
        bt_safN=0,
        pi_name="chris",
        sample_name="kapton",
        sample_composition="C",
        start_uid1=True,
        bt_uid=bt_uid,
        composition_string="C",
    )
    insert_imgs(
        RE,
        reg,
        2,
        img_size,
        tmp_dir,
        pi_name="tim",
        bt_safN=1,
        sample_name="Au",
        bkgd_sample_name="kapton",
        sample_composition="Au",
        start_uid2=True,
        bt_uid=bt_uid,
        composition_string="Au",
        detector_name="pe2_image",
    )
    insert_imgs(
        RE,
        reg,
        2,
        img_size,
        tmp_dir,
        pi_name="chris",
        bt_safN=2,
        sample_name="Au",
        bkgd_sample_name="kapton",
        sample_composition="Au",
        start_uid3=True,
        bt_uid=bt_uid,
        composition_string="Au",
    )
    yield db2
Exemplo n.º 4
0
def exp_db(db, tmp_dir, img_size, RE):
    db2 = db
    reg = db2.reg
    RE.subscribe(db2.insert)
    bt_uid = str(uuid.uuid4)

    insert_imgs(
        RE,
        reg,
        2,
        img_size,
        tmp_dir,
        bt_safN=0,
        pi_name="chris",
        sample_name="kapton",
        sample_composition="C",
        start_uid1=True,
        bt_uid=bt_uid,
        composition_string="Au",
    )
    insert_imgs(
        RE,
        reg,
        2,
        img_size,
        tmp_dir,
        pi_name="tim",
        bt_safN=1,
        sample_name="Au",
        bkgd_sample_name="kapton",
        sample_composition="Au",
        start_uid2=True,
        bt_uid=bt_uid,
        composition_string="Au",
    )
    insert_imgs(
        RE,
        reg,
        2,
        img_size,
        tmp_dir,
        pi_name="chris",
        bt_safN=2,
        sample_name="Au",
        bkgd_sample_name="kapton",
        sample_composition="Au",
        start_uid3=True,
        bt_uid=bt_uid,
        composition_string="Au",
    )
    yield db2
Exemplo n.º 5
0
def exp_db(ltdb, tmp_dir, img_size):
    db2 = ltdb
    RE = RunEngine()
    RE.ignore_callback_exceptions = False
    RE.subscribe(db2.insert)
    bt_uid = str(uuid.uuid4())

    insert_imgs(
        RE,
        2,
        img_size,
        tmp_dir,
        bt_safN=0,
        pi_name="chris",
        sample_name="kapton",
        sample_composition="C",
        start_uid1=True,
        bt_uid=bt_uid,
        composition_string="C",
    )
    insert_imgs(
        RE,
        2,
        img_size,
        tmp_dir,
        pi_name="tim",
        bt_safN=1,
        sample_name="Au",
        bkgd_sample_name="kapton",
        sample_composition="Au",
        start_uid2=True,
        bt_uid=bt_uid,
        composition_string="Au",
        detector_name="pe2_image",
    )
    insert_imgs(
        RE,
        2,
        img_size,
        tmp_dir,
        pi_name="chris",
        bt_safN=2,
        sample_name="Au",
        bkgd_sample_name="kapton",
        sample_composition="Au",
        start_uid3=True,
        bt_uid=bt_uid,
        composition_string="Au",
    )
    yield db2
Exemplo n.º 6
0
def test_export(RE, hw):
    collector = []

    def collect(name, doc):
        collector.append((name, doc))

    RE.subscribe(collect)
    RE(count([hw.det], 5))

    with tempfile.NamedTemporaryFile(mode='w') as f:
        # We don't actually need f itself, just a filepath to template on.
        generate_csv(f)
        filepaths = export(collector, f.name)
        print(filepaths)
Exemplo n.º 7
0
def example_data(hw, detector, RE):  # noqa
    sd = SupplementalData(baseline=[hw.motor])
    RE.preprocessors.append(sd)

    docs = []

    def collect(name, doc):
        docs.append((name, event_model.sanitize_doc(doc)))

    uid, = RE(scan([detector], hw.motor, -1, 1, 20), collect)
    return uid, docs
Exemplo n.º 8
0
def fresh_RE(request):
    return RE(request)
Exemplo n.º 9
0
 def clean_event_loop():
     if RE.state != "idle":
         RE.halt()
     ev = asyncio.Event(loop=loop)
     ev.set()
     loop.run_until_complete(ev.wait())
Exemplo n.º 10
0
    def _generate_data_func(plan, skip_tests_with=None, md=None):
        '''Generates data to be used for testing of suitcase.*.export(..)
        functions

        Parameters
        ----------
        plan : the plan to use to generate the test data

        Returns
        -------
        collector : list
            A list of (name, doc) tuple pairs generated by the run engine.
        skip_tests_with : list, optional
            any test having request.param in this list will be skipped
        md : dict, optional
            metadata to be passed to the RunEngine
        '''
        if skip_tests_with is None:
            skip_tests_with = []
        if md is None:
            md = {}

        # define the output lists and an internal list.
        collector = []
        event_list = []

        # define the collector function depending on the event_type
        if event_type(skip_tests_with) == 'event':

            def collect(name, doc):
                collector.append((name, doc))
                if name == 'event':
                    event_list.append(doc)
        elif event_type(skip_tests_with) == 'event_page':

            def collect(name, doc):
                if name == 'event':
                    event_list.append(doc)
                elif name == 'stop':
                    collector.append(
                        ('event_page',
                         event_model.pack_event_page(*event_list)))
                    collector.append((name, doc))
                else:
                    collector.append((name, doc))
        elif event_type(skip_tests_with) == 'bulk_events':

            def collect(name, doc):
                if name == 'event':
                    event_list.append(doc)
                elif name == 'stop':
                    collector.append(('bulk_events', {'primary': event_list}))
                    collector.append((name, doc))
                else:
                    collector.append((name, doc))
        else:
            raise UnknownEventType('Unknown event_type kwarg passed to '
                                   'suitcase.utils.events_data')

        # collect the documents
        RE.subscribe(collect)
        RE(plan(detector_list(skip_tests_with)), md=md)

        return collector
Exemplo n.º 11
0
 def clean_event_loop():
     if RE.state != "idle":
         RE.halt()
     ev = asyncio.Event(loop=loop)
     ev.set()
     loop.run_until_complete(ev.wait())