Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example scans with sscan record #942

Merged
merged 17 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DOC #940 convert the blocking call to st.wait()
prjemian committed Mar 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 7bacb1b0d8ad7f697051b074664ceb16cd450a18
45 changes: 26 additions & 19 deletions docs/source/examples/de_sscan.ipynb
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
@@ -79,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 23,
"metadata": {},
"outputs": [
{
@@ -115,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
@@ -176,8 +176,13 @@
"background) reports when the scan has finished or times out. We define an inner\n",
"`watch_the_button()` function to detect when the button goes from `1` to `0`\n",
"(the scan stops). We setup a subscription (*after* we start the move) to\n",
"monitor the button value and respond immediately. We wait for the status object\n",
"to finish with `st.wait()`. Finally, we cancel the monitor of the button."
"monitor the button value and respond immediately. \n",
"\n",
"We wait for the status object to finish with `st.wait()`. In a bluesky plan,\n",
"we'll need to use `apstools.plans.run_blocking_function` with `st.wait()` since\n",
"it is a blocking function.\n",
"\n",
"Finally, we cancel the monitor of the button."
]
},
{
@@ -186,6 +191,7 @@
"metadata": {},
"outputs": [],
"source": [
"from apstools.plans import run_blocking_function\n",
"from ophyd.status import Status\n",
"\n",
"def run_sscan():\n",
@@ -194,11 +200,11 @@
" def watch_the_button(old_value, value, **kwargs):\n",
" if old_value == 1 and value == 0:\n",
" st.set_finished()\n",
" scan_button.clear_sub(watch_the_button)\n",
"\n",
" yield from bps.mv(scan_button, 1)\n",
" scan_button.subscribe(watch_the_button)\n",
" st.wait()\n",
" scan_button.unsubscribe_all()"
" yield from run_blocking_function(st.wait)"
]
},
{
@@ -234,7 +240,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
@@ -246,19 +252,19 @@
"def run_sscan():\n",
" st = Status(timeout=20)\n",
"\n",
" def watch_the_button(old_value, value, **kwargs):\n",
" def watch_execute_scan(old_value, value, **kwargs):\n",
" if old_value == 1 and value == 0:\n",
" st.set_finished()\n",
" scan1.execute_scan.clear_sub(watch_execute_scan)\n",
"\n",
" yield from bps.mv(scan1.execute_scan, 1)\n",
" scan1.execute_scan.subscribe(watch_the_button)\n",
" st.wait()\n",
" scan1.execute_scan.unsubscribe_all()"
" scan1.execute_scan.subscribe(watch_execute_scan)\n",
" yield from run_blocking_function(st.wait)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 28,
"metadata": {},
"outputs": [
{
@@ -267,7 +273,7 @@
"()"
]
},
"execution_count": 8,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
@@ -360,9 +366,12 @@
"We can supply the count time per point and scan range parameters as arguments to\n",
"the setup. After setting the counting time for the scaler, the next step in the\n",
"setup is to clear any existing configuration of `scan1` using its `reset()`\n",
"method. In a bluesky plan, we'll need to use\n",
"`apstools.plans.run_blocking_function` with that `reset()` method. Finally,\n",
"we'll setup `scan1` with the EPICS PV names to be used."
"method.\n",
"\n",
"In a bluesky plan, we'll need to use `apstools.plans.run_blocking_function` with\n",
"that `reset()` method.\n",
"\n",
"Finally, we'll setup `scan1` with the EPICS PV names to be used."
]
},
{
@@ -371,8 +380,6 @@
"metadata": {},
"outputs": [],
"source": [
"from apstools.plans import run_blocking_function\n",
"\n",
"def setup_scan1(start, finish, npts, ct=1):\n",
" yield from bps.mv(scaler1.preset_time, ct) # counting time/point\n",
" yield from run_blocking_function(scan1.reset)\n",