{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# `specfile_example()` - Output scan(s) to a SPEC data file."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"One of the common concerns is how to access data from bluesky's database. The standard way is to replay the document stream from each of the scans through a bluesky callback that writes the data to the desired file format. Here, we write data to the SPEC file format.\n",
"\n",
"First, we must load the libraries we'll need."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from databroker import Broker\n",
"from apstools.examples import specfile_example"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we create an instance of the *Broker()* using our mongodb database. (For this to work, we know we already have a file located in `~/.config/databroker/mongodb_config.yml` that describes the databroker configuration for mongodb.)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"db = Broker.named(\"mongodb_config\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# get the most recent scan, by steps\n",
"\n",
"The databroker instance, `db`, provides access to its scans by several means. One way is to consider `db` as a list and retreive the last item from the list. This will return a *header* to the scan. The *header* is the common reference to be used. As is the common term, we will call it `h` and print its *start* document.\n",
"\n",
"For this first example, we'll work through the steps one by one."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:databroker._core:Interpreting key = -1 as an integer\n"
]
},
{
"data": {
"text/html": [
"\n",
"
\n",
"\n",
" \n",
" hints | \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" dimensions | \n",
" \n",
" \n",
" \n",
" [[['m1'], 'primary']]\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" md | \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" activity | \n",
" \n",
" \n",
" \n",
" TuneAxis development and testing\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" peak_bkg | \n",
" \n",
" \n",
" \n",
" 0.0045580721055284755\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" peak_center | \n",
" \n",
" \n",
" \n",
" -1.3940973681450914\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" peak_eta | \n",
" \n",
" \n",
" \n",
" 0.2993015167776747\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" peak_model | \n",
" \n",
" \n",
" \n",
" pseudo Voigt\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" peak_scale | \n",
" \n",
" \n",
" \n",
" 100000.0\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" peak_sigma | \n",
" \n",
" \n",
" \n",
" 0.025534621641250733\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" plan_name | \n",
" \n",
" \n",
" \n",
" TuneAxis.tune\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" plan_type | \n",
" \n",
" \n",
" \n",
" generator\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" scan_id | \n",
" \n",
" \n",
" \n",
" 5\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" time | \n",
" \n",
" \n",
" \n",
" 26 minutes ago (2019-02-19T17:12:23.527238)\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" tune_md | \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" initial_position | \n",
" \n",
" \n",
" \n",
" -1.5\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" time_iso8601 | \n",
" \n",
" \n",
" \n",
" 2019-02-19 17:12:23.523994\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" width | \n",
" \n",
" \n",
" \n",
" 2.5\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" tune_parameters | \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" initial_position | \n",
" \n",
" \n",
" \n",
" -1.5\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" num | \n",
" \n",
" \n",
" \n",
" 30\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" peak_choice | \n",
" \n",
" \n",
" \n",
" cen\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" width | \n",
" \n",
" \n",
" \n",
" 2.5\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" x_axis | \n",
" \n",
" \n",
" \n",
" m1\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" y_axis | \n",
" \n",
" \n",
" \n",
" spvoigt\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" uid | \n",
" \n",
" \n",
" \n",
" 957d83c1-9f11-47df-936b-ce14a396cd76\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
"
"
],
"text/plain": [
"{'time': 1550617943.5272377,\n",
" 'uid': '957d83c1-9f11-47df-936b-ce14a396cd76',\n",
" 'plan_name': 'TuneAxis.tune',\n",
" 'tune_parameters': {'num': 30,\n",
" 'width': 2.5,\n",
" 'initial_position': -1.5,\n",
" 'peak_choice': 'cen',\n",
" 'x_axis': 'm1',\n",
" 'y_axis': 'spvoigt'},\n",
" 'hints': {'dimensions': [[['m1'], 'primary']]},\n",
" 'scan_id': 5,\n",
" 'plan_type': 'generator',\n",
" 'md': {'activity': 'TuneAxis development and testing',\n",
" 'peak_model': 'pseudo Voigt',\n",
" 'peak_scale': 100000.0,\n",
" 'peak_center': -1.3940973681450914,\n",
" 'peak_sigma': 0.025534621641250733,\n",
" 'peak_eta': 0.2993015167776747,\n",
" 'peak_bkg': 0.0045580721055284755},\n",
" 'tune_md': {'width': 2.5,\n",
" 'initial_position': -1.5,\n",
" 'time_iso8601': '2019-02-19 17:12:23.523994'}}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h = db[-1]\n",
"h.start"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The databroker provides a simple table view of this scan (header):"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"