diff --git a/ideas/issue_91/sscan_as_plan.ipynb b/ideas/issue_91/sscan_as_plan.ipynb index 766ff25cf..e0b1dc47f 100644 --- a/ideas/issue_91/sscan_as_plan.ipynb +++ b/ideas/issue_91/sscan_as_plan.ipynb @@ -208,13 +208,15 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "import apstools.plans as APS_plans\n", "import ophyd\n", "\n", + "DIAGNOSTIC_PRINTING = False\n", + "\n", "\n", "def get_sscan_data_objects(sscan):\n", " \"\"\"\n", @@ -232,95 +234,457 @@ "\n", " \n", "def sscan_step_1D(sscan, _md={}):\n", - " \"\"\"simple 1-D step scan using EPICS synApps sscan record\"\"\"\n", - " # TODO: prep\n", + " \"\"\"\n", + " simple 1-D step scan using EPICS synApps sscan record\n", + " \n", + " assumes the sscan record has already been setup properly for a scan\n", + " \"\"\"\n", + " global new_data\n", + " \n", " t0 = time.time()\n", " sscan_status = ophyd.DeviceStatus(sscan.execute_scan)\n", " started = False\n", + " new_data = False\n", " \n", " def execute_cb(value, timestamp, **kwargs):\n", + " \"\"\"watch for sscan to complete\"\"\"\n", + " if DIAGNOSTIC_PRINTING:\n", + " elapsed = \"%.3f\" % (time.time() - t0)\n", + " phase = sscan.scan_phase.get(as_string=True)\n", + " print(\n", + " f\"{elapsed} execute_cb()\"\n", + " f\" {timestamp}:\"\n", + " f\" phase={phase}\"\n", + " f\" executing={value}\"\n", + " )\n", " if started and value in (0, \"IDLE\"):\n", " sscan_status._finished()\n", " sscan.execute_scan.unsubscribe_all()\n", " sscan.scan_phase.unsubscribe_all()\n", - " else:\n", - " elapsed = \"%.3f\" % (time.time() - t0)\n", - " phase = sscan.scan_phase.get(as_string=True)\n", - " print(f\"{elapsed} execute_cb() {timestamp}: phase={phase} executing={value}\")\n", " \n", " def phase_cb(value, timestamp, **kwargs):\n", - " elapsed = \"%.3f\" % (time.time() - t0)\n", - " phase = sscan.scan_phase.enum_strs[value]\n", - " #print(f\"{elapsed} phase_cb() {timestamp}: phase={phase} value={value}\")\n", + " \"\"\"watch for new data\"\"\"\n", + " global new_data\n", + " if DIAGNOSTIC_PRINTING:\n", + " elapsed = \"%.3f\" % (time.time() - t0)\n", + " phase = sscan.scan_phase.enum_strs[value]\n", + " print(\n", + " f\"{elapsed} phase_cb()\"\n", + " f\" {timestamp}:\"\n", + " f\" phase={phase}\"\n", + " f\" value={value}\"\n", + " )\n", " if value in (15, \"RECORD SCALAR DATA\"):\n", - " #yield sscan.read()\n", - " #print(sscan.read())\n", - " print(f\"{elapsed} new data {timestamp}\")\n", - " # TODO: how to report this data FROM HERE to RE\n", + " new_data = True # set flag for main plan\n", + " \n", + " sscan.select_channels()\n", + " sscan_data_objects = get_sscan_data_objects(sscan)\n", " \n", - " #yield from bps.open_run(_md)\n", " sscan.execute_scan.subscribe(execute_cb)\n", " sscan.scan_phase.subscribe(phase_cb)\n", - " yield from bps.mv(sscan.execute_scan, 1)\n", - " #report()\n", + "\n", + " yield from bps.open_run(_md) # start data collection\n", + " yield from bps.mv(sscan.execute_scan, 1) # start sscan\n", " started = True\n", - " #yield from bps.close_run()\n", "\n", - " \n", - " # TODO: collect and emit data, wait for sscan to end\n", + " # collect and emit data, wait for sscan to end\n", + " while not sscan_status.done or new_data:\n", + " if DIAGNOSTIC_PRINTING:\n", + " elapsed = \"%.3f\" % (time.time() - t0)\n", + " print(\n", + " f\"{elapsed} plan()\"\n", + " f\" new data={new_data}\"\n", + " f\" status={sscan_status}\"\n", + " )\n", + " if new_data:\n", + " new_data = False\n", + " yield from bps.create(\"primary\")\n", + " for k, obj in sscan_data_objects.items():\n", + " if DIAGNOSTIC_PRINTING:\n", + " print(f\"obj[{k}] = {obj}\")\n", + " yield from bps.read(obj)\n", + " yield from bps.save()\n", + " yield from bps.sleep(0.001)\n", + "\n", + " # dump the entire sscan record into another stream\n", + " yield from bps.create(\"sscan\")\n", + " yield from bps.read(sscan)\n", + " yield from bps.save()\n", + "\n", + " yield from bps.close_run()\n", + "\n", " return sscan_status" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "0.001 execute_cb() 1552342298.804289: phase=IDLE executing=0\n", - "0.004 execute_cb() 1552342298.804289: phase=SCAN_PENDING executing=1\n", - "0.004 execute_cb() 1552342405.5305305: phase=SCAN_PENDING executing=1\n" + "Transient Scan ID: 1 Time: 2019/03/12 06:26:00\n", + "Persistent Unique Scan ID: 'c09258e8-04a3-47d5-87b9-a016044c3bb9'\n", + "New stream: 'primary'\n", + "+-----------+------------+\n", + "| seq_num | time |\n", + "+-----------+------------+\n", + "| 1 | 06:26:02.2 |\n", + "| 2 | 06:26:03.0 |\n", + "| 3 | 06:26:03.9 |\n", + "| 4 | 06:26:04.9 |\n", + "| 5 | 06:26:05.8 |\n", + "| 6 | 06:26:06.7 |\n", + "New stream: 'sscan'\n", + "+-----------+------------+\n", + "generator sscan_step_1D ['c09258e8'] (scan num: 1)\n", + "\n", + "\n", + "\n" ] }, { "data": { "text/plain": [ - "()" + "('c09258e8-04a3-47d5-87b9-a016044c3bb9',)" ] }, - "execution_count": 24, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.823 new data 1552342405.603196\n", - "2.721 new data 1552342405.603196\n", - "3.625 new data 1552342405.603196\n", - "4.528 new data 1552342405.603196\n", - "5.430 new data 1552342405.603196\n", - "6.339 new data 1552342405.603196\n" - ] } ], "source": [ "scans = sscanDevice(P, name=\"scans\")\n", "scans.select_channels()\n", "\n", - "RE(sscan_step_1D(scans.scan1))" + "RE(sscan_step_1D(scans.scan1), md=dict(purpose=\"development\", issue=\"#91\"))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "h = db[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
timescans_scan1_positioners_p1_readback_valuescans_scan1_detectors_d01_current_valuescans_scan1_detectors_d02_current_valuescans_scan1_positioners_p1_setpoint_value
seq_num
12019-03-12 06:26:02.209883928-1.01.00.0-8.000000e-01
22019-03-12 06:26:03.098092794-0.81.01.0-6.000000e-01
32019-03-12 06:26:03.999228239-0.62.02.0-4.000000e-01
42019-03-12 06:26:04.903812647-0.45.04.0-2.000000e-01
52019-03-12 06:26:05.809070110-0.21.01.0-5.551115e-17
62019-03-12 06:26:06.7066051960.01.00.0-5.551115e-17
\n", + "
" + ], + "text/plain": [ + " time \\\n", + "seq_num \n", + "1 2019-03-12 06:26:02.209883928 \n", + "2 2019-03-12 06:26:03.098092794 \n", + "3 2019-03-12 06:26:03.999228239 \n", + "4 2019-03-12 06:26:04.903812647 \n", + "5 2019-03-12 06:26:05.809070110 \n", + "6 2019-03-12 06:26:06.706605196 \n", + "\n", + " scans_scan1_positioners_p1_readback_value \\\n", + "seq_num \n", + "1 -1.0 \n", + "2 -0.8 \n", + "3 -0.6 \n", + "4 -0.4 \n", + "5 -0.2 \n", + "6 0.0 \n", + "\n", + " scans_scan1_detectors_d01_current_value \\\n", + "seq_num \n", + "1 1.0 \n", + "2 1.0 \n", + "3 2.0 \n", + "4 5.0 \n", + "5 1.0 \n", + "6 1.0 \n", + "\n", + " scans_scan1_detectors_d02_current_value \\\n", + "seq_num \n", + "1 0.0 \n", + "2 1.0 \n", + "3 2.0 \n", + "4 4.0 \n", + "5 1.0 \n", + "6 0.0 \n", + "\n", + " scans_scan1_positioners_p1_setpoint_value \n", + "seq_num \n", + "1 -8.000000e-01 \n", + "2 -6.000000e-01 \n", + "3 -4.000000e-01 \n", + "4 -2.000000e-01 \n", + "5 -5.551115e-17 \n", + "6 -5.551115e-17 " + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "h.table()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
timescans_scan1_scan_phasescans_scan1_data_statescans_scan1_data_readyscans_scan1_scan_busyscans_scan1_alert_flagscans_scan1_alert_messagescans_scan1_current_pointscans_scan1_pasmscans_scan1_execute_scan...scans_scan1_acqmscans_scan1_atimescans_scan1_copytoscans_scan1_a1cdscans_scan1_ascdscans_scan1_positioners_p1_readback_valuescans_scan1_positioners_p1_setpoint_valuescans_scan1_detectors_d01_current_valuescans_scan1_detectors_d02_current_valuescans_scan1_triggers_t1_trigger_value
seq_num
12019-03-12 06:26:06.77330899207100SCAN Complete600...00.001.01.00.0-5.551115e-171.00.01.0
\n", + "

1 rows × 29 columns

\n", + "
" + ], + "text/plain": [ + " time scans_scan1_scan_phase \\\n", + "seq_num \n", + "1 2019-03-12 06:26:06.773308992 0 \n", + "\n", + " scans_scan1_data_state scans_scan1_data_ready \\\n", + "seq_num \n", + "1 7 1 \n", + "\n", + " scans_scan1_scan_busy scans_scan1_alert_flag \\\n", + "seq_num \n", + "1 0 0 \n", + "\n", + " scans_scan1_alert_message scans_scan1_current_point \\\n", + "seq_num \n", + "1 SCAN Complete 6 \n", + "\n", + " scans_scan1_pasm scans_scan1_execute_scan \\\n", + "seq_num \n", + "1 0 0 \n", + "\n", + " ... scans_scan1_acqm \\\n", + "seq_num ... \n", + "1 ... 0 \n", + "\n", + " scans_scan1_atime scans_scan1_copyto scans_scan1_a1cd \\\n", + "seq_num \n", + "1 0.0 0 1.0 \n", + "\n", + " scans_scan1_ascd scans_scan1_positioners_p1_readback_value \\\n", + "seq_num \n", + "1 1.0 0.0 \n", + "\n", + " scans_scan1_positioners_p1_setpoint_value \\\n", + "seq_num \n", + "1 -5.551115e-17 \n", + "\n", + " scans_scan1_detectors_d01_current_value \\\n", + "seq_num \n", + "1 1.0 \n", + "\n", + " scans_scan1_detectors_d02_current_value \\\n", + "seq_num \n", + "1 0.0 \n", + "\n", + " scans_scan1_triggers_t1_trigger_value \n", + "seq_num \n", + "1 1.0 \n", + "\n", + "[1 rows x 29 columns]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "h.table(\"sscan\")" + ] } ], "metadata": {