An attempt to integrate Sirepo/SRW simulations with Bluesky/Ophyd.
Based on this Sirepo simulation.
- install Sirepo using Vagrant/VirtualBox following the instructions (you will need to install VirtualBox and Vagrant)
- after the successful installation start the VM with
vagrant up
and ssh to it withvagrant ssh
- run the following command to start Sirepo with the Bluesky interface (
bluesky
is a "secret" key used on both server and client sides, and theSIREPO_FEATURE_CONFIG_SIM_TYPES=srw
part is optional if you run Sirepo directly on a Linux/Mac machine and only have SRW installed):
SIREPO_FEATURE_CONFIG_SIM_TYPES=srw SIREPO_AUTH_METHODS=bluesky:guest SIREPO_AUTH_BLUESKY_SECRET=bluesky sirepo service http
- in your browser, go to http://10.10.10.10:8000/srw, click the ":cloud: Import" button in the right-upper corner and upload the archive with the simulation stored in this repo
- you should be redirected to the address like http://10.10.10.10:8000/srw#/source/IKROlKfR
- grab the last 8 alphanumeric symbols (
IKROlKfR
), which represent a UID for the simulation we will be working with in the next section.
You can also consider running a Docker container:
docker run -it --rm -e SIREPO_AUTH_METHODS=bluesky:guest -e SIREPO_AUTH_BLUESKY_SECRET=bluesky -e SIREPO_SRDB_ROOT=/sirepo -e SIREPO_COOKIE_IS_SECURE=false -p 8000:8000 -v $HOME/tmp/sirepo-docker-run:/sirepo radiasoft/sirepo:beta /home/vagrant/.pyenv/shims/sirepo service http
- (OPTIONAL) make sure you have mongodb installed and the service is running (see local.yml for details)
- create conda environment:
git clone https://github.com/NSLS-II/sirepo-bluesky/
cd sirepo-bluesky/
conda create -n sirepo_bluesky python=3.6 -y
conda activate sirepo_bluesky
pip install -r requirements.txt
- start
ipython
and run the following:
%run -i re_config.py
import sirepo_detector as sd
sirepo_det = sd.SirepoDetector(sim_id='qyQ4yILz', reg=db.reg)
sirepo_det.select_optic('Aperture')
param1 = sirepo_det.create_parameter('horizontalSize')
param2 = sirepo_det.create_parameter('verticalSize')
sirepo_det.read_attrs = ['image', 'mean', 'photon_energy']
sirepo_det.configuration_attrs = ['horizontal_extent',
'vertical_extent',
'shape']
RE(bp.grid_scan([sirepo_det],
param1, 0, 1, 10,
param2, 0, 1, 10,
True))
You should get something like:
- get the data:
hdr = db[-1]
imgs = list(hdr.data('sirepo_det_image'))
cfg = hdr.config_data('sirepo_det')['primary'][0]
hor_ext = cfg['{}_horizontal_extent'.format(sirepo_det.name)]
vert_ext = cfg['{}_vertical_extent'.format(sirepo_det.name)]
plt.imshow(imgs[21], aspect='equal', extent=(*hor_ext, *vert_ext))
You should get something like:
To view single-electron spectrum report
(Hint: use a different sim_id
, e.g. for the NSLS-II CHX beamline example):
%run -i re_config.py
import sirepo_detector as sd
sirepo_det = sd.SirepoDetector(sim_id='8GJJWLFh', reg=db.reg, source_simulation=True)
sirepo_det.read_attrs = ['image', 'mean', 'photon_energy']
sirepo_det.configuration_attrs = ['horizontal_extent',
'vertical_extent',
'shape']
RE(bp.count([sirepo_det]))
hdr = db[-1]
imgs = list(hdr.data('sirepo_det_image'))
plt.plot(imgs[-1])
You should get something like: