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

Ad plugin stats #178

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 11 additions & 3 deletions src/ophyd_async/epics/areadetector/drivers/ad_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from enum import Enum
from typing import FrozenSet, Sequence, Set
from typing import Dict, FrozenSet, Optional, Sequence, Set, Type

from ophyd_async.core import (
DEFAULT_TIMEOUT,
Expand All @@ -11,7 +11,7 @@

from ...signal.signal import epics_signal_rw
from ..utils import ImageMode, ad_r, ad_rw
from ..writers.nd_plugin import NDArrayBase
from ..writers.nd_plugin import NDArrayBase, NDPluginBase


class DetectorState(str, Enum):
Expand Down Expand Up @@ -41,7 +41,15 @@ class DetectorState(str, Enum):


class ADBase(NDArrayBase):
def __init__(self, prefix: str, name: str = "") -> None:
def __init__(
self,
prefix: str,
name: str = "",
enabled_plugins: Optional[Dict[str, Type[NDPluginBase]]] = None,
) -> None:
self.enabled_plugins = {
prefix: plugin_class(prefix) for prefix, plugin_class in enabled_plugins.values()
} if enabled_plugins else {}
# Define some signals
self.acquire = ad_rw(bool, prefix + "Acquire")
self.acquire_time = ad_rw(float, prefix + "AcquireTime")
Expand Down
49 changes: 48 additions & 1 deletion src/ophyd_async/epics/areadetector/writers/nd_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,51 @@ def __init__(self, prefix: str, name: str = "") -> None:


class NDPluginStats(NDPluginBase):
pass
"""Plugin for computing statistics from an image or region of interest within an image.
Each boolean signal enables or disables all signals in the appropriate Enum class.
The enum signals may used in the ScalarSignals kwargs of a HDFWriter, and are also read-only
signals on the plugin.
"""

def __init__(self, prefix: str, name: str = "") -> None:
self.statistics = epics_signal_rw(bool, prefix + "ComputeStatistics")
self.statistics_background_width = epics_signal_rw(int, prefix + "BgdWidth")
self.centroid = epics_signal_rw(bool, prefix + "ComputeCentroid")
self.centroid_threshold = epics_signal_rw(float, prefix + "CentroidThreshold")
# self.profiles = epics_signal_rw(bool, prefix + "ComputeProfiles")
# self.profile_size_x = epics_signal_rw(int, prefix + "ProfileSizeX")
# self.profile_cursor_x = epics_signal_rw(int, prefix + "CursorX")
# self.profile_size_y = epics_signal_rw(int, prefix + "ProfileSizeY")
# self.profile_cursor_y = epics_signal_rw(int, prefix + "CursorY")
# self.histogram = epics_signal_rw(bool, prefix + "ComputeHistogram")
# self.histogram_max = epics_signal_rw(float, prefix + "HistMax")
# self.histogram_min = epics_signal_rw(float, prefix + "HistMin")
# self.histogram_size = epics_signal_rw(int, prefix + "HistSize")
super().__init__(prefix, name)

class StatisticsSignal(str, Enum):
"""Scalar signals that are enabled when self.statistics is set to True"""

MIN_VALUE = "StatsMinValue"
MAX_VALUE = "StatsMaxValue"
TOTAL = "StatsTotal"
NET = "StatsNet"
MIN_X = "StatsMinX"
MIN_Y = "StatsMinY"
MAX_X = "StatsMaxX"
MAX_Y = "StatsMaxY"
SIGMA_VALUE = "StatsSigma"

class CentroidSignal(str, Enum):
TOTAL = "CentroidTotal"
X_VALUE = "CentroidX"
Y_VALUE = "CentroidY"
SIGMA_X = "SigmaX"
SIGMA_Y = "SigmaY"
SIGMA_XY = "SigmaXY"
SKEW_X = "SkewX"
SKEW_Y = "SkewX"
KURTOSIS_X = "KurtosisX"
KURTOSIS_Y = "KurtosisY"
ECCENTRICITY = "Eccentricity"
ORIENTATION = "Orientation"
Loading