Exemplo n.º 1
0
def hw(tmpdir):
    from ophyd.sim import hw
    import ophyd
    # ophyd 1.4.0 added support for customizing the directory used by simulated
    # hardware that generates files
    if LooseVersion(ophyd.__version__) >= LooseVersion('1.4.0'):
        return hw(str(tmpdir))
    else:
        return hw()
Exemplo n.º 2
0
def test_my_list_grid_scan1():
    xpd_configuration["shutter"] = shctl1
    motor = hw().motor
    plan = my_list_grid_scan(xpd_pe1c,
                             motor, [1.],
                             cs700, [300., 400., 500.],
                             acquire_time=0.2,
                             images_per_set=300,
                             wait_for_step=20.)
    summarize_plan(plan)
Exemplo n.º 3
0
def test_my_list_grid_scan2():
    xpd_configuration["shutter"] = shctl1
    motor = hw().motor
    plan = my_list_grid_scan(xpd_pe1c,
                             motor, [1.],
                             cs700, [300., 400., 500.],
                             acquire_time=0.2,
                             images_per_set=5,
                             wait_for_step=0.)
    RE = RunEngine()
    RE(plan)
Exemplo n.º 4
0
def test_notify_watchers():
    from ophyd.sim import hw
    hw = hw()
    mst = MoveStatus(hw.motor, 10)

    def callback(*args, **kwargs):
        ...

    mst.watch(callback)
    mst.target = 0
    mst.start_pos = 0
    mst._notify_watchers(0)
Exemplo n.º 5
0
def init_omnia_sim_detector():
    from databroker import Broker
    from ophyd.sim import hw

    dbr = Broker.named("pdf")
    sim = hw()

    return OmniaDetector(
        dbr=dbr,
        name="omnia_det",
        motor1=sim.motor1,
        motor_field1="motor1",
        motor2=sim.motor2,
        motor_field2="motor2",
    )
Exemplo n.º 6
0
def test_fourc_orientation_save(cat, RE, fourc):
    assert len(cat) == 0
    det = hw().noisy_det

    # this run will not save orientation information
    _uids = RE(bp.count([det]))
    assert len(_uids) == 1
    assert len(cat) == 1
    assert "fourc" not in cat[1].primary.config

    # this run _will_ save orientation information
    _uids = RE(bp.count([det, fourc]))
    assert len(_uids) == 1
    assert len(cat) == 2
    xarray_data = cat[2].primary.config["fourc"].read()
    assert not isinstance(xarray_data, dict)
    descriptors = xarray_data.to_dict()
    assert isinstance(descriptors, dict)
    assert list(descriptors.keys()) == "coords attrs dims data_vars".split()
    key_list = """
        _pseudos
        _reals
        class_name
        diffractometer_name
        geometry_name
        lattice
        orientation_attrs
        reflections_details
        sample_name
        UB
    """.split()
    for key in key_list:
        key_name = f"fourc_{key}"
        assert hasattr(xarray_data, key_name)
        assert key_name in descriptors["data_vars"]

    assert xarray_data.fourc_class_name == "Fourc"
    assert xarray_data.fourc_geometry_name == "E4CV"
    assert xarray_data.fourc_diffractometer_name == "fourc"
    assert xarray_data.fourc_sample_name == "Si"

    assert len(xarray_data.fourc__pseudos) == 1
    assert xarray_data.fourc__pseudos[0].values.tolist() == "h k l".split()
    assert len(xarray_data.fourc__reals) == 1
    assert xarray_data.fourc__reals.values[0].tolist(
    ) == "omega chi phi tth".split()
Exemplo n.º 7
0
def test_list_orientation_runs(cat, RE, fourc, kappa):
    det = hw().noisy_det

    def scans():
        yield from bp.count([det])
        yield from bp.count([fourc])
        yield from bp.count([kappa])
        yield from bp.count([fourc, kappa])

    RE(scans())
    runs = hkl.util.list_orientation_runs(cat)
    # four sets of orientation info
    # (last scan has 2, first scan has none)
    assert len(runs.scan_id) == 4
    assert 1 not in runs.scan_id.to_list()  # no orientation
    assert runs.scan_id.to_list() == [2, 3, 4, 4]
    assert runs.diffractometer_name.to_list(
    ) == "fourc kappa fourc kappa".split()
Exemplo n.º 8
0
import os
import time

import bluesky.plans as bp
import dxchange
import numpy as np
import tomopy
from bluesky.run_engine import RunEngine
from ophyd.sim import SynSignal, hw, SynSignalWithRegistry
from xpdan.vend.callbacks.zmq import Publisher
from xpdconf.conf import glbl_dict

hw = hw()
fname = os.path.expanduser("~/Downloads/tooth.h5")

proj, flat, dark, theta = dxchange.read_aps_32id(fname, sino=(0, 1))

proj = tomopy.normalize(proj, flat, dark)

rot_center = tomopy.find_center(proj, theta, init=290, ind=0, tol=0.5)
# proj2 = np.hstack((proj[:, :, :],) * 200)
# proj2 = np.hstack((proj[:, :, :],) * 1)
# rot_center -= 200
proj2 = proj
m = hw.motor1
m.kind = "hinted"
mm = hw.motor2
mm.kind = "hinted"
mmm = hw.motor3
mmm.kind = "hinted"
Exemplo n.º 9
0
def fake_devices():
    return sim.hw()
Exemplo n.º 10
0
# It is that simple, that the message will now be archived in the info level
# (HXRSnD/logs/info.log) and debug level (HXRSnD/logs/debug.log) log files.

# #                             Leave Comments                              # #
###############################################################################

# This seems like it may not be that important, but the purpose of this file is
# to temporarily hold scripts developed during beamtime to then be migrated by
# us (PCDS) into the module. By leaving comments, you make it easier for
# everyone to understand what the code is doing.

###############################################################################
#                             Insert Code Below                               #
###############################################################################
hw = hw()  # Fake hardware for testing
fake_motor = hw.motor


class NotepadScanStatus(Device):
    istep = Cmp(EpicsSignal, ":ISTEP")
    isscan = Cmp(EpicsSignal, ":ISSCAN")
    nshots = Cmp(EpicsSignal, ":NSHOTS")
    nsteps = Cmp(EpicsSignal, ":NSTEPS")
    var0 = Cmp(EpicsSignal, ":SCANVAR00")
    var1 = Cmp(EpicsSignal, ":SCANVAR01")
    var2 = Cmp(EpicsSignal, ":SCANVAR02")
    var0_max = Cmp(EpicsSignal, ":MAX00")
    var1_max = Cmp(EpicsSignal, ":MAX01")
    var2_max = Cmp(EpicsSignal, ":MAX02")
    var0_min = Cmp(EpicsSignal, ":MIN00")
Exemplo n.º 11
0
# Create a graph
source = Stream()
# Convert from raw event model to data
fes = FromEventStream('event', ('data', 'noisy_det'), source, principle=True)

# Averageing graph
adder = fes.accumulate(lambda x, y: x + y)
counter = fes.accumulate(lambda s, x: s + 1, start=0)
averager = adder.zip(counter).map(lambda x: x[0] / x[1])

# Binned averaging
sw = fes.sliding_window(2).map(sum).map(lambda x: x / 2)

# Convert back to Event Model
tes1 = ToEventStream(averager, ('average', ))
tes2 = ToEventStream(sw, ('binned', ))

# sink to plotting
tes1.sink(lambda x: lp(*x))
tes2.sink(lambda x: lp2(*x))

# Run the scan
RE = RunEngine()
t = RE.subscribe(lambda *x: source.emit(x))
# RE.subscribe(lp3)
# RE.subscribe(print)
source.visualize(source_node=True)
RE(count([hw().noisy_det], 100))
plt.show()
Exemplo n.º 12
0
    topz = Cpt(SynAxis)


hf_stage = HFSampleStage(name='hf_stage')
# hf_stage.x.set(5)

hf_stage.read()


##############################################################################
####################################################################################
#Detector
from ophyd.sim import hw
from bluesky.plans import scan
from bluesky.run_engine import RunEngine
hw = hw()
detector = hw.det
detector.read()
simmotor1 = hw.motor
simmotor1.read()
simmotor1.set(0)
simmotor2 = hw.motor
simmotor2.read()
simmotor2.set(1)

# RE(scan([detector],simmotor1,0,14,10))


#Flyer
from ophyd.sim import hw
from bluesky.run_engine import RunEngine
Exemplo n.º 13
0
        print(f"creating {omnia_xy_index_fp}")
        t0 = time.time()
        grid_x = list()
        grid_y = list()
        uids = list()
        for h in self.dbr(sample_name="omnia"):
            grid_x.append(h.start["Grid_X"])
            grid_y.append(h.start["Grid_Y"])
            uids.append(h.start["uid"])

        df = pd.DataFrame(zip(grid_x, grid_y, uids),
                          columns=("Grid_X", "Grid_Y", "uid"))
        df.to_csv(omnia_xy_index_fp, sep="\t")
        print(f"finished {omnia_xy_index_fp} in {time.time()-t0:.3}s")


from databroker import Broker
from ophyd.sim import hw

dbr = Broker.named("pdf")
sim = hw()

omnia_det = OmniaDetector(
    dbr=dbr,
    name="omnia_det",
    motor1=sim.motor1,
    motor_field1="motor1",
    motor2=sim.motor2,
    motor_field2="motor2",
)
Exemplo n.º 14
0
                # This step does not move this motor.
                continue
            yield from abs_set(motor, pos, group=grp)
            pos_cache[motor] = pos
        yield from wait(group=grp)

    motors = step.keys()
    yield from move()
    plt.pause(.001)
    yield from trigger_and_read(list(detectors) + list(motors))


install_kicker()
bec = BestEffortCallback()
bec.enable_plots()
hw = hw()
RE = RunEngine()
# build the pipeline
raw_source = Stream()
raw_output = SimpleFromEventStream('event', ('data', 'det_a'),
                                   raw_source,
                                   principle=True)
raw_output2 = SimpleFromEventStream('event', ('data', 'noisy_det'), raw_source)

pipeline = raw_output.union(raw_output2).map(lambda x: 1).accumulate(
    lambda x, y: x + y)

res = SimpleToEventStream(pipeline, ('result', ))

merge = AlignEventStreams(res, raw_source)
merge.starsink(bec)
Exemplo n.º 15
0
 def hw(request):
     from ophyd.sim import hw
     return hw()
Exemplo n.º 16
0
def hw():
    from ophyd.sim import hw
    return hw()
Exemplo n.º 17
0
from databroker.v1 import temp
from xpdsim import xpd_pe1c, shctl1, cs700, ring_current, fb
from ophyd.sim import hw
import bluesky.plan_stubs as bps
from bluesky.preprocessors import pchain
import bluesky.preprocessors as bpp

from xpdacq.beamtime import ScanPlan, Sample, ct, Tramp, Tlist, tseries
from xpdacq.beamtimeSetup import _start_beamtime, _end_beamtime
from xpdacq.calib import run_calibration
from xpdacq.ipysetup import ipysetup
from xpdacq.utils import import_userScriptsEtc, import_sample_info
from xpdacq.xpdacq_conf import xpd_configuration

pe1c = xpd_pe1c
ns = hw()
Grid_X = ns.motor1
Grid_Y = ns.motor2
cryostream = cs700
db = temp()

_start_beamtime = _start_beamtime
_end_beamtime = _end_beamtime
import_userScriptsEtc = import_userScriptsEtc
import_sample_info = import_sample_info
ScanPlan = ScanPlan
Sample = Sample
ct = ct
Tramp = Tramp
Tlist = Tlist
tseries = tseries
Exemplo n.º 18
0
# Contain plan headers for testing of queue execution for BMM beamline
# Plans: mv, xafs, change_edge, shb_close_plan, set_slot

from ophyd.sim import hw

from bluesky.plans import count, scan
from bluesky.plan_stubs import mv  # noqa: F401

from bluesky_queueserver.manager.profile_tools import set_user_ns

det1, det2, motor = hw().det1, hw().det2, hw().motor

# Those are devices used with 'mv' plans
xafs_x = motor
xafs_y = motor
slits3_hsize = motor
xafs_det = motor


@set_user_ns
def xafs(inifile=None, *, user_ns, **kwargs):
    yield from count([det1, det2], num=5, delay=1)


@set_user_ns
def change_edge(el,
                focus=False,
                edge="K",
                energy=None,
                slits=True,
                target=300.0,
Exemplo n.º 19
0
def hw(request):
    from ophyd.sim import hw
    return hw()
Exemplo n.º 20
0
def hw(tmpdir):
    from ophyd.sim import hw
    return hw(str(tmpdir))
Exemplo n.º 21
0
# flake8: noqa

from ophyd.sim import hw

# Import ALL simulated Ophyd objects in global namespace (borrowed from ophyd.sim)
globals().update(hw().__dict__)
del hw
Exemplo n.º 22
0
def hw(tmpdir):
    from ophyd.sim import hw
    return hw(str(tmpdir))
Exemplo n.º 23
0
from importlib.resources import path

import pytest
from bluesky import RunEngine
from ophyd.sim import hw
from xpdacq.beamtime import Beamtime
from xpdacq.beamtime import xpd_configuration
from xpdacq.beamtimeSetup import load_beamtime
from xpdacq.simulation import xpd_pe1c

with path("data", "__init__.py") as p:
    DATA = p.parent

HW = hw()


@pytest.fixture()
def bt() -> Beamtime:
    bt = load_beamtime(str(DATA.joinpath("acqsim/xpdUser/config_base/yml")))
    return bt


@pytest.fixture
def RE():
    return RunEngine()


xpd_configuration.update({
    "area_det": xpd_pe1c,
    "x_controller": HW.motor1,
    "y_controller": HW.motor2