percival.detector
package¶
percival.detector.interface
module¶
The detector interface module contains a number of abstract interface definitions which are to be implemented by classes that support control and communication with detectors.
The interface classes do not implement any real functionality, but are used to define the methods (and their args) and properties, required to support a certain interface.
The interface classes rely on the python abc
module to support Abstract Base
Classes
Example use of interfaces¶
from __future__ import unicode_literals, print_function
try:
from pkg_resources import require
require('numpy')
require('future')
except:
pass # not everyone use setuptools and that is OK...
from percival.detector.interface import IDetector
class MyDetector( object ):
exposure = 0.1
def acquire( self, exposure, nframes=1, dac=42 ):
print("Acquiring...")
# Register MyDetector to as implementing the IDetector interface
IDetector.register( MyDetector )
# Verify the implementation of the IDetector interface in MyDetector
print("MyDetector provides IDetector: ", issubclass( MyDetector, IDetector ))
# Create an instance of MyDetector
det = MyDetector()
# Verify that the det object implements the IDetector interface
print("det implements IDetector: ", isinstance( det, IDetector ))
-
class
percival.detector.interface.
IABCMeta
[source]¶ Abstract Base Meta Class which implements checking for required methods and properties, even when the class is not directly subclassed. The Interface class which uses this metaclass will need to define a property called
_iface_requirements
which is a list of properties that must be implemented.This class is intended to work together with the
abc.ABCMeta
class: SubclassIABCMeta
into your own class and set the__metaclass__
=abc.ABCMeta
The__subclasshook__()
will automatically be called when a class interface need to be verified.
percival.detector.parameter
module¶
Support for observable parameters.
When using Observable
it is possible to register observers
for notifications (callbacks) on change of data values.
The implementation is thread safe by using python threading locks.
-
class
percival.detector.parameter.
Observable
(name)[source]¶ An observable implemented as a python Descriptor.
Use the
Observable.subscribe()
to register for notification updates.Note: The business logic is deferred to the Observable.__ObservableValue__
class inself.observable_value
.-
subscribe
(obsv, exception_handler=None)[source]¶ Add a subscriber to be notified on change of value in the Observable.
Parameters: - obsv (a callable or another
Observable
object. The callable must accept one argument which is the updated value.) – Observer to be notified of change. - exception_handler (callable with one argument which is the raised exception) – An exception handler or None
Return type: Observable._NotifySubscription
object. Hang on to this object for as long as notification updates are required. When this object is finalised, the notification updates will be cancelled.- obsv (a callable or another
-
-
percival.detector.parameter.
threadsafe
(lockname)[source]¶ A decorator to acquire and release a lock around a method call.
Use this to provide thread safe implementation of methods. It is not necessarily the most efficient use of locking, but for simple cases it does the job in an unintrusive fashion.