Skip to content

Commit

Permalink
ENH: add tab_whitelist/tab_component_names to devices
Browse files Browse the repository at this point in the history
  • Loading branch information
klauer committed Sep 29, 2020
1 parent 9daada6 commit e031879
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 263 deletions.
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: no-commit-to-branch
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-xml
- id: check-yaml
exclude: '^(conda-recipe/meta.yaml)$'
- id: debug-statements

- repo: https://gitlab.com/pycqa/flake8.git
rev: 3.8.3
hooks:
- id: flake8

- repo: https://github.com/timothycrosley/isort
rev: 5.5.3
hooks:
- id: isort
35 changes: 30 additions & 5 deletions hxrsnd/attocube.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""
Attocube devices
"""
import os
import logging
import os

import numpy as np
from ophyd import PositionerBase
from ophyd import Component as Cmp
from ophyd.utils import LimitError
from ophyd import PositionerBase
from ophyd.signal import EpicsSignal, EpicsSignalRO
from ophyd.status import wait as status_wait
from ophyd.utils import LimitError

from .sndmotor import SndMotor
from .snddevice import SndDevice
from .exceptions import MotorDisabled, MotorError, MotorFaulted
from .snddevice import SndDevice
from .sndmotor import SndMotor
from .utils import absolute_submodule_path, as_list

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,6 +48,31 @@ class EccBase(SndMotor, PositionerBase):
"""
ECC Motor Class
"""
tab_component_names = True
tab_whitelist = [
'check_status',
# 'check_value',
'connected',
'disable',
'egu',
'enable',
'enabled',
'error',
'expert_screen',
'high_limit',
'limits',
'low_limit',
'move',
'mv',
'position',
'reference',
'referenced',
'reset',
'set_limits',
'status',
'stop',
]

# position
user_readback = Cmp(EpicsSignalRO, ":POSITION", auto_monitor=True)
user_setpoint = Cmp(EpicsSignal, ":CMD:TARGET")
Expand Down
41 changes: 26 additions & 15 deletions hxrsnd/diode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

import numpy as np
from ophyd import EpicsSignalRO
from ophyd.device import Component as C, FormattedComponent as FC
from ophyd.device import Component as C
from ophyd.device import FormattedComponent as FC
from pcdsdevices.areadetector.detectors import PCDSAreaDetector

from .snddevice import SndDevice
from .aerotech import DiodeAero
from .snddevice import SndDevice

logger = logging.getLogger(__name__)

Expand All @@ -18,7 +19,7 @@ class DiodeBase(SndDevice):
"""
Base class for the diode.
"""
pass
pass


class HamamatsuDiode(DiodeBase):
Expand All @@ -32,9 +33,13 @@ class HamamatsuXMotionDiode(SndDevice):
"""
Class for the Hamamatsu diode but with an X motor
"""

tab_component_names = True
tab_whitelist = ['block', 'blocked', 'unblock']

diode = C(HamamatsuDiode, ":DIODE")
x = C(DiodeAero, ":X")
def __init__(self, prefix, name=None, block_pos=5, unblock_pos=0, *args,
def __init__(self, prefix, name=None, block_pos=5, unblock_pos=0, *args,
block_atol=0.001, desc=None, **kwargs):
super().__init__(prefix, name=name, *args, **kwargs)
self.block_pos = block_pos
Expand All @@ -49,12 +54,12 @@ def blocked(self):
"""
if np.isclose(self.x.position, self.block_pos, atol=self.block_atol):
return True
elif np.isclose(self.x.position, self.unblock_pos,
elif np.isclose(self.x.position, self.unblock_pos,
atol=self.block_atol):
return False
else:
return "Unknown"
return "Unknown"

def block(self, *args, **kwargs):
"""
Moves the diode into the blocking position.
Expand All @@ -75,7 +80,7 @@ def block(self, *args, **kwargs):
Returns
-------
status : MoveStatus
status : MoveStatus
Status object for the move.
"""
return self.x.mv(self.block_pos, *args, **kwargs)
Expand All @@ -100,7 +105,7 @@ def unblock(self, *args, **kwargs):
Returns
-------
status : MoveStatus
status : MoveStatus
Status object for the move.
"""
return self.x.mv(self.unblock_pos, *args, **kwargs)
Expand All @@ -110,12 +115,15 @@ class HamamatsuXYMotionCamDiode(SndDevice):
"""
Class for the Hamamatsu diode but with X and Y motors
"""
tab_component_names = True
tab_whitelist = ['block', 'blocked', 'unblock']

diode = C(HamamatsuDiode, ":DIODE")
x = C(DiodeAero, ":X")
y = C(DiodeAero, ":Y")
cam = C(PCDSAreaDetector, ":CAM", lazy=True)

def __init__(self, prefix, name=None, block_pos=5, pos_func=None,
def __init__(self, prefix, name=None, block_pos=5, pos_func=None,
block_atol=0.001, desc=None, *args, **kwargs):
super().__init__(prefix, name=name, *args, **kwargs)
self.block_pos = block_pos
Expand All @@ -135,18 +143,18 @@ def blocked(self):
Returns 'Unknown' if it is far from either of those positions.
"""
if callable(self.pos_func):
if np.isclose(self.x.position, self.pos_func()+self.block_pos,
if np.isclose(self.x.position, self.pos_func()+self.block_pos,
atol=self.block_atol):
return True
elif np.isclose(self.x.position, self.pos_func(),
elif np.isclose(self.x.position, self.pos_func(),
atol=self.block_atol):
return False
return "Unknown"

def block(self, *args, **kwargs):
"""
Moves the diode by the blocking position defined by the position
function plus the block position.
function plus the block position.
Parameters
----------
Expand All @@ -164,7 +172,7 @@ def block(self, *args, **kwargs):
Returns
-------
status : MoveStatus
status : MoveStatus
Status object for the move.
"""
# Move to the blocked position if we aren't already there
Expand Down Expand Up @@ -196,7 +204,7 @@ def unblock(self, *args, **kwargs):
Returns
-------
status : MoveStatus
status : MoveStatus
Status object for the move.
"""
# Move to the blocked position if we aren't already there
Expand All @@ -223,6 +231,8 @@ class DiodeIO(SndDevice):
name : str
Name of Wave8 device
"""
tab_component_names = True

peakA = FC(EpicsSignalRO,'{self.prefix}:_peakA_{self.channel}')
peakT = FC(EpicsSignalRO,'{self.prefix}:_peakT_{self.channel}')

Expand All @@ -243,6 +253,7 @@ class Wave8(SndDevice):
A system of sixteen diodes, each with two peaks; A and T.
"""
tab_component_names = True
diode_0 = C(DiodeIO, '', channel=0, name='Diode 0')
diode_1 = C(DiodeIO, '', channel=1, name='Diode 1')
diode_2 = C(DiodeIO, '', channel=2, name='Diode 2')
Expand Down
Loading

0 comments on commit e031879

Please sign in to comment.