Esempio n. 1
0
def test_live_grid(RE, hw):
    hw.motor1.delay = 0
    hw.motor2.delay = 0
    RE(grid_scan([hw.det4], hw.motor1, -3, 3, 6, hw.motor2, -5, 5, 10, False),
       LiveGrid((6, 10), 'det4'))

    # Test the deprecated name.
    with pytest.warns(UserWarning):
        RE(
            grid_scan([hw.det4], hw.motor1, -3, 3, 6, hw.motor2, -5, 5, 10,
                      False), LiveRaster((6, 10), 'det4'))
Esempio n. 2
0
def test_live_grid(RE, hw):
    hw.motor1.delay = 0
    hw.motor2.delay = 0
    RE(grid_scan([hw.det4],
                 hw.motor1, -3, 3, 6,
                 hw.motor2, -5, 5, 10, False),
       LiveGrid((6, 10), 'det4'))

    # Test the deprecated name.
    with pytest.warns(UserWarning):
        RE(grid_scan([hw.det4], hw.motor1, -3, 3, 6, hw.motor2,
                     -5, 5, 10, False),
           LiveRaster((6, 10), 'det4'))
Esempio n. 3
0
def test_live_scatter(RE, hw):
    RE(grid_scan([hw.det5],
                 hw.jittery_motor1, -3, 3, 6,
                 hw.jittery_motor2, -5, 5, 10, False),
       LiveScatter('jittery_motor1', 'jittery_motor2', 'det5',
                   xlim=(-3, 3), ylim=(-5, 5)))

    # Test the deprecated name.
    with pytest.warns(UserWarning):
        RE(grid_scan([hw.det5],
                     hw.jittery_motor1, -3, 3, 6,
                     hw.jittery_motor2, -5, 5, 10, False),
           LiveMesh('jittery_motor1', 'jittery_motor2', 'det5',
                    xlim=(-3, 3), ylim=(-5, 5)))
Esempio n. 4
0
def test_live_scatter(RE, hw):
    RE(grid_scan([hw.det5],
                 hw.jittery_motor1, -3, 3, 6,
                 hw.jittery_motor2, -5, 5, 10, False),
       LiveScatter('jittery_motor1', 'jittery_motor2', 'det5',
                   xlim=(-3, 3), ylim=(-5, 5)))

    # Test the deprecated name.
    with pytest.warns(UserWarning):
        RE(grid_scan([hw.det5],
                     hw.jittery_motor1, -3, 3, 6,
                     hw.jittery_motor2, -5, 5, 10, False),
           LiveMesh('jittery_motor1', 'jittery_motor2', 'det5',
                    xlim=(-3, 3), ylim=(-5, 5)))
Esempio n. 5
0
 def make_areascan(dets,
                   slow,
                   startslow,
                   stopslow,
                   nslow,
                   fast,
                   startfast,
                   stopfast,
                   nfast,
                   snake=False):
     BMMuser.final_log_entry = False
     uid = yield from grid_scan(
         dets,
         slow,
         startslow,
         stopslow,
         nslow,
         fast,
         startfast,
         stopfast,
         nfast,
         snake,
         md={
             'plan_name':
             f'grid_scan measurement {slow.name} {fast.name} {detector}'
         })
     BMMuser.final_log_entry = True
     return uid
Esempio n. 6
0
def test_pencil_tomo_pipeline(RE, hw, db):
    L = []
    rr = RunRouter([
        lambda x: tomo_callback_factory(x,
                                        publisher=lambda *x: L.append(x),
                                        handler_reg=db.reg.handler_reg)
    ])
    RE.subscribe(rr)
    RE(
        bp.grid_scan(
            [hw.det1],
            hw.motor1,
            0,
            180,
            30,
            hw.motor2,
            -5,
            5,
            5,
            False,
            md={
                "tomo": {
                    "type": "pencil",
                    "translation": "motor2",
                    "rotation": "motor1",
                    "center": 0.0,
                }
            },
        ))
    # det1
    # sinogram and recon
    assert len(L) == (30 * 5 + 2 + 1 + 2) * 2
Esempio n. 7
0
def test_outer_product_ascan_snaked(RE, hw):
    scan = bp.grid_scan([hw.det], hw.motor1, 1, 3, 3, hw.motor2, 10, 20, 2,
                        True)
    # Note: motor1 is the first motor specified, and so it is the "slow"
    # axis, matching the numpy convention.
    expected_data = [{
        'motor2': 10.0,
        'det': 1.0,
        'motor1': 1.0
    }, {
        'motor2': 20.0,
        'det': 1.0,
        'motor1': 1.0
    }, {
        'motor2': 20.0,
        'det': 1.0,
        'motor1': 2.0
    }, {
        'motor2': 10.0,
        'det': 1.0,
        'motor1': 2.0
    }, {
        'motor2': 10.0,
        'det': 1.0,
        'motor1': 3.0
    }, {
        'motor2': 20.0,
        'det': 1.0,
        'motor1': 3.0
    }]
    for d in expected_data:
        d.update({'motor1_setpoint': d['motor1']})
        d.update({'motor2_setpoint': d['motor2']})
    multi_traj_checker(RE, scan, expected_data)
Esempio n. 8
0
def test_mesh_pseudo(hw, RE):

    p3x3 = hw.pseudo3x3
    sig = hw.sig
    d = DocCollector()

    RE.subscribe(d.insert)
    rs = RE(bp.grid_scan([sig], p3x3.pseudo1, 0, 3, 5, p3x3.pseudo2, 7, 10, 7))

    if RE.call_returns_result:
        uid = rs.run_start_uids[0]
    else:
        uid = rs[0]

    df = pd.DataFrame(
        [_['data'] for _ in d.event[d.descriptor[uid][0]['uid']]])

    for k in p3x3.describe():
        assert k in df

    for k in sig.describe():
        assert k in df

    assert all(df[sig.name] == 0)
    assert all(df[p3x3.pseudo3.name] == 0)
Esempio n. 9
0
def test_live_fit_multidim(RE, hw):

    try:
        import lmfit
    except ImportError:
        raise pytest.skip('requires lmfit')

    hw.motor1.delay = 0
    hw.motor2.delay = 0
    hw.det4.exposure_time = 0

    def gaussian(x, y, A, sigma, x0, y0):
        return A * np.exp(-((x - x0) ** 2 + (y - y0) ** 2) / (2 * sigma ** 2))

    model = lmfit.Model(gaussian, ['x', 'y'])
    init_guess = {'A': 2,
                  'sigma': lmfit.Parameter('sigma', 3, min=0),
                  'x0': -0.2,
                  'y0': 0.3}
    cb = LiveFit(model, 'det4', {'x': 'motor1', 'y': 'motor2'}, init_guess,
                 update_every=50)
    RE(grid_scan([hw.det4],
                 hw.motor1, -1, 1, 10,
                 hw.motor2, -1, 1, 10, False),
       cb)

    expected = {'A': 1, 'sigma': 1, 'x0': 0, 'y0': 0}
    for k, v in expected.items():
        assert np.allclose(cb.result.values[k], v, atol=1e-6)
Esempio n. 10
0
def _test_srw_det_grid_scan(RE, db, tmpdir, sim_type, sim_id, server_name):
    import datetime
    from ophyd.utils import make_dir_tree

    RE.subscribe(db.insert)

    root_dir = '/tmp/data'
    _ = make_dir_tree(datetime.datetime.now().year, base_path=root_dir)

    srw_det = SirepoSRWDetector(name="srw_det",
                                sim_type=sim_type,
                                sim_id=sim_id,
                                sirepo_server=server_name,
                                root_dir=root_dir)
    srw_det.select_optic('Aperture')
    param1 = srw_det.create_parameter('horizontalSize')
    param2 = srw_det.create_parameter('verticalSize')
    srw_det.read_attrs = ['image', 'mean', 'photon_energy']
    srw_det.configuration_attrs = [
        'horizontal_extent', 'vertical_extent', 'shape'
    ]

    RE(bp.grid_scan([srw_det], param1, 0, 1, 3, param2, 0, 1, 3, True))

    db_means = []
    actual_means = [
        0, 0, 0, 1334615738479247.2, 1208898410914477.0, 0, 0,
        1208898410914477.0, 1334615738479247.2
    ]

    hdr = db[-1]
    t = hdr.table()
    for i in range(len(t)):
        db_means.append(t.iloc[i]['srw_det_mean'])
    assert actual_means == db_means, "grid_scan means do not match actual means"
Esempio n. 11
0
def test_plan_header(RE, hw):
    args = []

    ##
    args.append((bp.grid_scan([hw.det],
                              hw.motor, 1, 2, 3,
                              hw.motor1, 4, 5, 6,
                              hw.motor2, 7, 8, 9,
                              snake_axes=True),
                 {'motors': ('motor', 'motor1', 'motor2'),
                  'extents': ([1, 2], [4, 5], [7, 8]),
                  'shape': (3, 6, 9),
                  'snaking': (False, True, True),
                  'plan_pattern_module': 'bluesky.plan_patterns',
                  'plan_pattern': 'outer_product',
                  'plan_name': 'grid_scan'}))

    ##
    args.append((bp.inner_product_scan([hw.det], 9,
                                       hw.motor, 1, 2,
                                       hw.motor1, 4, 5,
                                       hw.motor2, 7, 8),
                {'motors': ('motor', 'motor1', 'motor2')}))

    for plan, target in args:
        c = DocCollector()
        RE(plan, c.insert)
        for s in c.start:
            _validate_start(s, target)
Esempio n. 12
0
def test_plan_header(RE, hw):
    args = []

    ##
    args.append((bp.grid_scan([hw.det],
                              hw.motor, 1, 2, 3,
                              hw.motor1, 4, 5, 6, True,
                              hw.motor2, 7, 8, 9, True),
                 {'motors': ('motor', 'motor1', 'motor2'),
                  'extents': ([1, 2], [4, 5], [7, 8]),
                  'shape': (3, 6, 9),
                  'snaking': (False, True, True),
                  'plan_pattern_module': 'bluesky.plan_patterns',
                  'plan_pattern': 'outer_product',
                  'plan_name': 'grid_scan'}))

    ##
    args.append((bp.inner_product_scan([hw.det], 9,
                                       hw.motor, 1, 2,
                                       hw.motor1, 4, 5,
                                       hw.motor2, 7, 8),
                {'motors': ('motor', 'motor1', 'motor2')}))

    for plan, target in args:
        c = DocCollector()
        RE(plan, c.insert)
        for s in c.start:
            _validate_start(s, target)
Esempio n. 13
0
def test_live_fit_multidim(RE, hw):

    try:
        import lmfit
    except ImportError:
        raise pytest.skip('requires lmfit')

    hw.motor1.delay = 0
    hw.motor2.delay = 0
    hw.det4.exposure_time = 0

    def gaussian(x, y, A, sigma, x0, y0):
        return A * np.exp(-((x - x0)**2 + (y - y0)**2) / (2 * sigma**2))

    model = lmfit.Model(gaussian, ['x', 'y'])
    init_guess = {
        'A': 2,
        'sigma': lmfit.Parameter('sigma', 3, min=0),
        'x0': -0.2,
        'y0': 0.3
    }
    cb = LiveFit(model,
                 'det4', {
                     'x': 'motor1',
                     'y': 'motor2'
                 },
                 init_guess,
                 update_every=50)
    RE(grid_scan([hw.det4], hw.motor1, -1, 1, 10, hw.motor2, -1, 1, 10, False),
       cb)

    expected = {'A': 1, 'sigma': 1, 'x0': 0, 'y0': 0}
    for k, v in expected.items():
        assert np.allclose(cb.result.values[k], v, atol=1e-6)
Esempio n. 14
0
def test_pencil_tomo_pipeline(RE, hw, db):
    L = []
    rr = RunRouter(
        [lambda x: tomo_callback_factory(x, publisher=lambda *x: L.append(x),
                                         handler_reg=db.reg.handler_reg)]
    )
    RE.subscribe(rr)
    RE(
        bp.grid_scan(
            [hw.det1],
            hw.motor1,
            0,
            180,
            30,
            hw.motor2,
            -5,
            5,
            5,
            False,
            md={
                "tomo": {
                    "type": "pencil",
                    "translation": "motor2",
                    "rotation": "motor1",
                    "center": 0.0,
                }
            },
        )
    )
    # det1
    # sinogram and recon
    assert len(L) == (30 * 5 + 2 + 1 +2) * 2
Esempio n. 15
0
    def run_exp(delay):  # pragma: no cover
        time.sleep(delay)
        print("running exp")

        p = Publisher(proxy[0], prefix=b"an")
        RE.subscribe(p)

        RE(
            bp.grid_scan(
                [hw.noisy_det],
                hw.motor3,
                0,
                2,
                2,
                hw.motor1,
                0,
                2,
                2,
                True,
                hw.motor2,
                0,
                2,
                2,
                True,
                md={
                    "tomo": {
                        "type": "pencil",
                        "rotation": "motor1",
                        "translation": "motor2",
                        "stack": "motor3",
                        "center": 1,
                    }
                },
            ))
Esempio n. 16
0
    def run_exp(delay):  # pragma: no cover
        time.sleep(delay)
        print("running exp")

        p = Publisher(proxy[0], prefix=b"an")
        RE.subscribe(p)

        RE(
            bp.grid_scan(
                [hw.noisy_det],
                hw.motor3,
                0,
                2,
                2,
                hw.motor1,
                0,
                2,
                2,
                True,
                hw.motor2,
                0,
                2,
                2,
                True,
                md={
                    "tomo": {
                        "type": "pencil",
                        "rotation": "motor1",
                        "translation": "motor2",
                        "stack": "motor3",
                        "center": 1,
                    }
                },
            )
        )
Esempio n. 17
0
def generate_example_catalog(data_path):
    data_path = Path(data_path)

    def factory(name, doc):
        serializer = Serializer(data_path / 'abc')
        serializer('start', doc)
        return [serializer], []

    RE = RunEngine()
    sd = SupplementalData()
    RE.preprocessors.append(sd)
    sd.baseline.extend([motor1, motor2])
    rr = RunRouter([factory])
    RE.subscribe(rr)
    RE(count([det]))
    RE(count([noisy_det], 5))
    RE(scan([det], motor, -1, 1, 7))
    RE(grid_scan([det4], motor1, -1, 1, 4, motor2, -1, 1, 7, False))
    RE(scan([det], motor, -1, 1, motor2, -1, 1, 5))
    RE(count([noisy_det, det], 5))
    RE(count([random_img], 5))
    RE(count([img], 5))

    def factory(name, doc):
        serializer = Serializer(data_path / 'xyz')
        serializer('start', doc)
        return [serializer], []

    RE = RunEngine()
    rr = RunRouter([factory])
    RE.subscribe(rr)
    RE(count([det], 3))

    catalog_filepath = data_path / 'catalog.yml'
    with open(catalog_filepath, 'w') as file:
        file.write(f'''
sources:
  abc:
    description: Some imaginary beamline
    driver: bluesky-jsonl-catalog
    container: catalog
    args:
      paths: {Path(data_path) / 'abc' / '*.jsonl'}
      handler_registry:
        NPY_SEQ: ophyd.sim.NumpySeqHandler
    metadata:
      beamline: "00-ID"
  xyz:
    description: Some imaginary beamline
    driver: bluesky-jsonl-catalog
    container: catalog
    args:
      paths: {Path(data_path) / 'xyz' / '*.jsonl'}
      handler_registry:
        NPY_SEQ: ophyd.sim.NumpySeqHandler
    metadata:
      beamline: "99-ID"
''')
    return str(catalog_filepath)
Esempio n. 18
0
def test_live_scatter(RE, hw):
    RE(
        grid_scan(
            [hw.det5],
            hw.jittery_motor1,
            -3,
            3,
            6,
            hw.jittery_motor2,
            -5,
            5,
            10,
            False,
        ),
        LiveScatter(
            "jittery_motor1",
            "jittery_motor2",
            "det5",
            xlim=(-3, 3),
            ylim=(-5, 5),
        ),
    )

    # Test the deprecated name.
    with pytest.warns(UserWarning):
        RE(
            grid_scan(
                [hw.det5],
                hw.jittery_motor1,
                -3,
                3,
                6,
                hw.jittery_motor2,
                -5,
                5,
                10,
                False,
            ),
            LiveMesh(
                "jittery_motor1",
                "jittery_motor2",
                "det5",
                xlim=(-3, 3),
                ylim=(-5, 5),
            ),
        )
Esempio n. 19
0
    def _plan(self, p1, p2):
        x1, y1 = p1
        x2, y2 = p2

        return grid_scan(self.dets,
                                  self.motor1, x1, x2, self.num1,
                                  self.motor2, y1, y2, self.num2,
                                  self.snake, md=self.md)
Esempio n. 20
0
def test_live_scatter(RE, hw):
    RE(
        grid_scan(
            [hw.det5],
            hw.jittery_motor1,
            -3,
            3,
            6,
            hw.jittery_motor2,
            -5,
            5,
            10,
            False,
        ),
        LiveScatter(
            "jittery_motor1",
            "jittery_motor2",
            "det5",
            xlim=(-3, 3),
            ylim=(-5, 5),
        ),
    )

    # Test the deprecated name.
    with pytest.warns(UserWarning):
        RE(
            grid_scan(
                [hw.det5],
                hw.jittery_motor1,
                -3,
                3,
                6,
                hw.jittery_motor2,
                -5,
                5,
                10,
                False,
            ),
            LiveMesh(
                "jittery_motor1",
                "jittery_motor2",
                "det5",
                xlim=(-3, 3),
                ylim=(-5, 5),
            ),
        )
Esempio n. 21
0
def test_plotting_hints(RE, hw, db):
    ''' This tests the run and checks that the correct hints are created.
        Hints are mainly created to help the BestEffortCallback in plotting the
        data.
        Use a callback to do the checking.
    '''
    dc = DocCollector()
    RE.subscribe(dc.insert)

    # check that the inner product hints are passed correctly
    hint = {
        'dimensions': [([hw.motor1.name, hw.motor2.name,
                         hw.motor3.name], 'primary')]
    }
    RE(
        inner_product_scan([hw.det], 20, hw.motor1, -1, 1, hw.motor2, -1, 1,
                           hw.motor3, -2, 0))
    assert dc.start[-1]['hints'] == hint

    # check that the outer product (grid_scan) hints are passed correctly
    hint = {
        'dimensions': [(['motor1'], 'primary'), (['motor2'], 'primary'),
                       (['motor3'], 'primary')]
    }
    # grid_scan passes "rectilinear" gridding as well
    # make sure this is also passed
    output_hint = hint.copy()
    output_hint['gridding'] = 'rectilinear'
    RE(
        grid_scan([hw.det], hw.motor1, -1, 1, 2, hw.motor2, -1, 1, 2, True,
                  hw.motor3, -2, 0, 2, True))

    assert dc.start[-1]['hints'] == output_hint

    # check that if gridding is supplied, it's not overwritten by grid_scan
    # check that the outer product (grid_scan) hints are passed correctly
    hint = {
        'dimensions': [(['motor1'], 'primary'), (['motor2'], 'primary'),
                       (['motor3'], 'primary')],
        'gridding':
        'rectilinear'
    }
    RE(
        grid_scan([hw.det], hw.motor1, -1, 1, 2, hw.motor2, -1, 1, 2, True,
                  hw.motor3, -2, 0, 2, True))
    assert dc.start[-1]['hints'] == hint
Esempio n. 22
0
def test_grid_scan():
    trigger_and_read = helper.shutter_wrapper(bps.trigger_and_read,
                                              movers.shctl1, 0, 100, 0)
    one_nd_step = helper.take_reading_wrapper(bps.one_nd_step,
                                              trigger_and_read)
    plan = bp.grid_scan([movers.cs700],
                        movers.cs700,
                        -1,
                        1,
                        3,
                        per_step=one_nd_step)
    sim.summarize_plan(plan)
Esempio n. 23
0
def test_plotting_hints(RE, hw, db):
    ''' This tests the run and checks that the correct hints are created.
        Hints are mainly created to help the BestEffortCallback in plotting the
        data.
        Use a callback to do the checking.
    '''
    dc = DocCollector()
    RE.subscribe(dc.insert)

    # check that the inner product hints are passed correctly
    hint = {'dimensions': [([hw.motor1.name, hw.motor2.name, hw.motor3.name],
                            'primary')]}
    RE(inner_product_scan([hw.det], 20, hw.motor1, -1, 1, hw.motor2, -1, 1,
                          hw.motor3, -2, 0))
    assert dc.start[-1]['hints'] == hint

    # check that the outer product (grid_scan) hints are passed correctly
    hint = {'dimensions': [(['motor1'], 'primary'),
                           (['motor2'], 'primary'),
                           (['motor3'], 'primary')]}
    # grid_scan passes "rectilinear" gridding as well
    # make sure this is also passed
    output_hint = hint.copy()
    output_hint['gridding'] = 'rectilinear'
    RE(grid_scan([hw.det], hw.motor1, -1, 1, 2, hw.motor2, -1, 1, 2,
                 True, hw.motor3, -2, 0, 2, True))

    assert dc.start[-1]['hints'] == output_hint

    # check that if gridding is supplied, it's not overwritten by grid_scan
    # check that the outer product (grid_scan) hints are passed correctly
    hint = {'dimensions': [(['motor1'], 'primary'),
                           (['motor2'], 'primary'),
                           (['motor3'], 'primary')],
            'gridding': 'rectilinear'}
    RE(grid_scan([hw.det], hw.motor1, -1, 1, 2, hw.motor2, -1, 1, 2,
                 True, hw.motor3, -2, 0, 2, True))
    assert dc.start[-1]['hints'] == hint
Esempio n. 24
0
def test_old_module_name(hw):
    det = hw.det
    motor = hw.motor
    motor1 = hw.motor1
    motor2 = hw.motor2
    from bluesky.plan_tools import (print_summary, print_summary_wrapper,
                                    plot_raster_path)
    with pytest.warns(UserWarning):
        print_summary(scan([det], motor, -1, 1, 10))
    with pytest.warns(UserWarning):
        list(print_summary_wrapper(scan([det], motor, -1, 1, 10)))
    with pytest.warns(UserWarning):
        plan = grid_scan([det], motor1, -5, 5, 10, motor2, -7, 7, 15, True)
        plot_raster_path(plan, 'motor1', 'motor2', probe_size=.3)
Esempio n. 25
0
def get_catalog():
    RE = RunEngine()

    directory = tempfile.TemporaryDirectory().name
    for i in range(1, 5):
        with Serializer(directory) as serializer:
            RE(scan([det], motor, -1, 1, 5 * i), serializer)
    with Serializer(directory) as serializer:
        RE(count([random_img], 3), serializer)
    with Serializer(directory) as serializer:
        RE(grid_scan([det4], motor1, -1, 2, 5, motor2, -1, 2, 7), serializer)

    catalog = BlueskyMsgpackCatalog(f"{directory}/*.msgpack")
    return catalog
Esempio n. 26
0
def test_ops_dimension_hints(RE, hw):
    det = hw.det
    motor = hw.motor
    motor1 = hw.motor1
    c = DocCollector()
    RE.subscribe(c.insert)
    RE(bp.grid_scan([det], motor, -1, 1, 7, motor1, 0, 2, 3))

    st = c.start[0]

    assert 'dimensions' in st['hints']

    assert st['hints']['dimensions'] == [(m.hints['fields'], 'primary')
                                         for m in (motor, motor1)]
Esempio n. 27
0
 def make_areascan(dets,
                   slow,
                   startslow,
                   stopslow,
                   nslow,
                   fast,
                   startfast,
                   stopfast,
                   nfast,
                   snake=False):
     BMMuser.final_log_entry = False
     uid = yield from grid_scan(dets, slow, startslow, stopslow, nslow,
                                fast, startfast, stopfast, nfast, snake)
     BMMuser.final_log_entry = True
     return uid
Esempio n. 28
0
    def _plan(self, p1, p2):
        x1, y1 = p1
        x2, y2 = p2

        return grid_scan(self.dets,
                         self.motor1,
                         x1,
                         x2,
                         self.num1,
                         self.motor2,
                         y1,
                         y2,
                         self.num2,
                         self.snake,
                         md=self.md)
def simple_run(RE, db, sim_id, optic):
    sim_id = sim_id
    sirepo_det = sd.SirepoDetector(sim_id=sim_id)
    sirepo_det.select_optic(optic)

    param1 = sirepo_det.create_parameter("horizontalSize")
    param2 = sirepo_det.create_parameter("verticalSize")
    sirepo_det.read_attrs = ["image", "mean", "photon_energy"]
    sirepo_det.configuration_attrs = ["horizontal_extent", "vertical_extent", "shape"]

    RE(bp.grid_scan([sirepo_det], param1, 0, 1, 10, param2, 0, 1, 10, True))
    plt.show()
    hdr = db[-1]
    data = np.array(list(hdr.data("sirepo_det_image")))
    plt.imshow(data[data.shape[0] - 3])
    plt.show()
Esempio n. 30
0
def test_ops_dimension_hints(RE, hw):
    det = hw.det
    motor = hw.motor
    motor1 = hw.motor1
    c = DocCollector()
    RE.subscribe(c.insert)
    rs, = RE(bp.grid_scan([det],
                          motor, -1, 1, 7,
                          motor1, 0, 2, 3, False))

    st = c.start[0]

    assert 'dimensions' in st['hints']

    assert st['hints']['dimensions'] == [
        (m.hints['fields'], 'primary') for m in (motor, motor1)]
Esempio n. 31
0
def xpdacq_grid_scan_with_dark(
        detectors: list,
        *args,
        snake_axes: typing.Union[bool, typing.Iterable[bool], None] = None,
        per_step: typing.Callable = xpdacq_per_step,
        md: typing.Union[dict, None] = None) -> typing.Generator:
    """
    Scan over a mesh; each motor is on an independent trajectory. If there is a change in the position of the
    slow motor, take a dark image.

    Parameters
    ----------
    detectors: list
        list of 'readable' objects
    ``*args``
        patterned like (``motor1, start1, stop1, num1,``
                        ``motor2, start2, stop2, num2,``
                        ``motor3, start3, stop3, num3,`` ...
                        ``motorN, startN, stopN, numN``)

        The first motor is the "slowest", the outer loop. For all motors
        except the first motor, there is a "snake" argument: a boolean
        indicating whether to following snake-like, winding trajectory or a
        simple left-to-right trajectory.
    snake_axes: boolean or iterable, optional
        which axes should be snaked, either ``False`` (do not snake any axes),
        ``True`` (snake all axes) or a list of axes to snake. "Snaking" an axis
        is defined as following snake-like, winding trajectory instead of a
        simple left-to-right trajectory. The elements of the list are motors
        that are listed in `args`. The list must not contain the slowest
        (first) motor, since it can't be snaked.
    per_step: callable, optional
        hook for customizing action of inner loop (messages per step).
        See docstring of `xpdacq_per_step` (the default)
        for details.
    md: dict, optional
        metadata
    """
    if args:
        slow_motor = args[0]
        per_step = slow_dark_wrapper(per_step, slow_motor)
    yield from bp.grid_scan(detectors,
                            *args,
                            snake_axes=snake_axes,
                            per_step=per_step,
                            md=md)
Esempio n. 32
0
def test_outer_product_ascan_snaked(RE, hw):
    scan = bp.grid_scan([hw.det],
                                 hw.motor1, 1, 3, 3,
                                 hw.motor2, 10, 20, 2, True)
    # Note: motor1 is the first motor specified, and so it is the "slow"
    # axis, matching the numpy convention.
    expected_data = [
        {'motor2': 10.0, 'det': 1.0, 'motor1': 1.0},
        {'motor2': 20.0, 'det': 1.0, 'motor1': 1.0},
        {'motor2': 20.0, 'det': 1.0, 'motor1': 2.0},
        {'motor2': 10.0, 'det': 1.0, 'motor1': 2.0},
        {'motor2': 10.0, 'det': 1.0, 'motor1': 3.0},
        {'motor2': 20.0, 'det': 1.0, 'motor1': 3.0}]
    for d in expected_data:
        d.update({'motor1_setpoint': d['motor1']})
        d.update({'motor2_setpoint': d['motor2']})
    multi_traj_checker(RE, scan, expected_data)
Esempio n. 33
0
def test_mesh_pseudo(hw, RE):
    p3x3 = hw.pseudo3x3
    sig = hw.sig
    d = DocCollector()

    RE.subscribe(d.insert)
    rs, = RE(bp.grid_scan([sig], p3x3.pseudo1, 0, 3, 5, p3x3.pseudo2, 7, 10,
                          7))
    df = pd.DataFrame([_['data'] for _ in d.event[d.descriptor[rs][0]['uid']]])

    for k in p3x3.describe():
        assert k in df

    for k in sig.describe():
        assert k in df

    assert all(df[sig.name] == 0)
    assert all(df[p3x3.pseudo3.name] == 0)
Esempio n. 34
0
def test_mesh_pseudo(hw, RE):
    p3x3 = hw.pseudo3x3
    sig = hw.sig
    d = DocCollector()

    RE.subscribe(d.insert)
    rs, = RE(bp.grid_scan([sig],
                          p3x3.pseudo1, 0, 3, 5,
                          p3x3.pseudo2, 7, 10, 7, False))
    df = pd.DataFrame([_['data']
                       for _ in d.event[d.descriptor[rs][0]['uid']]])

    for k in p3x3.describe():
        assert k in df

    for k in sig.describe():
        assert k in df

    assert all(df[sig.name] == 0)
    assert all(df[p3x3.pseudo3.name] == 0)
Esempio n. 35
0
def test_colliding_streams(RE, hw):

    collector = {'primary': [], 'baseline': []}
    descs = {}

    def local_cb(name, doc):
        if name == 'descriptor':
            descs[doc['uid']] = doc['name']
        elif name == 'event':
            collector[descs[doc['descriptor']]].append(doc)

    RE(
        baseline_wrapper(
            grid_scan([hw.motor], hw.motor, -1, 1, 5, hw.motor1, -5, 5, 7,
                      True), [hw.motor, hw.motor1]), local_cb)

    assert len(collector['primary']) == 35
    assert len(collector['baseline']) == 2

    assert list(range(1, 36)) == [e['seq_num'] for e in collector['primary']]
    assert list(range(1, 3)) == [e['seq_num'] for e in collector['baseline']]
Esempio n. 36
0
def test_live_fit_multidim(RE, hw):

    try:
        import lmfit
    except ImportError:
        raise pytest.skip("requires lmfit")

    hw.motor1.delay = 0
    hw.motor2.delay = 0
    hw.det4.exposure_time = 0

    def gaussian(x, y, A, sigma, x0, y0):
        return A * np.exp(-((x - x0)**2 + (y - y0)**2) / (2 * sigma**2))

    model = lmfit.Model(gaussian, ["x", "y"])
    init_guess = {
        "A": 2,
        "sigma": lmfit.Parameter("sigma", 3, min=0),
        "x0": -0.2,
        "y0": 0.3,
    }
    cb = LiveFit(
        model,
        "det4",
        {
            "x": "motor1",
            "y": "motor2"
        },
        init_guess,
        update_every=50,
    )
    RE(
        grid_scan([hw.det4], hw.motor1, -1, 1, 10, hw.motor2, -1, 1, 10,
                  False),
        cb,
    )

    expected = {"A": 1, "sigma": 1, "x0": 0, "y0": 0}
    for k, v in expected.items():
        assert np.allclose(cb.result.values[k], v, atol=1e-6)
Esempio n. 37
0
def test_colliding_streams(RE, hw):

    collector = {'primary': [], 'baseline': []}
    descs = {}

    def local_cb(name, doc):
        if name == 'descriptor':
            descs[doc['uid']] = doc['name']
        elif name == 'event':
            collector[descs[doc['descriptor']]].append(doc)

    RE(baseline_wrapper(grid_scan([hw.motor],
                                  hw.motor, -1, 1, 5,
                                  hw.motor1, -5, 5, 7, True),
                        [hw.motor, hw.motor1]),
       local_cb)

    assert len(collector['primary']) == 35
    assert len(collector['baseline']) == 2

    assert list(range(1, 36)) == [e['seq_num'] for e in collector['primary']]
    assert list(range(1, 3)) == [e['seq_num'] for e in collector['baseline']]
Esempio n. 38
0
def test_live_fit_multidim(RE, hw):

    try:
        import lmfit
    except ImportError:
        raise pytest.skip("requires lmfit")

    hw.motor1.delay = 0
    hw.motor2.delay = 0
    hw.det4.exposure_time = 0

    def gaussian(x, y, A, sigma, x0, y0):
        return A * np.exp(-((x - x0) ** 2 + (y - y0) ** 2) / (2 * sigma ** 2))

    model = lmfit.Model(gaussian, ["x", "y"])
    init_guess = {
        "A": 2,
        "sigma": lmfit.Parameter("sigma", 3, min=0),
        "x0": -0.2,
        "y0": 0.3,
    }
    cb = LiveFit(
        model,
        "det4",
        {"x": "motor1", "y": "motor2"},
        init_guess,
        update_every=50,
    )
    RE(
        grid_scan(
            [hw.det4], hw.motor1, -1, 1, 10, hw.motor2, -1, 1, 10, False
        ),
        cb,
    )

    expected = {"A": 1, "sigma": 1, "x0": 0, "y0": 0}
    for k, v in expected.items():
        assert np.allclose(cb.result.values[k], v, atol=1e-6)
Esempio n. 39
0
res = SimpleToEventStream(pipeline, ('result', ))

merge = AlignEventStreams(res, raw_source)
merge.starsink(bec)

RE.subscribe(lambda *x: raw_source.emit(x))
RE(
    pchain(
        bp.scan([hw.noisy_det], hw.motor, 0, 10, 10),
        bp.grid_scan([hw.ab_det],
                     hw.motor,
                     0,
                     10,
                     10,
                     hw.motor2,
                     0,
                     10,
                     10,
                     True,
                     per_step=one_nd_step),
        bp.spiral([hw.ab_det],
                  hw.motor,
                  hw.motor2,
                  0,
                  0,
                  10,
                  10,
                  1,
                  10,
                  per_step=one_nd_step),
Esempio n. 40
0
 def _gen(self):
     return grid_scan(self.detectors, *self.args, md=self.md)
Esempio n. 41
0
from bluesky.plans import grid_scan
from ophyd.sim import motor1, motor2, det4
dets = [det4]
RE(
    grid_scan(
        dets,
        motor1,
        -1.5,
        1.5,
        3,  # scan motor1 from -1.5 to 1.5 in 3 steps
        motor2,
        -0.1,
        0.1,
        5,
        False))  # scan motor2 from -0.1 to 0.1 in 5 steps
Esempio n. 42
0
mmm.kind = "hinted"
xrun(0,
    bp.grid_scan(
        [xpd_pe1c],
        mmm,
        0,
        2,
        2,
        m,
        0,
        180,
        4,
        True,
        mm,
        200,
        401,
        4,
        True,

        md={
            "tomo": {
                "type": "pencil",
                "rotation": "motor1",
                "translation": "motor2",
                "stack": "motor3",
                "center": rot_center - 200,
            }
        },
    )
)
Esempio n. 43
0
from bluesky import RunEngine
from bluesky.plans import grid_scan
from ophyd.sim import det4, motor1, motor2
from bluesky.callbacks.mpl_plotting import LiveGrid
motor1.delay = 0
motor2.delay = 0
RE = RunEngine({})
RE(grid_scan([det4], motor1, -3, 3, 6, motor2, -5, 5, 10, False),
   LiveGrid((6, 10), 'det4'))
Esempio n. 44
0
def test_plotting_hints(RE, hw, db):
    """ This tests the run and checks that the correct hints are created.
        Hints are mainly created to help the BestEffortCallback in plotting the
        data.
        Use a callback to do the checking.
    """
    dc = DocCollector()
    RE.subscribe(dc.insert)

    # check that the inner product hints are passed correctly
    hint = {
        "dimensions": [([hw.motor1.name, hw.motor2.name,
                         hw.motor3.name], "primary")]
    }
    RE(
        inner_product_scan([hw.det], 20, hw.motor1, -1, 1, hw.motor2, -1, 1,
                           hw.motor3, -2, 0))
    assert dc.start[-1]["hints"] == hint

    # check that the outer product (grid_scan) hints are passed correctly
    hint = {
        "dimensions": [
            (["motor1"], "primary"),
            (["motor2"], "primary"),
            (["motor3"], "primary"),
        ]
    }
    # grid_scan passes "rectilinear" gridding as well
    # make sure this is also passed
    output_hint = hint.copy()
    output_hint["gridding"] = "rectilinear"
    RE(
        grid_scan(
            [hw.det],
            hw.motor1,
            -1,
            1,
            2,
            hw.motor2,
            -1,
            1,
            2,
            True,
            hw.motor3,
            -2,
            0,
            2,
            True,
        ))

    assert dc.start[-1]["hints"] == output_hint

    # check that if gridding is supplied, it's not overwritten by grid_scan
    # check that the outer product (grid_scan) hints are passed correctly
    hint = {
        "dimensions": [
            (["motor1"], "primary"),
            (["motor2"], "primary"),
            (["motor3"], "primary"),
        ],
        "gridding":
        "rectilinear",
    }
    RE(
        grid_scan(
            [hw.det],
            hw.motor1,
            -1,
            1,
            2,
            hw.motor2,
            -1,
            1,
            2,
            True,
            hw.motor3,
            -2,
            0,
            2,
            True,
        ))
    assert dc.start[-1]["hints"] == hint
Esempio n. 45
0
def generate_example_catalog(data_path):
    data_path = Path(data_path)

    def factory(name, doc):
        serializer = Serializer(data_path / 'abc')
        serializer('start', doc)
        return [serializer], []

    RE = RunEngine()
    sd = SupplementalData()
    RE.preprocessors.append(sd)
    sd.baseline.extend([motor1, motor2])
    rr = RunRouter([factory])
    RE.subscribe(rr)
    RE(count([det]))
    RE(count([noisy_det], 5))
    RE(scan([det], motor, -1, 1, 7))
    RE(grid_scan([det4], motor1, -1, 1, 4, motor2, -1, 1, 7, False))
    RE(scan([det], motor, -1, 1, motor2, -1, 1, 5))
    RE(count([noisy_det, det], 5))
    # RE(count([img], 5))

    def factory(name, doc):
        serializer = Serializer(data_path / 'xyz')
        serializer('start', doc)
        return [serializer], []

    RE = RunEngine()
    rr = RunRouter([factory])
    RE.subscribe(rr)
    RE(count([det], 3))

    catalog_filepath = data_path / 'catalog.yml'
    with open(catalog_filepath, 'w') as file:
        file.write(f'''
plugins:
  source:
    - module: intake_bluesky
sources:
  abc:
    description: Some imaginary beamline
    driver: intake_bluesky.jsonl.BlueskyJSONLCatalog
    container: catalog
    args:
      paths: {Path(data_path) / 'abc' / '*.jsonl'}
      handler_registry:
        NPY_SEQ: ophyd.sim.NumpySeqHandler
    metadata:
      beamline: "00-ID"
  xyz:
    description: Some imaginary beamline
    driver: intake_bluesky.jsonl.BlueskyJSONLCatalog
    container: catalog
    args:
      paths: {Path(data_path) / 'xyz' / '*.jsonl'}
      handler_registry:
        NPY_SEQ: ophyd.sim.NumpySeqHandler
    metadata:
      beamline: "99-ID"
''')
    return str(catalog_filepath)
Esempio n. 46
0
def test_simple_grid_scan():
    RE = RunEngine()
    hardware = yaqc_bluesky.Device(39424)
    sensor = yaqc_bluesky.Device(39425)
    RE(grid_scan([sensor], hardware, -10, 10, 15))
Esempio n. 47
0
def test_plotting_hints(RE, hw, db):
    """ This tests the run and checks that the correct hints are created.
        Hints are mainly created to help the BestEffortCallback in plotting the
        data.
        Use a callback to do the checking.
    """
    dc = DocCollector()
    RE.subscribe(dc.insert)

    # check that the inner product hints are passed correctly
    hint = {
        "dimensions": [
            ([hw.motor1.name, hw.motor2.name, hw.motor3.name], "primary")
        ]
    }
    RE(
        inner_product_scan(
            [hw.det], 20, hw.motor1, -1, 1, hw.motor2, -1, 1, hw.motor3, -2, 0
        )
    )
    assert dc.start[-1]["hints"] == hint

    # check that the outer product (grid_scan) hints are passed correctly
    hint = {
        "dimensions": [
            (["motor1"], "primary"),
            (["motor2"], "primary"),
            (["motor3"], "primary"),
        ]
    }
    # grid_scan passes "rectilinear" gridding as well
    # make sure this is also passed
    output_hint = hint.copy()
    output_hint["gridding"] = "rectilinear"
    RE(
        grid_scan(
            [hw.det],
            hw.motor1,
            -1,
            1,
            2,
            hw.motor2,
            -1,
            1,
            2,
            True,
            hw.motor3,
            -2,
            0,
            2,
            True,
        )
    )

    assert dc.start[-1]["hints"] == output_hint

    # check that if gridding is supplied, it's not overwritten by grid_scan
    # check that the outer product (grid_scan) hints are passed correctly
    hint = {
        "dimensions": [
            (["motor1"], "primary"),
            (["motor2"], "primary"),
            (["motor3"], "primary"),
        ],
        "gridding": "rectilinear",
    }
    RE(
        grid_scan(
            [hw.det],
            hw.motor1,
            -1,
            1,
            2,
            hw.motor2,
            -1,
            1,
            2,
            True,
            hw.motor3,
            -2,
            0,
            2,
            True,
        )
    )
    assert dc.start[-1]["hints"] == hint
Esempio n. 48
0
def e_grid_scan(*args, **kwargs):
    return (yield from bp.grid_scan(*args, per_step=one_nd_step_pseudo_shutter, **kwargs))
Esempio n. 49
0
RE.subscribe(lambda *x: raw_source.emit(x))
RE.subscribe(lambda *x: p(*x))
RE.subscribe(lambda *x: time.sleep(.1))
RE.subscribe(lambda *x: time.sleep(1), "stop")

RE(
    pchain(
        bp.scan([hw.noisy_det], hw.motor, 0, 10, 10),
        bp.grid_scan(
            [hw.ab_det],
            hw.motor,
            0,
            5,
            5,
            hw.motor2,
            0,
            5,
            5,
            True,
            per_step=one_nd_step,
        ),
        bp.grid_scan(
            [hw.ab_det],
            hw.motor,
            0,
            10,
            10,
            hw.motor2,
            0,
            10,
Esempio n. 50
0
def test_live_grid(RE, hw):
    bec = BestEffortCallback()
    RE.subscribe(bec)
    RE(grid_scan([hw.det4], hw.motor1, 0, 1, 1, hw.motor2, 0, 1, 2, True))