Skip to content

Commit

Permalink
Merge pull request #12 from licode/hkl_update
Browse files Browse the repository at this point in the history
REF: Use AttributeSignal and ArrayAttributeSignal from ophyd.signal
  • Loading branch information
licode authored Nov 26, 2018
2 parents 4023ec0 + 51c62f1 commit bb6255a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 73 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ before_install:
install:
- conda install numpy pyepics prettytable ipython pip
# install ophyd and the hkl library
# TODO : this has a gsl2.2.1 dep
- conda install ophyd gsl=2.2.1 # missing dep?
- conda install pygobject3==3.18.2
- conda install ophyd gsl
- conda install pygobject
- conda install hkl libiconv
# mkl-random 1.0.1 requires cython, which is not installed.
- pip install cython
Expand Down
72 changes: 2 additions & 70 deletions hkl/diffract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,13 @@
from ophyd import (Signal, PseudoPositioner, Component as Cpt)
from ophyd.pseudopos import (pseudo_position_argument, real_position_argument)
from ophyd.utils.epics_pvs import (data_type, data_shape)

from ophyd.ophydobj import OphydObject, Kind
from ophyd.signal import AttributeSignal, ArrayAttributeSignal
from . import calc

logger = logging.getLogger(__name__)


class AttributeSignal(Signal):
'''Signal derived from a Python object instance's attribute
Parameters
----------
attr : str
The dotted attribute name, relative to this signal's parent.
name : str, optional
The signal name
parent : Device, optional
The parent device instance
'''
def __init__(self, attr, *, name=None, parent=None):
super().__init__(name=name, parent=parent)

if '.' in attr:
self.attr_base, self.attr = attr.rsplit('.', 1)
else:
self.attr_base, self.attr = None, attr

@property
def full_attr(self):
'''The full attribute name'''
if not self.attr_base:
return self.attr
else:
return '.'.join((self.attr_base, self.attr))

@property
def base(self):
'''The parent instance which has the final attribute'''
if self.attr_base is None:
return self.parent

obj = self.parent
for i, part in enumerate(self.attr_base.split('.')):
try:
obj = getattr(obj, part)
except AttributeError as ex:
attr = '.'.join(self.parent_attr[:i + 1])
raise AttributeError('{} ({})'.format(attr, ex))

return obj

def get(self, **kwargs):
return getattr(self.base, self.attr)

def put(self, value, **kwargs):
return setattr(self.base, self.attr, value)

def describe(self):
value = self.value
desc = {'source': 'PY:{}.{}'.format(self.parent.name, self.full_attr),
'dtype': data_type(value),
'shape': data_shape(value),
}
return {self.name: desc}


class ArrayAttributeSignal(AttributeSignal):
'''An AttributeSignal which is cast to an ndarray on get
This is used where data_type and data_shape may otherwise fail to determine
how to store the data into metadatastore.
'''
def get(self, **kwargs):
return np.asarray(super().get(**kwargs))


class Diffractometer(PseudoPositioner):
'''Diffractometer pseudopositioner
Expand Down

0 comments on commit bb6255a

Please sign in to comment.