-
Notifications
You must be signed in to change notification settings - Fork 87
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
DOC: Answer two common questions. #1223
Merged
danielballan
merged 6 commits into
bluesky:master
from
danielballan:explain-why-no-delay-or-time
Jul 2, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
615948b
DOC: Answer two common questions.
danielballan 8756ea8
Apply suggestions from code review
danielballan 301e380
Incorporate @prjemian suggestions.
danielballan a9cbc88
DOC: Fix scan_with_delay example.
danielballan 78f4c7a
Add import to example.
danielballan ae1772c
Copyediting
danielballan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,53 @@ Examples: | |
RE.subscribe(bec) | ||
RE(count([noisy_det], num=5)) | ||
|
||
.. note:: | ||
|
||
Why doesn't :func:`count` have an ``exposure_time`` parameter? | ||
|
||
Modern CCD detectors typically parametrize exposure time with *multiple* | ||
parameters (acquire time, acquire period, num exposures, ...) as do scalers | ||
(preset time, auto count time). There is no one "exposure time" that can be | ||
applied to all detectors. | ||
|
||
Additionally, when using multiple detectors as in ``count([det1, det2]))``, | ||
the user would need to provide a separate exposure time for each detector in | ||
the general case, which would grow wordy. | ||
|
||
One option is to set the time-related parameter(s) as a separate step. | ||
|
||
For interactive use: | ||
|
||
.. code-block:: python | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Tom. Suggest replacing lines 124-128 with this:
|
||
|
||
# Just an example. Your detector might have different names or numbers of | ||
# exposure-related parameters---which is the point. | ||
det.exposure_time.set(3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wary of this code block because it will be copy-pasted into a plan. |
||
det.acquire_period.set(3.5) | ||
|
||
From a plan: | ||
|
||
.. code-block:: python | ||
|
||
# Just an example. Your detector might have different names or numbers of | ||
# exposure-related parameters---which is the point. | ||
yield from bluesky.plan_stubs.mv( | ||
det.exposure_time, 3, | ||
det.acquire_period, 3.5) | ||
|
||
Another is to write a custom plan that wraps :func:`count` and sets the | ||
exposure time. This plan can encode the details that bluesky in general | ||
can't know. | ||
|
||
.. code-block:: python | ||
|
||
def count_with_time(detectors, num, delay, exposure_time, *, md=None): | ||
# Assume all detectors have one exposure time component called | ||
# 'exposure_time' that fully specifies its exposure. | ||
for detector in detectors: | ||
yield from bluesky.plan_stubs.mv(detector.exposure_time, exposure_time) | ||
yield from bluesky.plans.count(detectors, num, delay, md=md) | ||
|
||
.. autosummary:: | ||
:toctree: generated | ||
:nosignatures: | ||
|
@@ -150,6 +197,52 @@ pseudo-axis. It's all the same to the plans. Examples: | |
RE.subscribe(bec) | ||
RE(scan([det], motor, 1, 5, 5)) | ||
|
||
.. note:: | ||
|
||
Why don't scans have a ``delay`` parameter? | ||
|
||
You may have noticed that :func:`count` has a ``delay`` parameter but none | ||
of the scans do. This is intentional. | ||
|
||
The common reason for wanting a delay in a scan is to allow a motor to | ||
settle or a temperature controller to reach equilibrium. It is better to | ||
configure this on the respective devices, so that scans will always add the | ||
appropriate delay for the particular device being scanned. | ||
|
||
.. code-block:: python | ||
|
||
motor.settle_time = 1 | ||
temperature_controller.settle_time = 10 | ||
|
||
For many cases, this is more convenient and more robust than typing a delay | ||
parameter in every invocation of the scan. You only have to set it once, and | ||
it applies thereafter. | ||
|
||
This is why bluesky leaves ``delay`` out of the scans, to guide users toward | ||
klauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
an approach that will likely be a better fit than the one that might occur | ||
to them first. For situations where a ``delay`` parameter really is the | ||
right tool for the job, it is of course always possible to add a ``delay`` | ||
parameter yourself by writing a custom plan. Here is one approach, using a | ||
:ref:`per_step hook <per_step_hook>`. | ||
|
||
.. code-block:: python | ||
|
||
import bluesky.plans | ||
import bluesky.plan_stubs | ||
|
||
def scan_with_delay(*args, delay=0, **kwargs): | ||
"Accepts all the normal 'scan' parameters, plus an optional delay." | ||
|
||
def one_nd_step_with_delay(detectors, step, pos_cache): | ||
"This is a copy of bluesky.plan_stubs.one_nd_step with a sleep added." | ||
motors = step.keys() | ||
yield from bluesky.plan_stubs.move_per_step(step, pos_cache) | ||
yield from bluesky.plan_stubs.sleep(delay) | ||
yield from bluesky.plan_stubs.trigger_and_read(list(detectors) + list(motors)) | ||
|
||
kwargs.setdefault('per_step', one_nd_step_with_delay) | ||
yield from bluesky.plans.scan(*args, **kwargs) | ||
|
||
.. autosummary:: | ||
:toctree: generated | ||
:nosignatures: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect place to expand on why a common method is a challenge. Add this paragraph:
Do multi-channel analyzers and multi-channel scalers set the time differently. This is the place to mention briefly.