{
"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 APS_BlueSky_tools.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",
"
\n",
"\n",
" \n",
" hostname | \n",
" \n",
" \n",
" \n",
" mint-vm\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" iso8601 | \n",
" \n",
" \n",
" \n",
" 2018-12-27 00:36:00.050644\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" login_id | \n",
" \n",
" \n",
" \n",
" mintadmin@mint-vm\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" plan_description | \n",
" \n",
" \n",
" \n",
" archive snapshot of ophyd Signals (usually EPICS PVs)\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" plan_name | \n",
" \n",
" \n",
" \n",
" snapshot\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" plan_type | \n",
" \n",
" \n",
" \n",
" generator\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" purpose | \n",
" \n",
" \n",
" \n",
" example\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" scan_id | \n",
" \n",
" \n",
" \n",
" 1\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" software_versions | \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" APS_Bluesky_Tools | \n",
" \n",
" \n",
" \n",
" 0.0.40+1.g8705698\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" bluesky | \n",
" \n",
" \n",
" \n",
" 1.4.1\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" databroker | \n",
" \n",
" \n",
" \n",
" 0.11.3\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" ophyd | \n",
" \n",
" \n",
" \n",
" 1.3.0\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" PyEpics | \n",
" \n",
" \n",
" \n",
" 3.3.1\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" python | \n",
" \n",
" \n",
" \n",
" 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 17:14:51) \n",
"[GCC 7.2.0]\n",
" \n",
" \n",
" | \n",
" \n",
"\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" time | \n",
" \n",
" \n",
" \n",
" 7 days ago (2018-12-27T00:36:00.051762)\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" uid | \n",
" \n",
" \n",
" \n",
" 9bc1fe93-e56b-4dfc-a2bc-ee91b6f88200\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
" \n",
" username | \n",
" \n",
" \n",
" \n",
" mintadmin\n",
" \n",
" \n",
" | \n",
"
\n",
"\n",
"
"
],
"text/plain": [
"{'time': 1545892560.0517623,\n",
" 'uid': '9bc1fe93-e56b-4dfc-a2bc-ee91b6f88200',\n",
" 'hints': {},\n",
" 'software_versions': {'python': '3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 17:14:51) \\n[GCC 7.2.0]',\n",
" 'PyEpics': '3.3.1',\n",
" 'bluesky': '1.4.1',\n",
" 'ophyd': '1.3.0',\n",
" 'databroker': '0.11.3',\n",
" 'APS_Bluesky_Tools': '0.0.40+1.g8705698'},\n",
" 'iso8601': '2018-12-27 00:36:00.050644',\n",
" 'plan_type': 'generator',\n",
" 'plan_name': 'snapshot',\n",
" 'username': 'mintadmin',\n",
" 'scan_id': 1,\n",
" 'plan_description': 'archive snapshot of ophyd Signals (usually EPICS PVs)',\n",
" 'login_id': 'mintadmin@mint-vm',\n",
" 'hostname': 'mint-vm',\n",
" 'purpose': 'example'}"
]
},
"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": [
"