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

make function for AD prime plugin #837

Closed
prjemian opened this issue Apr 5, 2023 · 3 comments · Fixed by #861
Closed

make function for AD prime plugin #837

prjemian opened this issue Apr 5, 2023 · 3 comments · Fixed by #861
Assignees
Milestone

Comments

@prjemian
Copy link
Contributor

prjemian commented Apr 5, 2023

This is a common pattern:

from .. import iconfig
from apstools.devices import AD_plugin_primed
from apstools.devices import AD_prime_plugin2

if iconfig.get("ALLOW_AREA_DETECTOR_WARMUP", False):
    # WORKAROUND
    # Even with `lazy_open=1`, ophyd checks if the area
    # detector HDF5 plugin has been primed.  We might
    # need to prime it.  Here's ophyd's test:
    # if np.array(adsimdet.hdf1.array_size.get()).sum() == 0:
    #     logger.info(f"Priming {adsimdet.hdf1.name} ...")
    #     adsimdet.hdf1.warmup()
    #     logger.info(f"Enabling {adsimdet.image.name} plugin ...")
    #     adsimdet.image.enable.put("Enable")
    if not AD_plugin_primed(adsimdet.hdf1):
        AD_prime_plugin2(adsimdet.hdf1)

Make it into a function.

@prjemian prjemian added this to the 1.6.16 milestone Apr 5, 2023
@prjemian prjemian self-assigned this Apr 5, 2023
@prjemian
Copy link
Contributor Author

prjemian commented Apr 5, 2023

such as this definition:

from apstools.devices import AD_plugin_primed
from apstools.devices import AD_prime_plugin2

def ensure_AD_plugin_primed(plugin, allow_warmup=False):
    """
    Ensure the AD plugin is warmed up, if allowed.

    This is a workaround for a check in area_detector_handlers which
    found a mismatch in the description of the image array parameters
    (size, number of bits, & color mode) between the cam and the plugin.

    Even with ``lazy_open=1``, ophyd (via area_detector_handlers) checks
    if the area detector HDF5 plugin has been _primed_.

    We might need to prime it.  Here's ophyd's test (which is not sufficient)::

        if np.array(plugin.array_size.get()).sum() == 0:
            logger.info(f"Priming {plugin.name} ...")
            plugin.warmup()
    """
    if allow_warmup:
        if not AD_plugin_primed(plugin):
            logger.info(f"Priming {plugin.name} ...")
            AD_prime_plugin2(plugin)

then replace the original call with this new one:

from .. import iconfig
from apstools.devices import ensure_AD_plugin_primed

ensure_AD_plugin_primed(adsimdet.hdf1, iconfig.get("ALLOW_AREA_DETECTOR_WARMUP", False))

@MarkRivers
Copy link

Even with lazy_open=1, ophyd (via area_detector_handlers) checks if the area detector HDF5 plugin has been primed.

Can't this be fixed in ophyd?

@prjemian
Copy link
Contributor Author

Fixing this problem in ophyd would involve removing the if ... clause from the HDF5Plugin's stage() method:

    def stage(self):
        if np.array(self.array_size.get()).sum() == 0:
            raise UnprimedPlugin(
                f"The plugin {self.dotted_name} on the "
                f"area detector with name {self.root.name} "
                f"has not been primed."
            )
        return super().stage()

There must be other code (called by the bluesky RunEngine) which reports the image array parameters in the descriptor documents. In the case of a lazy_open=1 plugin configuration, this other code must be refactored to wait for the first image before creating the associated descriptor document.

prjemian added a commit that referenced this issue May 20, 2023
prjemian added a commit that referenced this issue May 20, 2023
prjemian added a commit that referenced this issue May 20, 2023
prjemian added a commit that referenced this issue May 20, 2023
prjemian added a commit that referenced this issue May 20, 2023
prjemian added a commit that referenced this issue May 20, 2023
prjemian added a commit that referenced this issue May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants