Skip to content

Commit

Permalink
removes RE dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Dec 4, 2017
1 parent 9d0bb52 commit 9732260
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion APS_BlueSky_tools/_demo_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def main():
print("spvoigt.scale: ", spvoigt.scale)
print("spvoigt.bkg: ", spvoigt.bkg)

tuner = TuneAxis([spvoigt], m1, RE, signal_name="spvoigt")
tuner = TuneAxis([spvoigt], m1, signal_name="spvoigt")
live_table = LiveTable(["m1", "spvoigt"])
tuner.width = 2
tuner.step_factor = tuner.num/2.5
Expand Down
41 changes: 26 additions & 15 deletions APS_BlueSky_tools/plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
.. autosummary::
~nscan
~sscan
~TuneAxis
"""
Expand Down Expand Up @@ -109,25 +108,39 @@ def inner_scan():
return (yield from inner_scan())


def sscan(*args, md=None, **kw): # TODO: planned
"""
gather data form the sscan record and emit documents
Should this operate a complete scan using the sscan record?
"""
raise NotImplemented("this is only planned")
# def sscan(*args, md=None, **kw): # TODO: planned
# """
# gather data form the sscan record and emit documents
#
# Should this operate a complete scan using the sscan record?
# """
# raise NotImplemented("this is only planned")


class TuneAxis(object):
"""
tune an axis with a signal
This class provides a tuning object so that a Device or other entity
may gain its own tuning process, keeping track of the particulars
needed to tune this device again. For example, one could add
a tuner to a motor stage::
motor = EpicsMotor("xxx:motor", "motor")
motor.tuner = TuneAxis([det], motor)
Then the ``motor`` could be tuned individually::
RE(motor.tuner.tune(md={"activity": "tuning"}))
or the :meth:`tune()` could be part of a plan with other steps.
Example::
tuner = TuneAxis([det], axis, RE)
tuner = TuneAxis([det], axis)
live_table = LiveTable(["axis", "det"])
RE(tuner.multi_pass_tune(width=2, num=9), live_table)
RE(tuner.tune(0.05, num=9), live_table)
RE(tuner.tune(width=0.05, num=9), live_table)
.. autosummary::
Expand All @@ -137,11 +150,10 @@ class TuneAxis(object):
"""

def __init__(self, signals, axis, RE, signal_name=None):
def __init__(self, signals, axis, signal_name=None):
self.signals = signals
self.signal_name = signal_name or signals[0].name
self.axis = axis
self.RE = RE # TODO: can we avoid needing this term? decorator?
self.stats = {}
self.tune_ok = False
self.peaks = None
Expand Down Expand Up @@ -191,13 +203,12 @@ def tune(self, width=None, num=None, md=None):
_md.update(md or {})
if "pass_max" not in _md:
self.stats = []
self.peaks = PeakStats(x=self.axis.name, y=self.signal_name)

@bpp.subs_decorator(self.peaks)
def _scan():
self.peaks = PeakStats(x=self.axis.name, y=self.signal_name)
subscription_number = self.RE.subscribe(self.peaks)
yield from bp.scan(
self.signals, self.axis, start, finish, num=num, md=_md)
self.RE.unsubscribe(subscription_number)

if self.peak_detected():
self.tune_ok = True
Expand Down

0 comments on commit 9732260

Please sign in to comment.