pytweezer.analysis.analysis_base module¶
Base classes for streaming analysis processes.
An analysis process is a small, long-lived program that subscribes to one or
more pub/sub streams, receives (message, head, data) messages in a loop,
transforms each one, and republishes the result on its own name. The existing
scripts in this package (data_average.py, imageselector.py,
subtract_bg.py, rotate_image.py) all hand-roll the same skeleton:
hold a
Propertiesconnection named after the process,declare the input streams as a
PropertyAttribute,create a client, subscribe, then loop
recv -> transform -> send.
This module factors that skeleton into AnalysisProcess, and captures
the only real differences between image and data analyses in two subclasses:
ImageAnalysis– uses anImageClient, subscribes to theimagestreamsproperty, and republishes on channel'_'.
DataAnalysis– uses aDataClient, subscribes to thedatastreamsproperty, and republishes on the default channel.
Both clients publish with the same client.send(header, data, channel=...)
order, so AnalysisProcess.send_result() is shared by both subclasses.
To write a new analysis, subclass one of the two and override process():
class ImageSlice(ImageAnalysis):
_index = PropertyAttribute('SelectedImage', 1)
def process(self, head, data):
if head['_imgindex'] == self._index:
return head, data # publish this one
return None # drop everything else
if __name__ == '__main__':
run_analysis(ImageSlice)
- class pytweezer.analysis.analysis_base.AnalysisProcess(name)[source]¶
Bases:
objectCommon skeleton for a streaming analysis process.
Subclasses supply the transport-specific pieces via the three hooks
make_client(),send_result()and the_streamsproperty, and the analysis-specific behaviour by overridingprocess().- Attributes set up by
__init__: name – the process name (also the Properties namespace / title). _props – the
Propertiesconnection. client – the pub/sub client (anImageClientorDataClient).
- Attributes set up by
- class pytweezer.analysis.analysis_base.DataAnalysis(name)[source]¶
Bases:
AnalysisProcessAnalysis process that consumes and republishes a data stream.
- class pytweezer.analysis.analysis_base.ImageAnalysis(name)[source]¶
Bases:
AnalysisProcessAnalysis process that consumes and republishes an image stream.