Ejemplo n.º 1
0
def test_pre_suspend_plan(RE, pre_plan, post_plan, expected_list, hw):
    sig = hw.bool_sig
    scan = [Msg('checkpoint'), Msg('sleep', None, .2)]
    msg_lst = []
    sig.put(0)

    def accum(msg):
        msg_lst.append(msg)

    susp = SuspendBoolHigh(sig, pre_plan=pre_plan, post_plan=post_plan)

    RE.install_suspender(susp)
    RE._loop.call_later(.1, sig.put, 1)
    RE._loop.call_later(1, sig.put, 0)
    RE.msg_hook = accum
    RE(scan)

    assert len(msg_lst) == len(expected_list)
    assert expected_list == [m[0] for m in msg_lst]

    RE.remove_suspender(susp)
    RE(scan)
    assert susp.RE is None

    RE.install_suspender(susp)
    RE.clear_suspenders()
    assert susp.RE is None
    assert not RE.suspenders
Ejemplo n.º 2
0
def test_suspender_plans(RE, hw):
    'Tests that the suspenders can be installed via Msg'
    loop = RE._loop
    sig = hw.bool_sig
    my_suspender = SuspendBoolHigh(sig, sleep=0.2)

    def putter(val):
        sig.put(val)

    putter(0)

    # Do the messages work?
    RE([Msg('install_suspender', None, my_suspender)])
    assert my_suspender in RE.suspenders
    RE([Msg('remove_suspender', None, my_suspender)])
    assert my_suspender not in RE.suspenders

    # Can we call both in a plan?
    RE([
        Msg('install_suspender', None, my_suspender),
        Msg('remove_suspender', None, my_suspender)
    ])

    scan = [Msg('checkpoint'), Msg('sleep', None, .2)]

    # No suspend scan: does the wrapper error out?
    start = ttime.time()
    RE(suspend_wrapper(scan, my_suspender))
    stop = ttime.time()
    delta = stop - start
    assert delta < .9

    # Suspend scan
    start = ttime.time()
    threading.Timer(.1, putter, (1, )).start()
    threading.Timer(.5, putter, (0, )).start()
    RE(suspend_wrapper(scan, my_suspender))
    stop = ttime.time()
    delta = stop - start
    assert delta > .9

    # Did we clean up?
    start = ttime.time()
    threading.Timer(.1, putter, (1, )).start()
    threading.Timer(.5, putter, (0, )).start()
    RE(scan)
    stop = ttime.time()
    delta = stop - start
    assert delta < .9
Ejemplo n.º 3
0
def test_pretripped(RE, hw):
    'Tests if suspender is tripped before __call__'
    sig = hw.bool_sig
    scan = [Msg('checkpoint')]
    msg_lst = []
    sig.put(1)

    def accum(msg):
        msg_lst.append(msg)

    susp = SuspendBoolHigh(sig)

    RE.install_suspender(susp)
    RE._loop.call_later(1, sig.put, 0)
    RE.msg_hook = accum
    RE(scan)

    assert len(msg_lst) == 2
    assert ['wait_for', 'checkpoint'] == [m[0] for m in msg_lst]
Ejemplo n.º 4
0
def test_pause_from_suspend(RE, hw):
    'Tests what happens when a pause is requested from a suspended state'
    sig = hw.bool_sig
    scan = [Msg('checkpoint')]
    msg_lst = []
    sig.put(1)

    def accum(msg):
        msg_lst.append(msg)

    susp = SuspendBoolHigh(sig)

    RE.install_suspender(susp)
    RE._loop.call_later(1, RE.request_pause)
    RE._loop.call_later(2, sig.put, 0)
    RE.msg_hook = accum
    with pytest.raises(RunEngineInterrupted):
        RE(scan)
    assert [m[0] for m in msg_lst] == ['wait_for']
    RE.resume()
    assert ['wait_for', 'wait_for', 'checkpoint'] == [m[0] for m in msg_lst]
Ejemplo n.º 5
0
def test_pause_from_suspend(fresh_RE):
    'Tests what happens when a pause is requested from a suspended state'
    RE = fresh_RE
    sig = ophyd.Signal()
    scan = [Msg('checkpoint')]
    msg_lst = []
    sig.put(1)

    def accum(msg):
        msg_lst.append(msg)

    susp = SuspendBoolHigh(sig)

    RE.install_suspender(susp)
    RE._loop.call_later(1, RE.request_pause)
    RE._loop.call_later(2, sig.put, 0)
    RE.msg_hook = accum
    RE(scan)
    assert [m[0] for m in msg_lst] == ['wait_for']
    RE.resume()
    assert ['wait_for', 'wait_for', 'checkpoint'] == [m[0] for m in msg_lst]
Ejemplo n.º 6
0
def test_deferred_pause_from_suspend(RE, hw):
    'Tests what happens when a soft pause is requested from a suspended state'
    sig = hw.bool_sig
    scan = [Msg('checkpoint'), Msg('null')]
    msg_lst = []
    sig.put(1)

    def accum(msg):
        print(msg)
        msg_lst.append(msg)

    susp = SuspendBoolHigh(sig)

    RE.install_suspender(susp)
    threading.Timer(1, RE.request_pause, (True, )).start()
    threading.Timer(4, sig.put, (0, )).start()
    RE.msg_hook = accum
    with pytest.raises(RunEngineInterrupted):
        RE(scan)
    assert [m[0] for m in msg_lst] == ['wait_for', 'checkpoint']
    RE.resume()
    assert ['wait_for', 'checkpoint', 'null'] == [m[0] for m in msg_lst]
Ejemplo n.º 7
0
from ophyd import EpicsSignal
from bluesky.suspenders import SuspendBoolHigh

fast_shutter = EpicsSignal('XF:28IDC-ES:1{Sh:Exp}Sw:Cls1-Sts')
shutter_sus = SuspendBoolHigh(fast_shutter, sleep=3)
# RE.install_suspender(shutter_sus)
Ejemplo n.º 8
0

# Here are some conditions that will cause scans to pause automatically:
# - when the beam current goes below a certain threshold
susp_current = SuspendFloor(beamline_status.beam_current,
                            suspend_thresh=150.0,
                            resume_thresh=240.0,
                            tripped_message='beam current too low',
                            )

# - when the shutter is closed
susp_shutter = SuspendBoolLow(beamline_status.shutter_status,
                              tripped_message='shutter not open',
                              )

# - if the beamline isn't enabled
susp_enabled = SuspendBoolLow(beamline_status.beamline_enabled,
                              tripped_message='beamline is not enabled',
                              )

susp_cryo_cooler = SuspendBoolHigh(beamline_status.cryo_filling,
                                   sleep=60*10,
                                   tripped_message='Cyrocooler is refilling')

# NOTE: to enable or disable the suspenders, (un)comment the following:
# Install all suspenders:
#RE.install_suspender(susp_current)
#RE.install_suspender(susp_shutter)
#RE.install_suspender(susp_enabled)
#RE.install_suspender(susp_cryo_cooler)
Ejemplo n.º 9
0
#new figure feature
import os
import json
import bluesky.plans as bp
import bluesky.plan_stubs as bps
import bluesky.preprocessors as bpp
from bluesky.suspenders import SuspendBoolHigh
import uuid
from cycler import cycler
import pandas as pd


# Add suspender for shutter
# Note: to clear suspenders use RE.clear_suspenders()
suspend_fe_shutter = SuspendBoolHigh(EpicsSignalRO('XF:23ID-PPS{Sh:FE}Pos-Sts'))
RE.install_suspender(suspend_fe_shutter)

suspend_ds_shutter = SuspendBoolHigh(EpicsSignalRO('XF:23ID2-PPS{PSh}Pos-Sts'))
RE.install_suspender(suspend_ds_shutter)


def relabel_fig(fig, new_label):
    fig.set_label(new_label)
    fig.canvas.manager.set_window_title(fig.get_label())

# NOTE : This now requires DETS as a list
def multi_part_ascan(DETS, motor1, steps, motor2, asc_p):
    for d in steps:
        yield from bps.abs_set(motor1, d, wait=True)
        yield from bp.scan(DETS, motor2, *asc_p)
Ejemplo n.º 10
0
print(__file__)
from bluesky.suspenders import (SuspendBoolHigh, SuspendBoolLow, SuspendFloor,
                                SuspendCeil, SuspendInBand, SuspendOutBand)

fe_shut_suspender = SuspendBoolHigh(EpicsSignalRO(shutter_fe.status.pvname),
                                    sleep=10 * 60)
ph_shut_suspender = SuspendBoolHigh(EpicsSignalRO(shutter_ph.status.pvname),
                                    sleep=10 * 60)

# suspender for beamline current is mA
beam_current_suspender = SuspendFloor(nsls_ii.beam_current,
                                      suspend_thresh=300,
                                      sleep=10 * 60)
suspenders = [
    fe_shut_suspender,
    ph_shut_suspender,
    beam_current_suspender,
]
''' Some help on suspenders /bluesky
# how to add a suspender:
# Method 1:
# RE.install_suspender(fe_shut_suspender)
# Method 2 (in the plan):
# RE(bpp.suspend_wrapper(myplan(), [suspenders]))




# general bluesky info
# blue sky plans (mostly) reside here:
# general plans
Ejemplo n.º 11
0
    all_BMM_suspenders.append(suspender_bmps)
except:
    pass

## ----------------------------------------------------------------------------------
## suspend if the main photon shutter closes, resume 5 seconds after opening
try:
    suspender_sha = SuspendBoolLow(user_ns['idps'].state, sleep=60)
    all_BMM_suspenders.append(suspender_sha)
except:
    pass

## ----------------------------------------------------------------------------------
## suspend if the experimental photon shutter closes, resume 5 seconds after opening
try:
    suspender_shb = SuspendBoolHigh(user_ns['shb'].state, sleep=5)
    all_BMM_suspenders.append(suspender_shb)
except:
    pass


def BMM_suspenders():
    BMMuser = user_ns['BMMuser']
    if BMMuser.suspenders_engaged:
        return
    for s in all_BMM_suspenders:
        user_ns['RE'].install_suspender(s)
    BMMuser.suspenders_engaged = True


def BMM_clear_suspenders():
from bluesky.suspenders import SuspendFloor, SuspendBoolHigh

ring_suspender = SuspendFloor(ring_curr, 190, resume_thresh=200,
                              sleep=120)  #, post_plan=beamline_align_v2)

shutterb_suspender = SuspendBoolHigh(EpicsSignalRO(shutterb.status.pvname),
                                     sleep=10 *
                                     60)  #post_plan=beamline_align_v2)

# Is this the right PV???
fe_shut_suspender = SuspendBoolHigh(EpicsSignal('XF:02ID-PPS{Sh:FE}Pos-Sts'),
                                    sleep=10 * 60)
#fe_shut_suspender = SuspendBoolHigh(EpicsSignal('XF:02ID-PPS{Sh:FE}Pos-Sts'), sleep=10*60)

## It needs:
## RE.install_suspender(test_shutsusp)
## RE.remove_suspender(test_shutsusp)

RE.install_suspender(ring_suspender)
RE.install_suspender(fe_shut_suspender)
RE.install_suspender(shutterb_suspender)

print("")
print(
    "You can safely ignore the 'SuspendOutBand' warning - this is a known issue that is fixed in a newer version."
)
Ejemplo n.º 13
0
susp_rc = SuspendFloor(ring_current,
                       140,
                       resume_thresh=160,
                       sleep=10 * 60,
                       pre_plan=list(shuttergenerator(shut_b, 'Close')),
                       post_plan=list(shuttergenerator(shut_b, 'Open')))

# Cryo cooler suspender
susp_cryo = SuspendCeil(cryo_v19,
                        0.8,
                        resume_thresh=0.2,
                        sleep=15 * 60,
                        pre_plan=list(shuttergenerator(shut_b, 'Close')),
                        post_plan=list(shuttergenerator(shut_b, 'Open')))

# Shutter status suspender
susp_shut_fe = SuspendBoolHigh(EpicsSignalRO(shut_fe.status.pvname), sleep=10)
susp_shut_a = SuspendBoolHigh(EpicsSignalRO(shut_a.status.pvname), sleep=10)
susp_shut_b = SuspendBoolHigh(EpicsSignalRO(shut_b.status.pvname), sleep=10)

# HDCM bragg temperature suspender
susp_dcm_bragg_temp = SuspendCeil(dcm.temp_pitch,
                                  120,
                                  resume_thresh=118,
                                  sleep=1)

# Install suspenders
RE.install_suspender(susp_rc)
RE.install_suspender(susp_shut_fe)
RE.install_suspender(susp_dcm_bragg_temp)
Ejemplo n.º 14
0
print(__file__)
from bluesky.suspenders import (SuspendBoolHigh, SuspendBoolLow, SuspendFloor,
                                SuspendCeil, SuspendInBand, SuspendOutBand)

fe_shut_suspender = SuspendBoolHigh(shutter_fe.state, sleep=10 * 60)
ph_shut_suspender = SuspendBoolHigh(shutter_ph.state, sleep=10 * 60)

# suspender for beamline current is mA
beam_current_suspender = SuspendFloor(nsls_ii.beam_current,
                                      suspend_thresh=300,
                                      sleep=10 * 60)
suspenders = [
    fe_shut_suspender,
    ph_shut_suspender,
    beam_current_suspender,
]
''' Some help on suspenders /bluesky
# how to add a suspender:
# Method 1:
# RE.install_suspender(fe_shut_suspender)
# Method 2 (in the plan):
# RE(bpp.suspend_wrapper(myplan(), [suspenders]))




# general bluesky info
# blue sky plans (mostly) reside here:
# general plans
import bluesky.plans as bp
# (bp.count())
Ejemplo n.º 15
0
def tell_slack_shb_closed():
    print('triggering closed message')
    post_to_slack('B shutter closed')
    return (yield from null())


def tell_slack_shb_opened():
    print('triggering opened message')
    post_to_slack('B shutter opened')
    return (yield from null())


try:
    suspender_shb = SuspendBoolHigh(user_ns['shb'].state,
                                    sleep=5,
                                    pre_plan=tell_slack_shb_closed(),
                                    post_plan=tell_slack_shb_opened())
    all_BMM_suspenders.append(suspender_shb)
except Exception as e:
    print(f'failed to create shb suspender: {e}')
    pass


def BMM_suspenders():
    BMMuser = user_ns['BMMuser']
    if BMMuser.suspenders_engaged:
        return
    for s in all_BMM_suspenders:
        user_ns['RE'].install_suspender(s)
    BMMuser.suspenders_engaged = True
Ejemplo n.º 16
0
from bluesky.suspenders import (SuspendBoolHigh, SuspendBoolLow, SuspendFloor,
                                SuspendCeil, SuspendInBand, SuspendOutBand)

from ophyd import EpicsSignal
from .startup import RE

ring_suspender = SuspendFloor(EpicsSignal('XF:23ID-SR{}I-I'),
                              250,
                              sleep=3 * 60)
#ring_suspender = SuspendFloor(EpicsSignal('XF:23ID-SR{}I-I'), 250, sleep=3)
fe_shut_suspender = SuspendBoolHigh(EpicsSignal('XF:23ID-PPS{Sh:FE}Pos-Sts'),
                                    sleep=10 * 60)
#fe_shut_suspender = SuspendBoolHigh(EpicsSignal('XF:23ID-PPS{Sh:FE}Pos-Sts'), sleep=3)
ps1_shut_suspender = SuspendBoolHigh(EpicsSignal('XF:23IDA-PPS:1{PSh}Pos-Sts'),
                                     sleep=5 * 60)
#ps1_shut_suspender =  SuspendBoolHigh(EpicsSignal('XF:23IDA-PPS:1{PSh}Pos-Sts'),sleep=3)

RE.install_suspender(ring_suspender)
RE.install_suspender(fe_shut_suspender)
RE.install_suspender(ps1_shut_suspender)