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

Add initial orchestrators idea #1169

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 41 additions & 0 deletions ophyd/areadetector/detectors_orchestrators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from .detectors import SimDetector


class SimDetectorOrch(SimDetector):
def configure_peaks(self, **kwargs):
"""
Grid: dict {"Start": (M,N), "Width": (J,K), "Num": (W,L),
"Step": (P,Q)}

Configures the driver to create a grid of Peaks.
"""

grid = kwargs.get("grid")

# Most intuitive configuration is set
# using grid.
if grid is not None:
start_tuple = grid["Start"]
width_tuple = grid["Width"]
num_tuple = grid["Num"]
step_tuple = grid["Step"]

self.cam.peak_start.put(start_tuple)
self.cam.peak_width.put(width_tuple)
self.cam.peak_num.put(num_tuple)
self.cam.peak_step.put(step_tuple)

# Making it possible to oberride other parameters that
# are not basically necessary but influence on the
# configuration
properties = {
kwargs.get("variation"): self.cam.peak_variation,
kwargs.get("gain"): self.cam.gain,
kwargs.get("gain_xy"): self.cam.gain_xy,
}

for _property in properties.keys():
if _property is not None:
properties[_property].put(_property)

self.cam.sim_mode.put(1)
43 changes: 43 additions & 0 deletions ophyd/areadetector/plugins_orchestrators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from .plugins import ProcessPlugin


class ProcessPluginOrch(ProcessPlugin):
def configure_average(self, num_to_avg=1, **kwargs):
"""
num_to_avg: int

Configures ProcessPlugin to output
and average of the last num_to_avg images
"""

# Most intuitive configuration is
# set by default. Can be overriden by user with kwargs.
self.enable_background.put(0)
self.enable_flat_field.put(0)
self.enable_offset_scale.put(0)

self.enable_filter.put(1)
self.enable.put(1)
self.filter_type.put(1) # Average

self.auto_reset_filter.put(num_to_avg)
self.filter_callbacks.put(1) # Array N only
self.num_filter.put(num_to_avg)

# Overriding with kwargs part
properties = {
kwargs.get("enable_background"): self.enable_background,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to make the keys the values in kwargs (many of which will be None). I think what you want is something like

for k, v in kwargs:
    getattr(self, k).put(v)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried something similar to:

for k in kwargs.values():
    getattr(self.cam, k).put(kwargs[k])

but for some reason the operation completed without errors but also without changing the PV values.

I tried testing again now but for some reason, cloning my own fork, installing it with pip and testing it with the same SimDetector IOC container image i used before throws an NotImplementedError every time i try to execute a put operation... what am i doing wrong?

>>> from ophyd.areadetector.detectors  import SimDetector
>>> s = SimDetector(prefix="SIM:", name="SIM")
>>> s.cam.acquire.put(1)
Traceback (most recent call last):
  File "/home/marco/.local/lib/python3.10/site-packages/ophyd/device.py", line 325, in __get__
    return instance._signals[self.attr]
KeyError: 'acquire'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/marco/.local/lib/python3.10/site-packages/ophyd/device.py", line 327, in __get__
    return instance._instantiate_component(self.attr)
  File "/home/marco/.local/lib/python3.10/site-packages/ophyd/device.py", line 1352, in _instantiate_component
    self._signals[attr] = cpt.create_component(self)
  File "/home/marco/.local/lib/python3.10/site-packages/ophyd/device.py", line 266, in create_component
    cpt_inst = self.cls(pv_name, parent=instance, **kwargs)
  File "/home/marco/.local/lib/python3.10/site-packages/ophyd/areadetector/base.py", line 36, in __init__
    super().__init__(prefix + "_RBV", write_pv=prefix, **kwargs)
  File "/home/marco/.local/lib/python3.10/site-packages/ophyd/signal.py", line 1740, in __init__
    super().__init__(
  File "/home/marco/.local/lib/python3.10/site-packages/ophyd/signal.py", line 971, in __init__
    self._read_pv = self.cl.get_pv(
  File "/home/marco/.local/lib/python3.10/site-packages/ophyd/_dummy_shim.py", line 51, in get_pv
    raise NotImplementedError
NotImplementedError

shouldnt this be implemented in the base class?

kwargs.get("enable_flat_field"): self.enable_flat_field,
kwargs.get("enable_offset_scale"): self.enable_offset_scale,
kwargs.get("enable_filter"): self.enable_filter,
kwargs.get("enable"): self.enable,
kwargs.get("filter_type"): self.filter_type,
kwargs.get("auto_reset_filter"): self.auto_reset_filter,
kwargs.get("filter_callbacks"): self.filter_callbacks,
kwargs.get("num_filter"): self.num_filter,
kwargs.get("reset_filter"): self.reset_filter,
}

for _property in properties.keys():
if _property is not None:
properties[_property].put(_property)