Features

Features

Features in a model are those parameters that can be read, set, or both. They were modeled after Lantz Feat objects, and the idea is that they can encapsulate common patterns in device control. They are similar to Settings in behavior, except for the absence of a cache. Features do communicate with the device when reading a value.

For example, a feature could be the value of an analog input on a DAQ, or the temperature of a camera. They are meant to be part of a measurement, their values can change in loops in order to make a scan. Features can be used as decorators in pretty much the same way @propery can be used. The only difference is that they register themselves in the models properties object, so it is possible to update values either by submitting a value directly to the Feature or by sending a dictionary to the properties and updating all at once.

It is possible to mark a feature as a setting. In this case, the value will not be read from the device, but it will be cached. In case it is needed to refresh a value from the device, it is possible to use a specific argument, such as None. For example:

@Feature(setting=True, force_update_arg=0)
def exposure(self):
    self.driver.get_exposure()

@exposure.setter
def exposure(self, exposure_time):
    self.driver.set_exposure(exposure_time)

Todo

It is possible to define complex behavior such as unit conversion, limit checking, etc. We should narrow down what is appropriate for a model and what should go into the Controller.

Todo

A useful pattern is to catch the exception raised by the controllers if a value is out of range, or with the wrong units.

license:MIT, see LICENSE for more details
copyright:2020 Aquiles Carattino
class experimentor.models.feature.Feature(fget=None, fset=None, fdel=None, doc=None, **kwargs)[source]

Properties that belong to models. It makes easier the setting and getting of attributes, while at the same time it keeps track of the properties of each model. A Feature is, fundamentally, a descriptor, that extends some functionality by accepting keyword arguments when defining.

Todo

There is a lot of functionality that can be implemented, but that hasn’t yet, such as checking limits, unit conversion, etc.

name

The name of the feature, it must be unique since it will be used as a key in a dictionary.

Type:str
kwargs

If the feature is initialized with arguments, they will be stored here. Only keyword arguments are allowed.

Type:dict
deleter(fdel)[source]
getter(fget)[source]
kwargs = None
name = ''
setter(fset)[source]