Skip to content

Instantly share code, notes, and snippets.

@danielballan
Last active Nov 11, 2020
Embed
What would you like to do?
Area Detector + ophyd test harness

Run Area Detector

Start the container interactively.

sudo podman run -it --rm --name=area-detector -e AD_PREFIX=13SIM1: -p 5064:5064 -v /tmp:/tmp prjemian/synapps-6.1-ad-3.7:latest

In the container's shell:

iocSimDetector/simDetector.sh start

To attach to the epics > shell and see log messages:

screen -r

Use Ctrl+A Ctrl+D to escape back to the container's shell.

Connect EPICS clients from host

Use ifconfig and find the broadcast address on the the podman network. SetEPICS_CA_ADDR_LIST to that address.

Run

EPICS_CA_ADDR_LIST=... ipython -i interactive_test.py

to exercise the area detector and the bluesky stack. The script may take some time (~10 seconds) to run, and once it completes it should place you in an interactive session where you can run, for eexample,

In [1]: catalog[-1].primary.read()['det_image'].load()
Out[1]: 
<xarray.DataArray 'det_image' (time: 1, dim_0: 100, dim_1: 1024, dim_2: 1024)>
array([[[[  1,   2,   3, ..., 254, 255,   0],
         [  2,   3,   4, ..., 255,   0,   1],
         [  3,   4,   5, ...,   0,   1,   2],
         ...,
         [254, 255,   0, ..., 251, 252, 253],
         [255,   0,   1, ..., 252, 253, 254],
         [  0,   1,   2, ..., 253, 254, 255]],
<snipped>

to get an image array.

import os
import tempfile
import time
from bluesky import RunEngine
from bluesky.plans import count
from databroker import temp
from ophyd import Component
from ophyd.areadetector import SimDetector, HDF5Plugin, SingleTrigger
from ophyd.areadetector.filestore_mixins import (
FileStoreHDF5,
FileStoreIterativeWrite,
)
RE = RunEngine()
db = temp()
catalog = db.v2
RE.subscribe(db.insert)
PV_PREFIX = "13SIM1:"
# prefixes = ['13SIM1:', 'XF:31IDA-BI{Cam:Tbl}']
# Create a directory for the HDF5 file which we will cleanup at the end.
d = tempfile.TemporaryDirectory()
directory = d.name
os.makedirs(directory, exist_ok=True)
class FileWriter(HDF5Plugin, FileStoreHDF5, FileStoreIterativeWrite):
def get_frames_per_point(self):
# Base class uses self.num_capture and always returns 0, it seems.
return self.parent.cam.num_images.get()
class MyDetector(SingleTrigger, SimDetector):
hdf1 = Component(
FileWriter,
"HDF1:",
write_path_template=directory,
read_path_template=directory,
root="/",
)
det = MyDetector(PV_PREFIX, name="det")
det.read_attrs = ["hdf1"]
det.hdf1.read_attrs = []
det.cam.acquire_time.put(0.1)
det.hdf1.warmup()
time.sleep(3)
RE(count([det]))
catalog[-1].primary.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment