コード例 #1
0
ファイル: test_signal.py プロジェクト: NSLS-II/ophyd
def test_epicssignal_set(motor_pair_signal, put_complete):
    sim_pv = motor_pair_signal
    sim_pv.put_complete = put_complete

    logging.getLogger('ophyd.signal').setLevel(logging.DEBUG)
    logging.getLogger('ophyd.utils.epics_pvs').setLevel(logging.DEBUG)
    print('tolerance=', sim_pv.tolerance)
    assert sim_pv.tolerance is not None

    start_pos = sim_pv.get()

    # move to +0.2 and check the status object
    target = sim_pv.get() + 0.2
    st = sim_pv.set(target, timeout=1, settle_time=0.001)
    wait(st, timeout=5)
    assert st.done
    assert st.success
    print('status 1', st)
    assert abs(target - sim_pv.get()) < 0.05

    # move back to -0.2, forcing a timeout with a low value
    target = sim_pv.get() - 0.2
    st = sim_pv.set(target, timeout=1e-6)
    time.sleep(0.5)
    print('status 2', st)
    assert st.done
    assert not st.success

    # keep the axis in position
    st = sim_pv.set(start_pos)
    wait(st, timeout=5)
コード例 #2
0
ファイル: test_signal.py プロジェクト: bsobhani/ophyd
def test_epicssignal_set(put_complete):
    sim_pv = EpicsSignal(write_pv='XF:31IDA-OP{Tbl-Ax:X1}Mtr.VAL',
                         read_pv='XF:31IDA-OP{Tbl-Ax:X1}Mtr.RBV',
                         put_complete=put_complete)
    sim_pv.wait_for_connection()

    logging.getLogger('ophyd.signal').setLevel(logging.DEBUG)
    logging.getLogger('ophyd.utils.epics_pvs').setLevel(logging.DEBUG)
    print('tolerance=', sim_pv.tolerance)
    assert sim_pv.tolerance is not None

    start_pos = sim_pv.get()

    # move to +0.2 and check the status object
    target = sim_pv.get() + 0.2
    st = sim_pv.set(target, timeout=1, settle_time=0.001)
    wait(st)
    assert st.done
    assert st.success
    print('status 1', st)
    assert abs(target - sim_pv.get()) < 0.05

    # move back to -0.2, forcing a timeout with a low value
    target = sim_pv.get() - 0.2
    st = sim_pv.set(target, timeout=1e-6)
    time.sleep(0.1)
    print('status 2', st)
    assert st.done
    assert not st.success

    # keep the axis in position
    st = sim_pv.set(start_pos)
    wait(st)
コード例 #3
0
ファイル: test_signal.py プロジェクト: danielballan/ophyd
def test_epicssignal_set(put_complete):
    sim_pv = EpicsSignal(write_pv='XF:31IDA-OP{Tbl-Ax:X1}Mtr.VAL',
                         read_pv='XF:31IDA-OP{Tbl-Ax:X1}Mtr.RBV',
                         put_complete=put_complete)
    sim_pv.wait_for_connection()

    logging.getLogger('ophyd.signal').setLevel(logging.DEBUG)
    logging.getLogger('ophyd.utils.epics_pvs').setLevel(logging.DEBUG)
    print('tolerance=', sim_pv.tolerance)
    assert sim_pv.tolerance is not None

    start_pos = sim_pv.get()

    # move to +0.2 and check the status object
    target = sim_pv.get() + 0.2
    st = sim_pv.set(target, timeout=1, settle_time=0.001)
    wait(st, timeout=5)
    assert st.done
    assert st.success
    print('status 1', st)
    assert abs(target - sim_pv.get()) < 0.05

    # move back to -0.2, forcing a timeout with a low value
    target = sim_pv.get() - 0.2
    st = sim_pv.set(target, timeout=1e-6)
    time.sleep(0.1)
    print('status 2', st)
    assert st.done
    assert not st.success

    # keep the axis in position
    st = sim_pv.set(start_pos)
    wait(st, timeout=5)
コード例 #4
0
def test_epics_signal_positioner():
    readback = record_field(motor_recs[0], 'RBV')
    setpoint = record_field(motor_recs[0], 'VAL')
    p = EpicsSignalPositioner(readback,
                              write_pv=setpoint,
                              name='p',
                              egu='egu',
                              tolerance=0.005)
    p.wait_for_connection()
    assert p.connected

    position_callback = Mock()
    started_motion_callback = Mock()
    finished_motion_callback = Mock()
    moved_cb = Mock()
    assert p.egu == 'egu'

    p.subscribe(position_callback, event_type=p.SUB_READBACK)
    p.subscribe(started_motion_callback, event_type=p.SUB_START)
    p.subscribe(finished_motion_callback, event_type=p.SUB_DONE)

    start_pos = p.position
    target_pos = start_pos - 1.5
    p.move(target_pos, wait=True, moved_cb=moved_cb)
    logger.debug(str(p))
    assert not p.moving
    assert abs(p.position - target_pos) <= p.tolerance

    moved_cb.assert_called_with(obj=p)
    position_callback.assert_called_with(obj=p,
                                         value=target_pos,
                                         sub_type=p.SUB_READBACK,
                                         timestamp=mock.ANY)
    started_motion_callback.assert_called_once_with(obj=p,
                                                    sub_type=p.SUB_START,
                                                    timestamp=mock.ANY)
    finished_motion_callback.assert_called_once_with(obj=p,
                                                     sub_type=p.SUB_DONE,
                                                     value=None,
                                                     timestamp=mock.ANY)

    st = p.set(start_pos)

    wait(st)

    assert st.done
    assert st.error == 0
    assert st.elapsed > 0
    assert abs(p.position - start_pos) <= p.tolerance

    repr(p)
    str(p)

    p.stop()

    p.position

    pc = copy(p)
    assert pc.egu == p.egu
    assert pc.limits == p.limits
コード例 #5
0
def test_epicssignal_set(cleanup, motor, put_complete):
    sim_pv = EpicsSignal(write_pv=motor.user_setpoint.pvname,
                         read_pv=motor.user_readback.pvname,
                         put_complete=put_complete)
    cleanup.add(sim_pv)
    sim_pv.wait_for_connection()

    logging.getLogger('ophyd.signal').setLevel(logging.DEBUG)
    logging.getLogger('ophyd.utils.epics_pvs').setLevel(logging.DEBUG)
    print('tolerance=', sim_pv.tolerance)
    assert sim_pv.tolerance is not None

    start_pos = sim_pv.get()

    # move to +0.2 and check the status object
    target = sim_pv.get() + 0.2
    st = sim_pv.set(target, timeout=1, settle_time=0.001)
    wait(st, timeout=5)
    assert st.done
    assert st.success
    print('status 1', st)
    assert abs(target - sim_pv.get()) < 0.05

    # move back to -0.2, forcing a timeout with a low value
    target = sim_pv.get() - 0.2
    st = sim_pv.set(target, timeout=1e-6)
    time.sleep(0.5)
    print('status 2', st)
    assert st.done
    assert not st.success

    # keep the axis in position
    st = sim_pv.set(start_pos)
    wait(st, timeout=5)
コード例 #6
0
def test_synaxis_timestamps():
    from ophyd.status import wait
    import time

    def time_getter(m):
        return {k: v['timestamp']
                for k, v in m.read().items()}

    def tester(m, orig_time):
        new_time = time_getter(m)
        assert orig_time != new_time
        return new_time

    motor = SynAxis(name='motor1')
    motor.delay = .01
    orig_time = time_getter(motor)

    wait(motor.set(3))
    orig_time = tester(motor, orig_time)

    wait(motor.setpoint.set(4))
    orig_time = tester(motor, orig_time)

    motor.setpoint.put(3)
    time.sleep(2*motor.delay)
    orig_time = tester(motor, orig_time)
コード例 #7
0
def test_epicssignal_set(motor_pair_signal, put_complete):
    sim_pv = motor_pair_signal
    sim_pv.put_complete = put_complete

    logging.getLogger('ophyd.signal').setLevel(logging.DEBUG)
    logging.getLogger('ophyd.utils.epics_pvs').setLevel(logging.DEBUG)
    print('tolerance=', sim_pv.tolerance)
    assert sim_pv.tolerance is not None

    start_pos = sim_pv.get()

    # move to +0.2 and check the status object
    target = sim_pv.get() + 0.2
    st = sim_pv.set(target, timeout=1, settle_time=0.001)
    wait(st, timeout=5)
    assert st.done
    assert st.success
    print('status 1', st)
    assert abs(target - sim_pv.get()) < 0.05

    # move back to -0.2, forcing a timeout with a low value
    target = sim_pv.get() - 0.2
    st = sim_pv.set(target, timeout=1e-6)
    time.sleep(0.5)
    print('status 2', st)
    assert st.done
    assert not st.success

    # keep the axis in position
    st = sim_pv.set(start_pos)
    wait(st, timeout=5)
コード例 #8
0
ファイル: test_signal.py プロジェクト: danielballan/ophyd
def test_set_method():
    sig = Signal(name='sig')

    st = sig.set(28)
    wait(st)
    assert st.done
    assert st.success
    assert sig.get() == 28
コード例 #9
0
ファイル: test_signal.py プロジェクト: bsobhani/ophyd
def test_set_method():
    sig = Signal(name='sig')

    st = sig.set(28)
    wait(st)
    assert st.done
    assert st.success
    assert sig.get() == 28
コード例 #10
0
    def stage(self):

        # Customize what is done before every scan (and undone at the end)
        # self.stage_sigs[self.trans_diode] = 5
        # or just use pyepics directly if you need to
        ret = super().stage()
        self.initi_trigger.put(1, wait=True)
        wait(self.trigger())
        return ret
コード例 #11
0
def test_epics_signal_positioner():
    readback = record_field(motor_recs[0], 'RBV')
    setpoint = record_field(motor_recs[0], 'VAL')
    p = EpicsSignalPositioner(readback, write_pv=setpoint, name='p', egu='egu',
                              tolerance=0.005)
    p.wait_for_connection()
    assert p.connected

    position_callback = Mock()
    started_motion_callback = Mock()
    finished_motion_callback = Mock()
    moved_cb = Mock()
    assert p.egu == 'egu'

    p.subscribe(position_callback, event_type=p.SUB_READBACK)
    p.subscribe(started_motion_callback, event_type=p.SUB_START)
    p.subscribe(finished_motion_callback, event_type=p.SUB_DONE)

    start_pos = p.position
    target_pos = start_pos - 1.5
    p.move(target_pos, wait=True, moved_cb=moved_cb)
    logger.debug(str(p))
    assert not p.moving
    assert abs(p.position - target_pos) <= p.tolerance

    moved_cb.assert_called_with(obj=p)
    position_callback.assert_called_with(
        obj=p, value=target_pos, sub_type=p.SUB_READBACK, timestamp=mock.ANY)
    started_motion_callback.assert_called_once_with(
        obj=p, sub_type=p.SUB_START, timestamp=mock.ANY)
    finished_motion_callback.assert_called_once_with(
        obj=p, sub_type=p.SUB_DONE, value=None, timestamp=mock.ANY)

    st = p.set(start_pos)

    wait(st)

    assert st.done
    assert st.error == 0
    assert st.elapsed > 0
    assert abs(p.position - start_pos) <= p.tolerance

    repr(p)
    str(p)

    p.stop()

    p.position

    pc = copy(p)
    assert pc.egu == p.egu
    assert pc.limits == p.limits
コード例 #12
0
ファイル: test_flyers.py プロジェクト: stuartcampbell/ophyd
def test_ad_time_series(ts_sim_detector, tscollector):
    sim_detector = ts_sim_detector

    num_points = 3

    cam = sim_detector.cam
    cam.stage_sigs[cam.acquire_time] = 0.001
    cam.stage_sigs[cam.acquire_period] = 0.001
    cam.stage_sigs[cam.image_mode] = 'Single'
    cam.stage_sigs[cam.trigger_mode] = 'Internal'

    print('tscollector desc', tscollector.describe())
    print('tscollector flyer desc', tscollector.describe_collect())
    print('tscollector repr', repr(tscollector))
    print('simdet stage sigs', sim_detector.stage_sigs)
    print('tscoll stage sigs', tscollector.stage_sigs)
    print('cam stage sigs', cam.stage_sigs)
    print('stats stage sigs', sim_detector.stats.stage_sigs)

    st = tscollector.complete()
    wait(st)

    tscollector.stage_sigs[tscollector.num_points] = num_points

    sim_detector.stage()
    tscollector.kickoff()

    for i in range(num_points):
        st = sim_detector.trigger()
        wait(st)
        print(st)
        time.sleep(0.1)

    tscollector.pause()
    tscollector.resume()

    collected = list(tscollector.collect())
    print('collected', collected)
    sim_detector.unstage()
    assert len(collected) == num_points
コード例 #13
0
ファイル: test_flyers.py プロジェクト: NSLS-II/ophyd
def test_ad_time_series(ts_sim_detector, tscollector):
    sim_detector = ts_sim_detector

    num_points = 3

    cam = sim_detector.cam
    cam.stage_sigs[cam.acquire_time] = 0.001
    cam.stage_sigs[cam.acquire_period] = 0.001
    cam.stage_sigs[cam.image_mode] = 'Single'
    cam.stage_sigs[cam.trigger_mode] = 'Internal'

    print('tscollector desc', tscollector.describe())
    print('tscollector flyer desc', tscollector.describe_collect())
    print('tscollector repr', repr(tscollector))
    print('simdet stage sigs', sim_detector.stage_sigs)
    print('tscoll stage sigs', tscollector.stage_sigs)
    print('cam stage sigs', cam.stage_sigs)
    print('stats stage sigs', sim_detector.stats.stage_sigs)

    try:
        # In case the collector is currently running...
        wait(tscollector.complete())
    except RuntimeError:
        ...

    tscollector.stage_sigs[tscollector.num_points] = num_points

    sim_detector.stage()
    tscollector.kickoff()

    for i in range(num_points):
        st = sim_detector.trigger()
        wait(st)
        print(st)
        time.sleep(0.1)

    tscollector.pause()
    tscollector.resume()

    st = tscollector.complete()
    wait(st)

    collected = list(tscollector.collect())
    print('collected', collected)
    sim_detector.unstage()
    assert len(collected) == num_points
コード例 #14
0
ファイル: test_ophydobj.py プロジェクト: NSLS-II/ophyd
def test_status_wait():
    st = StatusBase()
    st._finished()
    wait(st)
コード例 #15
0
def test_monitor_flyer(pivot):
    class BasicDevice(Device):
        mtr1 = Cpt(EpicsMotor, 'XF:31IDA-OP{Tbl-Ax:X2}Mtr')
        mtr2 = Cpt(EpicsMotor, 'XF:31IDA-OP{Tbl-Ax:X3}Mtr')

    class FlyerDevice(MonitorFlyerMixin, BasicDevice):
        pass

    fdev = FlyerDevice('',
                       name='fdev',
                       stream_names={'mtr1.user_readback': 'oranges'},
                       pivot=pivot)
    fdev.wait_for_connection()

    fdev.monitor_attrs = ['mtr1.user_readback', 'mtr2.user_readback']
    fdev.describe()

    st = fdev.kickoff()
    wait(st)

    mtr1, mtr2 = fdev.mtr1, fdev.mtr2
    rbv1, rbv2 = mtr1.position, mtr2.position
    fdev.mtr1.move(rbv1 + 0.2, wait=True)
    fdev.mtr2.move(rbv2 + 0.2, wait=True)

    fdev.pause()

    fdev.mtr1.move(rbv1 - 0.2, wait=True)
    fdev.mtr2.move(rbv2 - 0.2, wait=True)

    fdev.resume()
    st = fdev.complete()
    wait(st)

    print(fdev.describe_collect())

    desc1 = fdev.mtr1.user_readback.describe()
    desc2 = fdev.mtr2.user_readback.describe()

    if not pivot:
        desc1[fdev.mtr1.user_readback.name]['dtype'] = 'array'
        desc2[fdev.mtr2.user_readback.name]['dtype'] = 'array'

    assert (fdev.describe_collect() == {
        'oranges': desc1,
        'fdev_mtr2': desc2,
    })
    data = list(fdev.collect())
    print('collected data', data)
    # data from both motors

    if not pivot:
        assert len(data) == 2
        d1 = data[0]['data']['fdev_mtr1']
        d2 = data[1]['data']['fdev_mtr2']

    else:
        assert len(data) >= 2

        d1 = [d['data']['fdev_mtr1'] for d in data if 'fdev_mtr1' in d['data']]
        d2 = [d['data']['fdev_mtr2'] for d in data if 'fdev_mtr2' in d['data']]

    # and at least more than one data point...
    assert len(d1) > 1
    assert len(d2) > 1

    print('data1', d1)
    print('data2', d2)
コード例 #16
0
ファイル: test_ophydobj.py プロジェクト: NSLS-II/ophyd
def test_status_wait_timeout():
    st = StatusBase()

    with pytest.raises(TimeoutError):
        wait(st, timeout=0.05)
コード例 #17
0
ファイル: test_ophydobj.py プロジェクト: dchabot/ophyd
 def test_wait(self):
     st = StatusBase()
     st._finished()
     wait(st)
コード例 #18
0
ファイル: test_ophydobj.py プロジェクト: klauer/ophyd
 def test_wait(self):
     st = StatusBase()
     st._finished()
     wait(st)
コード例 #19
0
ファイル: test_flyers.py プロジェクト: NSLS-II/ophyd
def test_monitor_flyer(pivot):
    class BasicDevice(Device):
        mtr1 = Cpt(EpicsMotor, 'XF:31IDA-OP{Tbl-Ax:X2}Mtr')
        mtr2 = Cpt(EpicsMotor, 'XF:31IDA-OP{Tbl-Ax:X3}Mtr')

    class FlyerDevice(MonitorFlyerMixin, BasicDevice):
        pass

    fdev = FlyerDevice('', name='fdev', stream_names={'mtr1.user_readback': 'oranges'},
                       pivot=pivot)
    fdev.wait_for_connection()

    fdev.monitor_attrs = ['mtr1.user_readback', 'mtr2.user_readback']
    fdev.describe()

    st = fdev.kickoff()
    wait(st)

    mtr1, mtr2 = fdev.mtr1, fdev.mtr2
    rbv1, rbv2 = mtr1.position, mtr2.position
    fdev.mtr1.move(rbv1 + 0.2, wait=True)
    fdev.mtr2.move(rbv2 + 0.2, wait=True)

    fdev.pause()

    fdev.mtr1.move(rbv1 - 0.2, wait=True)
    fdev.mtr2.move(rbv2 - 0.2, wait=True)

    fdev.resume()
    st = fdev.complete()
    wait(st)

    print(fdev.describe_collect())

    desc1 = fdev.mtr1.user_readback.describe()
    desc2 = fdev.mtr2.user_readback.describe()

    if not pivot:
        desc1[fdev.mtr1.user_readback.name]['dtype'] = 'array'
        desc2[fdev.mtr2.user_readback.name]['dtype'] = 'array'

    assert (fdev.describe_collect() ==
            {'oranges': desc1,
             'fdev_mtr2': desc2,
             }
            )
    data = list(fdev.collect())
    print('collected data', data)
    # data from both motors

    if not pivot:
        assert len(data) == 2
        d1 = data[0]['data']['fdev_mtr1']
        d2 = data[1]['data']['fdev_mtr2']

    else:
        assert len(data) >= 2

        d1 = [d['data']['fdev_mtr1'] for d in data
              if 'fdev_mtr1' in d['data']]
        d2 = [d['data']['fdev_mtr2'] for d in data
              if 'fdev_mtr2' in d['data']]

    # and at least more than one data point...
    assert len(d1) > 1
    assert len(d2) > 1

    print('data1', d1)
    print('data2', d2)
コード例 #20
0
ファイル: test_ophydobj.py プロジェクト: CJ-Wright/ophyd
def test_status_wait_timeout():
    st = StatusBase()

    with pytest.raises(TimeoutError):
        wait(st, timeout=0.05)
コード例 #21
0
ファイル: test_ophydobj.py プロジェクト: CJ-Wright/ophyd
def test_wait_status_failed():
    st = StatusBase(timeout=0.05)
    with pytest.raises(RuntimeError):
        wait(st)
コード例 #22
0
ファイル: test_ophydobj.py プロジェクト: CJ-Wright/ophyd
def test_status_wait():
    st = StatusBase()
    st._finished()
    wait(st)
コード例 #23
0
ファイル: test_ophydobj.py プロジェクト: NSLS-II/ophyd
def test_wait_status_failed():
    st = StatusBase(timeout=0.05)
    with pytest.raises(RuntimeError):
        wait(st)