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", + " | time | \n", + "scans_scan1_positioners_p1_readback_value | \n", + "scans_scan1_detectors_d01_current_value | \n", + "scans_scan1_detectors_d02_current_value | \n", + "scans_scan1_positioners_p1_setpoint_value | \n", + "
---|---|---|---|---|---|
seq_num | \n", + "\n", + " | \n", + " | \n", + " | \n", + " | \n", + " |
1 | \n", + "2019-03-12 06:26:02.209883928 | \n", + "-1.0 | \n", + "1.0 | \n", + "0.0 | \n", + "-8.000000e-01 | \n", + "
2 | \n", + "2019-03-12 06:26:03.098092794 | \n", + "-0.8 | \n", + "1.0 | \n", + "1.0 | \n", + "-6.000000e-01 | \n", + "
3 | \n", + "2019-03-12 06:26:03.999228239 | \n", + "-0.6 | \n", + "2.0 | \n", + "2.0 | \n", + "-4.000000e-01 | \n", + "
4 | \n", + "2019-03-12 06:26:04.903812647 | \n", + "-0.4 | \n", + "5.0 | \n", + "4.0 | \n", + "-2.000000e-01 | \n", + "
5 | \n", + "2019-03-12 06:26:05.809070110 | \n", + "-0.2 | \n", + "1.0 | \n", + "1.0 | \n", + "-5.551115e-17 | \n", + "
6 | \n", + "2019-03-12 06:26:06.706605196 | \n", + "0.0 | \n", + "1.0 | \n", + "0.0 | \n", + "-5.551115e-17 | \n", + "
\n", + " | time | \n", + "scans_scan1_scan_phase | \n", + "scans_scan1_data_state | \n", + "scans_scan1_data_ready | \n", + "scans_scan1_scan_busy | \n", + "scans_scan1_alert_flag | \n", + "scans_scan1_alert_message | \n", + "scans_scan1_current_point | \n", + "scans_scan1_pasm | \n", + "scans_scan1_execute_scan | \n", + "... | \n", + "scans_scan1_acqm | \n", + "scans_scan1_atime | \n", + "scans_scan1_copyto | \n", + "scans_scan1_a1cd | \n", + "scans_scan1_ascd | \n", + "scans_scan1_positioners_p1_readback_value | \n", + "scans_scan1_positioners_p1_setpoint_value | \n", + "scans_scan1_detectors_d01_current_value | \n", + "scans_scan1_detectors_d02_current_value | \n", + "scans_scan1_triggers_t1_trigger_value | \n", + "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
seq_num | \n", + "\n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " |
1 | \n", + "2019-03-12 06:26:06.773308992 | \n", + "0 | \n", + "7 | \n", + "1 | \n", + "0 | \n", + "0 | \n", + "SCAN Complete | \n", + "6 | \n", + "0 | \n", + "0 | \n", + "... | \n", + "0 | \n", + "0.0 | \n", + "0 | \n", + "1.0 | \n", + "1.0 | \n", + "0.0 | \n", + "-5.551115e-17 | \n", + "1.0 | \n", + "0.0 | \n", + "1.0 | \n", + "
1 rows × 29 columns
\n", + "