Skip to main content

Sirepo-Bluesky interface

Project description

https://img.shields.io/travis/NSLS-II/sirepo-bluesky.svg https://img.shields.io/pypi/v/sirepo-bluesky.svg

Sirepo-Bluesky interface

Purpose

An attempt to integrate Sirepo/SRW simulations with Bluesky/Ophyd.

Based on this Sirepo simulation that can be downloaded in the next section:

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/basic_beamline.png

Prepare a local Sirepo server

  • 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 with vagrant 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 the SIREPO_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 “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:

mkdir -p $HOME/tmp/sirepo-docker-run
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

Prepare Bluesky and trigger a simulated Sirepo detector

  • (OPTIONAL) Make sure you have mongodb installed and the service is running (see local.yml for details)

  • Create a conda environment:

git clone https://github.com/NSLS-II/sirepo-bluesky/
cd sirepo-bluesky/
conda create -n sirepo_bluesky python=3.7 -y
conda activate sirepo_bluesky
pip install -e .
  • Start ipython and run the following where sim_id is the UID for the simulation we are working with:

%run -i examples/prepare_det_env.py
import sirepo_bluesky.sirepo_detector as sd
import bluesky.plans as bp
sirepo_det = sd.SirepoDetector(sim_id='<sim_id>', 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:

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/sirepo_bluesky_grid.png
  • 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:

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/sirepo_bluesky.png

To view single-electron spectrum report (Hint: use a different sim_id, e.g. for the NSLS-II CHX beamline example):

%run -i examples/prepare_det_env.py
import sirepo_bluesky.sirepo_detector as sd
import bluesky.plans as bp
sirepo_det = sd.SirepoDetector(sim_id='<sim_id>', 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:

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/spectrum.png

Use a simulated Sirepo Flyer to run multiple simulations

  • This section is based on the Young’s Double Slit Experiment Sirepo example that can be found in the wavefront propagation folder on the SRW simulations section

  • Open the simulation and grab the new UID (the last 8 alphanumeric symbols)

  • Start ipython and run the following:

%run -i examples/prepare_flyer_env.py
import bluesky.plans as bp
import sirepo_bluesky.sirepo_flyer as sf
  • To create 5 different simulations that change 4 parameters at a time:

params_to_change = []
for i in range(1, 6):
    key1 = 'Aperture'
    parameters_update1 = {'horizontalSize': i * .1, 'verticalSize': (16 - i) * .1}
    key2 = 'Lens'
    parameters_update2 = {'horizontalFocalLength': i + 7}
    key3 = 'Obstacle'
    parameters_update3 = {'horizontalSize': 6 - i}
    params_to_change.append({key1: parameters_update1,
                             key2: parameters_update2,
                             key3: parameters_update3})
  • Create the flyer and run a fly scan where sim_id is the UID of this simulation:

sirepo_flyer = sf.SirepoFlyer(sim_id='<sim_id>', server_name='http://10.10.10.10:8000',
                              root_dir=root_dir, params_to_change=params_to_change,
                              watch_name='W60')

RE(bp.fly([sirepo_flyer]))
  • Access the data:

hdr = db[-1]
hdr.table(stream_name="sirepo_flyer")

Databroker will return the following information:

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/flyer_output.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sirepo-bluesky-0.0.2.tar.gz (37.9 kB view details)

Uploaded Source

Built Distribution

sirepo_bluesky-0.0.2-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file sirepo-bluesky-0.0.2.tar.gz.

File metadata

  • Download URL: sirepo-bluesky-0.0.2.tar.gz
  • Upload date:
  • Size: 37.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for sirepo-bluesky-0.0.2.tar.gz
Algorithm Hash digest
SHA256 05e520d72cc100dd9bc28c6742c45fec4856763595acdd91c738ad71580abd21
MD5 bf72e0307f882fc30982984faed9b5bf
BLAKE2b-256 8e0c19de62f9a7122f87254410abd8f40b582d900399c885f38ca84abb0440a8

See more details on using hashes here.

File details

Details for the file sirepo_bluesky-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: sirepo_bluesky-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for sirepo_bluesky-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c5a96767e567506c41d84bceff80612a5e57e663481fe2ca9f8c703fb940bb78
MD5 8c70cae9854dbed997606114680b3669
BLAKE2b-256 dad1ffb91d951341ff6703841b756db1662da01c6cc764523ec6878e9987467f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page