Created
September 7, 2017 21:24
-
-
Save danielballan/84fb58d2bbd2c0ffa869ea7c7ef8c26a to your computer and use it in GitHub Desktop.
standard bluesky startup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Make ophyd listen to pyepics. | |
| from ophyd import setup_ophyd | |
| setup_ophyd() | |
| # Set up a RunEngine and use metadata backed by a sqlite file. | |
| from bluesky import RunEngine | |
| from bluesky.utils import get_history | |
| RE = RunEngine(get_history()) | |
| # Set up a Broker. | |
| from databroker import Broker | |
| db = Broker.named(NAME_HERE) # EDIT THIS LINE | |
| # Subscribe metadatastore to documents. | |
| # If this is removed, data is not saved to metadatastore. | |
| RE.subscribe(db.insert) | |
| # Set up SupplementalData. | |
| from bluesky import SupplementalData | |
| sd = SupplementalData() | |
| RE.preprocessors.append(sd) | |
| # Add a progress bar. | |
| from bluesky.utils import ProgressBarManager | |
| pbar_manager = ProgressBarManager() | |
| RE.waiting_hook = pbar_manager | |
| # Register bluesky IPython magics. | |
| from bluesky.magics import BlueskyMagics | |
| get_ipython().register_magics(BlueskyMagics) | |
| # Set up the BestEffortCallback. | |
| from bluesky.callbacks.best_effort import BestEffortCallback | |
| bec = BestEffortCallback() | |
| RE.subscribe(bec) | |
| peaks = bec.peaks # just as alias for less typing | |
| # At the end of every run, verify that files were saved and | |
| # print a confirmation message. | |
| from bluesky.callbacks.broker import verify_files_saved | |
| # RE.subscribe(post_run(verify_files_saved), 'stop') | |
| # Import matplotlib and put it in interactive mode. | |
| import matplotlib.pyplot as plt | |
| plt.ion() | |
| # Make plots update live while scans run. | |
| from bluesky.utils import install_qt_kicker | |
| install_qt_kicker() | |
| # Optional: set any metadata that rarely changes. | |
| # RE.md['beamline_id'] = 'YOUR_BEAMLINE_HERE' | |
| # convenience imports | |
| from bluesky.callbacks import * | |
| from bluesky.callbacks.broker import * | |
| from bluesky.simulators import * | |
| from bluesky.plans import * | |
| import numpy as np | |
| from pyOlog.ophyd_tools import * | |
| # Uncomment the following lines to turn on verbose messages for | |
| # debugging. | |
| # import logging | |
| # ophyd.logger.setLevel(logging.DEBUG) | |
| # logging.basicConfig(level=logging.DEBUG) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment