Add a helper warmup function for hdf5 plugins of AD#162
Draft
mrakitin wants to merge 1 commit intoNSLS-II:masterfrom
Draft
Add a helper warmup function for hdf5 plugins of AD#162mrakitin wants to merge 1 commit intoNSLS-II:masterfrom
mrakitin wants to merge 1 commit intoNSLS-II:masterfrom
Conversation
|
Since this method is needed for other file area detector writing plugins, perhaps it should be more general? Here is code from def AD_plugin_primed(plugin):
"""
Has area detector pushed an NDarray to the file writer plugin? True or False
PARAMETERS
plugin
*obj* :
area detector plugin to be *primed* (such as ``detector.hdf1``)
EXAMPLE::
AD_plugin_primed(detector.hdf1)
Works around an observed issue: #598
https://github.com/NSLS-II/ophyd/issues/598#issuecomment-414311372
If detector IOC has just been started and has not yet taken an image
with the file writer plugin, then a TimeoutError will occur as the
file writer plugin "Capture" is set to 1 (Start). In such case,
first acquire at least one image with the file writer plugin enabled.
Also issue in apstools (needs a robust method to detect if primed):
https://github.com/BCDA-APS/apstools/issues/464
Since Area Detector release 2.1 (2014-10-14).
The *prime* process is not needed if you select the
*LazyOpen* feature with *Stream* mode for the file plugin.
*LazyOpen* defers file creation until the first frame arrives
in the plugin. This removes the need to initialize the plugin
with a dummy frame before starting capture.
"""
cam = plugin.parent.cam
tests = []
for obj in (cam, plugin):
test = np.array(obj.array_size.get()).sum() != 0
tests.append(test)
if not test:
logger.debug("'%s' image size is zero", obj.name)
checks = dict(
array_size=False,
color_mode=True,
data_type=True,
)
for key, as_string in checks.items():
c = getattr(cam, key).get(as_string=as_string)
p = getattr(plugin, key).get(as_string=as_string)
test = c == p
tests.append(test)
if not test:
logger.debug("%s does not match", key)
return False not in tests |
|
Here's the code that primes the plugin: def AD_prime_plugin2(plugin):
"""
Prime this area detector's file writer plugin.
Collect and push an NDarray to the file writer plugin.
Works with all file writer plugins.
Based on ``ophyd.areadetector.plugins.HDF5Plugin.warmup()``.
PARAMETERS
plugin
*obj* :
area detector plugin to be *primed* (such as ``detector.hdf1``)
EXAMPLE::
AD_prime_plugin2(detector.hdf1)
"""
if AD_plugin_primed(plugin):
logger.debug("'%s' plugin is already primed", plugin.name)
return
sigs = OrderedDict(
[
(plugin.enable, 1),
(plugin.parent.cam.array_callbacks, 1), # set by number
(plugin.parent.cam.image_mode, 0), # Single, set by number
# Trigger mode names are not identical for every camera.
# Assume here that the first item in the list is
# the best default choice to prime the plugin.
(plugin.parent.cam.trigger_mode, 0), # set by number
# just in case the acquisition time is set very long...
(plugin.parent.cam.acquire_time, 1),
(plugin.parent.cam.acquire_period, 1),
(plugin.parent.cam.acquire, 1), # set by number
]
)
original_vals = {sig: sig.get() for sig in sigs}
for sig, val in sigs.items():
time.sleep(0.1) # abundance of caution
sig.set(val).wait()
time.sleep(2) # wait for acquisition
for sig, val in reversed(list(original_vals.items())):
time.sleep(0.1)
sig.set(val).wait() |
jklynch
requested changes
Oct 14, 2022
Contributor
jklynch
left a comment
There was a problem hiding this comment.
I would like to make 2 recommendations:
- this code should go in a new file nslsii/areadetector/utils.py
- Pete Jemian's code should also go there and be used to implement warmup_hdf5_plugins
Member
|
Can we please do this as a plan so it will compose nicely? def AD_prime_plugin2(plugin):
"""
Prime this area detector's file writer plugin.
Collect and push an NDarray to the file writer plugin.
Works with all file writer plugins.
Based on ``ophyd.areadetector.plugins.HDF5Plugin.warmup()``.
PARAMETERS
plugin
*obj* :
area detector plugin to be *primed* (such as ``detector.hdf1``)
EXAMPLE::
AD_prime_plugin2(detector.hdf1)
"""
if AD_plugin_primed(plugin):
logger.debug("'%s' plugin is already primed", plugin.name)
return
sigs = OrderedDict(
[
(plugin.enable, 1),
(plugin.parent.cam.array_callbacks, 1), # set by number
(plugin.parent.cam.image_mode, 0), # Single, set by number
# Trigger mode names are not identical for every camera.
# Assume here that the first item in the list is
# the best default choice to prime the plugin.
(plugin.parent.cam.trigger_mode, 0), # set by number
# just in case the acquisition time is set very long...
(plugin.parent.cam.acquire_time, 1),
(plugin.parent.cam.acquire_period, 1),
(plugin.parent.cam.acquire, 1), # set by number
]
)
original_vals = {}
for sig in sigs:
original_vals[sig] = yield from bps.rd(sig)
for sig, val in sigs.items():
yield from bps.sleep(.1)
yield from bps.abs_set(sig, val)
yield from bps.sleep(2) # wait for acquisition
for sig, val in reversed(original_vals.items()):
yield from bps.sleep(.1)
yield from bps.abs_set(sig, val) |
|
I'd be happier seeing both |
Member
Author
|
We should revive it. Should it go to ophyd? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This was originally implemented at NSLS-II TES, porting the function to here to be available to other beamlines.