Esempio n. 1
0
def test_relative_pseudo(hw, RE, db):
    RE.subscribe(db.insert)
    p = hw.pseudo3x3
    p.set(1, 1, 1)
    base_pos = p.position

    # this triggers the merging code path
    rs, = RE(
        bp.relative_inner_product_scan([p], 5, p.pseudo1, -1, 1, p.pseudo2, -2,
                                       -1))
    tb1 = db[rs].table().drop('time', 1)
    assert p.position == base_pos

    # this triggers this does not
    rs, = RE(
        bp.relative_inner_product_scan([p], 5, p.real1, 1, -1, p.real2, 2, 1))
    tb2 = db[rs].table().drop('time', 1)
    assert p.position == base_pos

    # same columns
    assert set(tb1) == set(tb2)
    # same number of points
    assert len(tb1) == len(tb2)

    def get_hint(c):
        h = c.hints['fields']
        return h[0] if h else c.name

    for c in list(p.pseudo_positioners) + list(p.real_positioners):
        col = get_hint(c)
        print(col)
        assert (tb1[col] == tb2[col]).all()

    assert (tb1[get_hint(p.pseudo1)] == np.linspace(0, 2, 5)).all()
Esempio n. 2
0
def test_reset_wrapper(hw, RE):
    p = hw.pseudo3x3
    m_col = MsgCollector()
    RE.msg_hook = m_col

    RE(bp.relative_inner_product_scan([], 1, p.pseudo1, 0, 1, p.pseudo2, 0, 1))
    expecte_objs = [
        p, None, None, p, None, p, None, None, p, None, None, p, p, None
    ]
    assert len(m_col.msgs) == 14
    assert [m.obj for m in m_col.msgs] == expecte_objs
Esempio n. 3
0
def test_relative_pseudo(hw, RE, db):
    RE.subscribe(db.insert)
    p = hw.pseudo3x3
    p.set(1, 1, 1)
    base_pos = p.position

    # this triggers the merging code path
    rs, = RE(bp.relative_inner_product_scan([p],
                                            5,
                                            p.pseudo1, -1, 1,
                                            p.pseudo2, -2, -1))
    tb1 = db[rs].table().drop('time', 1)
    assert p.position == base_pos

    # this triggers this does not
    rs, = RE(bp.relative_inner_product_scan([p],
                                            5,
                                            p.real1, 1, -1,
                                            p.real2, 2, 1))
    tb2 = db[rs].table().drop('time', 1)
    assert p.position == base_pos

    # same columns
    assert set(tb1) == set(tb2)
    # same number of points
    assert len(tb1) == len(tb2)

    def get_hint(c):
        h = c.hints['fields']
        return h[0] if h else c.name

    for c in list(p.pseudo_positioners) + list(p.real_positioners):
        col = get_hint(c)
        print(col)
        assert (tb1[col] == tb2[col]).all()

    assert (tb1[get_hint(p.pseudo1)] == np.linspace(0, 2, 5)).all()
Esempio n. 4
0
def test_reset_wrapper(hw, RE):
    p = hw.pseudo3x3
    m_col = MsgCollector()
    RE.msg_hook = m_col

    RE(bp.relative_inner_product_scan([], 1,
                                      p.pseudo1, 0, 1,
                                      p.pseudo2, 0, 1))
    expecte_objs = [p, None, None,
                    p, None, p,
                    None, None, p,
                    None, None, p,
                    p, None]
    assert len(m_col.msgs) == 14
    assert [m.obj for m in m_col.msgs] == expecte_objs
Esempio n. 5
0
def test_inner_product_dscan(RE, hw):
    scan = bp.relative_inner_product_scan([hw.det], 3,
                                          hw.motor1, 1, 3,
                                          hw.motor2, 10, 30)
    # Note: motor1 is the first motor specified, and so it is the "slow"
    # axis, matching the numpy convention.
    hw.motor1.set(5)
    hw.motor2.set(8)
    expected_data = [
        {'motor2': 18.0, 'det': 1.0, 'motor1': 6.0},
        {'motor2': 28.0, 'det': 1.0, 'motor1': 7.0},
        {'motor2': 38.0, 'det': 1.0, 'motor1': 8.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. 6
0
def test_inner_product_dscan(RE, hw):
    scan = bp.relative_inner_product_scan([hw.det], 3,
                                          hw.motor1, 1, 3,
                                          hw.motor2, 10, 30)
    # Note: motor1 is the first motor specified, and so it is the "slow"
    # axis, matching the numpy convention.
    hw.motor1.set(5)
    hw.motor2.set(8)
    expected_data = [
        {'motor2': 18.0, 'det': 1.0, 'motor1': 6.0},
        {'motor2': 28.0, 'det': 1.0, 'motor1': 7.0},
        {'motor2': 38.0, 'det': 1.0, 'motor1': 8.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. 7
0
 def _gen(self):
     return relative_inner_product_scan(self.detectors,
                                        self.num,
                                        *self.args,
                                        md=self.md)
Esempio n. 8
0
bec = BestEffortCallback()
RE.subscribe(bec)
RE.subscribe(db.insert)

# move motor to a reproducible location
RE(mov(motor1, 0))
RE(mov(motor2, 0))
RE(
    relative_outer_product_scan([det4], motor1, -1, 0, 10, motor2, -2, 0, 20,
                                True))
RE(outer_product_scan([det4], motor1, -1, 0, 10, motor2, -2, 0, 20, True))

# move motor to a reproducible location
RE(mov(motor1, 0))
RE(mov(motor2, 0))
RE(relative_inner_product_scan([det4], 10, motor1, -1, 0, motor2, -2, 0))
RE(inner_product_scan([det4], 10, motor1, -1, 0, motor2, -2, 0))

# do it manually
from cycler import cycler

mot1_cycl = cycler(motor1, np.linspace(-1, 0, 10))
mot2_cycl = cycler(motor2, np.linspace(-2, 0, 10))

# inner product
inner_hints = {
    'fields': [det4.name],
    'dimensions': [([motor1.name, motor2.name], 'primary')]
}
RE(scan_nd([det4], mot1_cycl + mot2_cycl), hints=inner_hints)
from bluesky.plans import relative_inner_product_scan
from bluesky.callbacks import LiveTable

assert slt_mb2.connected

uids = RE(relative_inner_product_scan([em], 5, slt_mb2.o, 0, 1, slt_mb2.i, 0, 1,
          md={'note': 'demo'}),
         LiveTable([slt_mb2.o, slt_mb2.i, em]))


headers = db[uids]
columns = ['time', 'em_chan22']
name_template = '{scan_id}_{note}.csv'
for h in headers:
    db.get_table(headers)[columns].to_csv(name_template.format(**h.start))


# or, in one line:
# db.get_table(db[uids])[['time', 'em_chan22']].to_csv('your_filename_here.csv')
Esempio n. 10
0
RE.subscribe(db.insert)



# move motor to a reproducible location
RE(mov(motor1, 0))
RE(mov(motor2, 0))
RE(relative_outer_product_scan([det4], motor1, -1, 0, 10, motor2, -2,
                               0, 20, True))
RE(outer_product_scan([det4], motor1, -1, 0, 10, motor2, -2, 0, 20,
                      True))

# move motor to a reproducible location
RE(mov(motor1, 0))
RE(mov(motor2, 0))
RE(relative_inner_product_scan([det4], 10, motor1, -1, 0, motor2, -2,
                               0))
RE(inner_product_scan([det4], 10, motor1, -1, 0, motor2, -2, 0))


# do it manually
from cycler import cycler


mot1_cycl = cycler(motor1, np.linspace(-1, 0, 10))
mot2_cycl = cycler(motor2, np.linspace(-2, 0, 10))


# inner product
inner_hints = {'fields' : [det4.name],
               'dimensions' : [ ([motor1.name, motor2.name],'primary')]}
RE(scan_nd([det4], mot1_cycl+mot2_cycl), hints=inner_hints)
Esempio n. 11
0
from bluesky.plans import relative_inner_product_scan
from bluesky.callbacks import LiveTable

assert slt_mb2.connected

RE(relative_inner_product_scan([em], 5, slt_mb2.o, 0, 1, slt_mb2.i, 0, 1),
   LiveTable([slt_mb2.o, slt_mb2.i, em]))
Esempio n. 12
0
def d2scan(dets, *args, time=None, md=None):
    args, time = _get_a2_args(*args, time=time)
    total_points = int(args[-1])
    yield from _pre_scan(dets, total_points=total_points, count_time=time)
    return (yield from plans.relative_inner_product_scan(dets, *args, md=md,
                                                         per_step=one_nd_step))
Esempio n. 13
0
from bluesky.plans import relative_inner_product_scan
from bluesky.callbacks import LiveTable

assert slt_mb2.connected

uids = RE(
    relative_inner_product_scan([em],
                                5,
                                slt_mb2.o,
                                0,
                                1,
                                slt_mb2.i,
                                0,
                                1,
                                md={'note': 'demo'}),
    LiveTable([slt_mb2.o, slt_mb2.i, em]))

headers = db[uids]
columns = ['time', 'em_chan22']
name_template = '{scan_id}_{note}.csv'
for h in headers:
    db.get_table(headers)[columns].to_csv(name_template.format(**h.start))

# or, in one line:
# db.get_table(db[uids])[['time', 'em_chan22']].to_csv('your_filename_here.csv')