Sampling

Different sampling strategies as well as reactor for coordinating sampling of multiple sensors each with different strategies.

class katcp.sampling.SampleAuto(inform_callback, sensor, *params)

Bases: katcp.sampling.SampleStrategy

Strategy which sends updates whenever the sensor itself is updated.

Methods

SampleAuto.attach()
SampleAuto.detach() Detach strategy from its sensor.
SampleAuto.get_sampling()
SampleAuto.get_sampling_formatted() Return the current sampling strategy and parameters.
SampleAuto.get_strategy(strategyName, ...) Factory method to create a strategy object.
SampleAuto.inform() Inform strategy creator of the sensor status.
SampleAuto.periodic(timestamp) This method is called when a period strategy is being configured or periodically after that.
SampleAuto.update(sensor)
class katcp.sampling.SampleDifferential(inform_callback, sensor, *params)

Bases: katcp.sampling.SampleStrategy

Differential sampling strategy for integer and float sensors.

Sends updates only when the value has changed by more than some specified threshold, or the status changes.

Methods

SampleDifferential.attach()
SampleDifferential.detach() Detach strategy from its sensor.
SampleDifferential.get_sampling()
SampleDifferential.get_sampling_formatted() Return the current sampling strategy and parameters.
SampleDifferential.get_strategy(...) Factory method to create a strategy object.
SampleDifferential.inform() Inform strategy creator of the sensor status.
SampleDifferential.periodic(timestamp) This method is called when a period strategy is being configured or periodically after that.
SampleDifferential.update(sensor)
class katcp.sampling.SampleEvent(inform_callback, sensor, *params)

Bases: katcp.sampling.SampleEventRate

Strategy which sends updates when the sensor value or status changes.

This implementation of the event strategy extends the KATCP guidelines to allow an optional minimum time between updates (in millseconds) to be specified as a parameter. If further sensor updates occur before this time has elapsed, no additional events are sent out.

Methods

SampleEvent.attach()
SampleEvent.detach() Detach strategy from its sensor.
SampleEvent.get_sampling()
SampleEvent.get_sampling_formatted() Return the current sampling strategy and parameters.
SampleEvent.get_strategy(strategyName, ...) Factory method to create a strategy object.
SampleEvent.inform() Inform strategy creator of the sensor status.
SampleEvent.periodic(timestamp)
SampleEvent.update(sensor[, now])
class katcp.sampling.SampleEventRate(inform_callback, sensor, *params)

Bases: katcp.sampling.SampleStrategy

Event rate sampling strategy.

Report the sensor value whenever it changes or if more than longest_period milliseconds have passed since the last reported update. However, do not report the value if less than shortest_period milliseconds have passed since the last reported update.

Methods

SampleEventRate.attach()
SampleEventRate.detach() Detach strategy from its sensor.
SampleEventRate.get_sampling()
SampleEventRate.get_sampling_formatted() Return the current sampling strategy and parameters.
SampleEventRate.get_strategy(strategyName, ...) Factory method to create a strategy object.
SampleEventRate.inform() Inform strategy creator of the sensor status.
SampleEventRate.periodic(timestamp)
SampleEventRate.update(sensor[, now])
class katcp.sampling.SampleNone(inform_callback, sensor, *params)

Bases: katcp.sampling.SampleStrategy

Sampling strategy which never sends any updates.

Methods

SampleNone.attach() Attach strategy to its sensor.
SampleNone.detach() Detach strategy from its sensor.
SampleNone.get_sampling()
SampleNone.get_sampling_formatted() Return the current sampling strategy and parameters.
SampleNone.get_strategy(strategyName, ...) Factory method to create a strategy object.
SampleNone.inform() Inform strategy creator of the sensor status.
SampleNone.periodic(timestamp) This method is called when a period strategy is being configured or periodically after that.
SampleNone.update(sensor) Callback used by the sensor’s notify method.
class katcp.sampling.SamplePeriod(inform_callback, sensor, *params)

Bases: katcp.sampling.SampleStrategy

Periodic sampling strategy.

For periodic sampling of any sensor.

Methods

SamplePeriod.attach() Attach strategy to its sensor.
SamplePeriod.detach() Detach strategy from its sensor.
SamplePeriod.get_sampling()
SamplePeriod.get_sampling_formatted() Return the current sampling strategy and parameters.
SamplePeriod.get_strategy(strategyName, ...) Factory method to create a strategy object.
SamplePeriod.inform() Inform strategy creator of the sensor status.
SamplePeriod.periodic(timestamp)
SamplePeriod.update(sensor) Callback used by the sensor’s notify method.
class katcp.sampling.SampleReactor(logger=<logging.Logger object at 0x19cdf10>)

Bases: katcp.core.ExcepthookThread

SampleReactor manages sampling strategies.

This class keeps track of all the sensors and what strategy is currently used to sample each one. It also provides a thread that calls periodic sampling strategies as needed.

Parameters :

logger : logging.Logger object

Python logger to write logs to.

Methods

SampleReactor.add_strategy(strategy) Add a sensor strategy to the reactor.
SampleReactor.getName()
SampleReactor.isAlive()
SampleReactor.isDaemon()
SampleReactor.is_alive()
SampleReactor.join([timeout])
SampleReactor.remove_strategy(strategy) Remove a strategy from the reactor.
SampleReactor.run() Run the sample reactor.
SampleReactor.setDaemon(daemonic)
SampleReactor.setName(name)
SampleReactor.start()
SampleReactor.stop() Send event to processing thread and wait for it to stop.
add_strategy(strategy)

Add a sensor strategy to the reactor.

Strategies should be removed using remove_strategy().

The new strategy is then attached to the sensor for updates and a periodic sample is triggered to schedule the next one.

Parameters :

strategy : SampleStrategy object

The sampling strategy to add to the reactor.

remove_strategy(strategy)

Remove a strategy from the reactor.

Strategies are added with add_strategy().

Parameters :

strategy : SampleStrategy object

The sampling strategy to remove from the reactor.

run()

Run the sample reactor.

stop()

Send event to processing thread and wait for it to stop.

class katcp.sampling.SampleStrategy(inform_callback, sensor, *params)

Bases: object

Base class for strategies for sampling sensors.

Parameters :

inform_callback : callable

Callback to send inform messages with, used as inform_callback(msg).

sensor : Sensor object

Sensor to sample.

params : list of objects

Custom sampling parameters.

Methods

SampleStrategy.attach() Attach strategy to its sensor.
SampleStrategy.detach() Detach strategy from its sensor.
SampleStrategy.get_sampling() Return the Strategy constant for this sampling strategy.
SampleStrategy.get_sampling_formatted() Return the current sampling strategy and parameters.
SampleStrategy.get_strategy(strategyName, ...) Factory method to create a strategy object.
SampleStrategy.inform() Inform strategy creator of the sensor status.
SampleStrategy.periodic(timestamp) This method is called when a period strategy is being configured or periodically after that.
SampleStrategy.update(sensor) Callback used by the sensor’s notify method.
attach()

Attach strategy to its sensor.

detach()

Detach strategy from its sensor.

get_sampling()

Return the Strategy constant for this sampling strategy.

Sub-classes should implement this method and return the appropriate constant.

Returns :

strategy : Strategy constant

The strategy type constant for this strategy.

get_sampling_formatted()

Return the current sampling strategy and parameters.

The strategy is returned as a string and the values in the parameter list are formatted as strings using the formatter for this sensor type.

Returns :

strategy_name : string

KATCP name for the strategy.

params : list of strings

KATCP formatted parameters for the strategy.

classmethod get_strategy(strategyName, inform_callback, sensor, *params)

Factory method to create a strategy object.

Parameters :

inform_callback : callable

Callback to send inform messages with, used as inform_callback(msg).

sensor : Sensor object

Sensor to sample.

params : list of objects

Custom sampling parameters.

Returns :

strategy : SampleStrategy object

The created sampling strategy.

inform()

Inform strategy creator of the sensor status.

periodic(timestamp)

This method is called when a period strategy is being configured or periodically after that.

Sub-classes should override this method or update() to provide the necessary sampling strategy.

Parameters :

timestamp : float in seconds

The time at which the next sample was requested.

Returns :

next_timestamp : float in seconds

The desired timestamp for the next sample.

update(sensor)

Callback used by the sensor’s notify method.

This update method is called whenever the sensor value is set so sensor will contain the right info. Note that the strategy does not really need to be passed sensor because it already has a handle to it but receives it due to the generic observer mechanism.

Sub-classes should override this method or periodic() to provide the necessary sampling strategy.

Parameters :

sensor : Sensor object

The sensor which was just updated.

Previous topic

Kattypes

Next topic

Tutorial

This Page