Replay Analysis

If somehow the server doesn’t output expected results because of some incident, I will show how to replay the same analysis here. You will need to run the following script in python, IPython or jupyter notebooks. This script shows how to send the data from the database to the running server.

from bluesky.callbacks.zmq import Publisher

# create a publisher to send the data to address "xf28id1-ca1:5577" using "raw" as the prefix
publisher = Publisher("xf28id1-ca1:5577", prefix=b"raw")
# choose a blue sky run in the database, here use the latest as an example
run = db[-1]
# pipe the documents into the publisher
for name, doc in run.documents():
    publisher(name, doc)

If you don’t have the servers running, and you would like to use the data pipeline directly in a script, I recommend using the data pipeline. This is the component in the server to do the data processing. It is a bit more work but give you more freedom to program your own software.

from pdfstream.callbacks.config import Config
from pdfstream.callbacks.analysispipeline import AnalysisPipeline
from pdfstream.callbacks.visualizationpipeline import VisualizationPipeline
from pdfstream.callbacks.serializationpipeline import SerializationPipeline


# create the configuration, key words are optional
config = Config()
# read the configuration file
config.read_a_file("~/.config/acq/xpd_server.ini")
# create three pipelines
analyze = AnalysisPipeline(config)
visualize = VisualizationPipeline(config)
serialize = SerializationPipeline(config)
# choose a blue sky run in the database, here use the latest as an example
run = db[-1]
# pipe the data stream into the pipelines
for name, doc in run.documents():
    name, doc = analyze(name, doc)
    visualize(name, doc)
    serialize(name, doc)