Giter Club home page Giter Club logo

sirepo-bluesky-legacy's Introduction

Purpose:

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

Based on this Sirepo simulation.

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 ":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

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 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:

sirepo-bluesky-legacy's People

Contributors

mrakitin avatar kalebswartz7 avatar abbygi avatar moellep avatar awalter-bnl avatar stuartcampbell avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.