Skip to content

Commit

Permalink
#91 phoenix (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Mar 11, 2019
1 parent 3275ae6 commit 315ab9d
Showing 1 changed file with 248 additions and 0 deletions.
248 changes: 248 additions & 0 deletions ideas/issue_91/sscan_as_plan.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# sscan as Bluesky plan\n",
"\n",
"## 1D step scans using sscan record\n",
"\n",
"Support the [sscan record](https://epics.anl.gov/bcda/synApps/sscan/sscanRecord.html) with a [bluesky](http://nsls-ii.github.io/bluesky) plan for data acquisition. Consider the case of [1D step scans using sscan record](https://epics.anl.gov/bcda/synApps/sscan/sscanRecord.html#HEADING_1-1)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import asyncio\n",
"from collections import deque, OrderedDict\n",
"import numpy as np\n",
"import time\n",
"\n",
"%matplotlib notebook\n",
"from bluesky.utils import install_qt_kicker\n",
"install_qt_kicker()\n",
"\n",
"# common IOC prefix to be used\n",
"P = \"prj:\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ophyd.scaler import ScalerCH\n",
"scaler = ScalerCH(f\"{P}scaler1\", name=\"scaler\")\n",
"scaler.select_channels(None)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ophyd import EpicsMotor\n",
"m1 = EpicsMotor(f\"{P}m1\", name=\"m1\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from apstools.synApps_ophyd import userCalcsDevice\n",
"calcs = userCalcsDevice(P, name=\"calcs\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from apstools.synApps_ophyd import sscanDevice\n",
"scans = sscanDevice(P, name=\"scans\")\n",
"scans.select_channels()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from apstools.synApps_ophyd import SaveData\n",
"save_data = SaveData(f\"{P}saveData_\", name=\"save_data\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# configure saveData for data collection into MDA files:\n",
" \n",
"save_data.file_system.put(\"/tmp\")\n",
"save_data.subdirectory.put(\"saveData\")\n",
"save_data.base_name.put(\"sscan1_\")\n",
"save_data.next_scan_number.put(1)\n",
"save_data.comment1.put(\"testing\")\n",
"save_data.comment2.put(\"configured and run from ophyd\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# configure the sscan record for data collection:\n",
"\n",
"# clear out the weeds\n",
"scans.reset()\n",
"\n",
"scan = scans.scan1\n",
"scan.number_points.put(6)\n",
"scan.positioners.p1.setpoint_pv.put(m1.user_setpoint.pvname)\n",
"scan.positioners.p1.readback_pv.put(m1.user_readback.pvname)\n",
"scan.positioners.p1.start.put(-1)\n",
"scan.positioners.p1.end.put(0)\n",
"scan.positioner_delay.put(0.0)\n",
"scan.detector_delay.put(0.1)\n",
"scan.detectors.d01.input_pv.put(scaler.channels.chan03.s.pvname)\n",
"scan.detectors.d02.input_pv.put(scaler.channels.chan02.s.pvname)\n",
"scan.triggers.t1.trigger_pv.put(scaler.count.pvname)\n",
"\n",
"# finally, reconfigure\n",
"scans.select_channels()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# make a noisy detector in an EPICS swait record, peak ceneter at 2\n",
"from apstools.synApps_ophyd import swait_setup_lorentzian\n",
"swait_setup_lorentzian(calcs.calc2, m1, 2)\n",
"noisy_det = calcs.calc2.val\n",
"noisy_det.kind = \"hinted\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"def ophyd_step_scan(motor):\n",
" \"\"\"step-scan the motor and read the noisy detector\"\"\"\n",
" t0 = time.time()\n",
" for p in range(10):\n",
" motor.move(p-3)\n",
" print(\n",
" \"%8.3f\" % (time.time()-t0), \n",
" \"%8.2f\" % motor.position, \n",
" \"%8.4f\" % noisy_det.get()\n",
" )\n",
" motor.move(0)\n",
" print(\"Complete in %.3f seconds\" % (time.time()-t0))\n",
"\n",
"# ophyd_step_scan(m1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"--------\n",
"## setup Bluesky, databroker, and the RunEngine"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from databroker import Broker\n",
"db = Broker.named(\"mongodb_config\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bluesky import RunEngine\n",
"import bluesky.plans as bp\n",
"from bluesky.callbacks.best_effort import BestEffortCallback\n",
"from bluesky import SupplementalData\n",
"\n",
"RE = RunEngine({})\n",
"RE.subscribe(db.insert)\n",
"RE.subscribe(BestEffortCallback())\n",
"RE.preprocessors.append(SupplementalData())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"simple step scan using bluesky plan"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# RE(bp.scan([noisy_det], m1, -5, 5, 11))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"------\n",
"## Develop the BS plan"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 315ab9d

Please sign in to comment.