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

ENH/MNT: refactor sim.SynGauss and add MotorGauss #906

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
39 changes: 33 additions & 6 deletions ophyd/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def hints(self):
raise AttributeError


class SynGauss(Device):
class Gauss(Device):
"""
Evaluate a point on a Gaussian based on the value of a motor.

Expand Down Expand Up @@ -505,8 +505,9 @@ class SynGauss(Device):
motor = SynAxis(name='motor')
det = SynGauss('det', motor, 'motor', center=0, Imax=1, sigma=1)
"""

def _compute(self):
m = self._motor.read()[self._motor_field]['value']
m = self._get_motor()
# we need to do this one at a time because
# - self.read() may be screwed with by the user
# - self.get() would cause infinite recursion
Expand All @@ -531,18 +532,18 @@ def _compute(self):
enum_strings=('none', 'poisson', 'uniform'))
noise_multiplier = Cpt(Signal, value=1, kind='config')

def __init__(self, name, motor, motor_field, center, Imax,
*, random_state=None,
def _get_motor(self):
return self.parent.motor.get()

def __init__(self, name, center=0, Imax=1,
*, random_state=None,
**kwargs):
set_later = {}
for k in ('sigma', 'noise', 'noise_multiplier'):
v = kwargs.pop(k, None)
if v is not None:
set_later[k] = v
super().__init__(name=name, **kwargs)
self._motor = motor
self._motor_field = motor_field
self.center.put(center)
self.Imax.put(Imax)

Expand Down Expand Up @@ -585,6 +586,32 @@ def exposure_time(self):
def exposure_time(self, v):
self.val.exposure_time = v

class SynGauss(Gauss):
motor = None

def __init__(self, name, motor, motor_field, center, Imax,
*, random_state=None,

**kwargs):
self._motor = motor
self._motor_field = motor_field
super().__init__(name=name, **kwargs)

def _get_motor(self):
return self._motor.read()[self._motor_field]['value']

class MotorGauss(Device):
motor = Cpt(SynAxis)
det = Cpt(Gauss)

def __init__(self, name, center=0, Imax=1,
*, random_state=None,
**kwargs):
super().__init__(name=name, **kwargs)
self.det.center.put(center)
self.det.Imake.put(Imax)



class Syn2DGauss(Device):
"""
Expand Down