@@ -411,6 +411,8 @@ def __init__(self, buffer_length=0, **kwargs):
411411 self ._acquiring = False
412412 # A condition to signal arrival of a new data and unblock grab_next_data
413413 self ._new_data_condition = threading .Condition ()
414+ # A data processing pipeline: a list of f(data) -> data.
415+ self .pipeline = []
414416
415417 def __del__ (self ):
416418 self .disable ()
@@ -483,8 +485,12 @@ def _fetch_data(self):
483485 return None
484486
485487 def _process_data (self , data ):
486- """Do any data processing and return data."""
487- return data
488+ """Do any data processing and return data.
489+
490+ Subclasses should call super()._process_data(data) after doing their
491+ own processing."""
492+ import functools
493+ return functools .reduce (lambda x , f : f (x ), self .pipeline , data )
488494
489495 def _send_data (self , client , data , timestamp ):
490496 """Dispatch data to the client."""
@@ -669,18 +675,19 @@ def __init__(self, **kwargs):
669675 self .get_roi ,
670676 self .set_roi ,
671677 None )
678+
672679 def _process_data (self , data ):
673680 """Apply self._transform to data."""
674681 flips = (self ._transform [0 ], self ._transform [1 ])
675682 rot = self ._transform [2 ]
676683
677684 # Choose appropriate transform based on (flips, rot).
678- return {(0 , 0 ): numpy .rot90 (data , rot ),
679- (0 , 1 ): numpy .flipud (numpy .rot90 (data , rot )),
680- (1 , 0 ): numpy .fliplr (numpy .rot90 (data , rot )),
681- (1 , 1 ): numpy .fliplr (numpy .flipud (numpy .rot90 (data , rot )))
682- }[flips ]
683-
685+ data = {(0 , 0 ): numpy .rot90 (data , rot ),
686+ (0 , 1 ): numpy .flipud (numpy .rot90 (data , rot )),
687+ (1 , 0 ): numpy .fliplr (numpy .rot90 (data , rot )),
688+ (1 , 1 ): numpy .fliplr (numpy .flipud (numpy .rot90 (data , rot )))
689+ }[flips ]
690+ return super (). _process_data ( data )
684691
685692 def set_readout_mode (self , description ):
686693 """Set the readout mode and _readout_transform."""
0 commit comments