def PrimaryFilteringStream(): ''' Filter the stream for just primary results. **Stream Inputs** md : dict No requirements data : dict must have a 2D np.ndarray with one of accepted detector keys **Stream Outputs** Two streams are outputted, sout and serr sout : the stream with valid data Outputs from zero to any number streams (depends on how many detectors were found) md : detector_key : the detector key (string) data : data with only one image as detector key if there was more than one, it selects one of them Note this has unspecified behaviour. serr : the stream with bad data. This can be sinked to an error stream Examples -------- >>> # A typical workflow is as follows: >>> # instantiate the main stream input >>> from streamz import Stream >>> s = Stream() >>> # create the filtering stream >>> from SciStreams.streams.XS_Streams import PrimaryFilteringStream >>> sin, sout = PrimaryFilteringStream() >>> s.connect(sin) >>> import numpy as np >>> # create dummy detector image, from pilatus300 >>> img = np.random.random((619, 487)) >>> from SciStreams.core.StreamDoc import StreamDoc >>> sdoc = StreamDoc(kwargs=dict(pilatus300_image=img)) >>> # save result in a list L that you can review later >>> L = sout.sink_to_list() >>> # emit the data >>> s.emit(sdoc) Returns ------- sin : Stream instance the source stream (see Stream Inputs) sout : Stream instance the output stream (see Stream Outputs) ''' sin = sc.Stream(stream_name="Primary Filter") # a primary filter, data will not go through if does not match attributes sout = sin.filter(filter_attributes) # get the error streams attributes (to output to some log) serr = sin.filter(lambda x: not filter_attributes) serr = scs.get_attributes(serr) serr = scs.add_attributes(serr, error="primary_filter") sout = sc.map(sout, pick_allowed_detectors) # turn list into individual streams # (if empty list, emits nothing, this is sort of like filter) sout = sout.concat() # just some checks to see if it's good data, else ignore return sin, sout, serr
def clear_attributes(child): return streamz.map(child, StreamDoc_core.clear_attributes)
def to_attributes(child): ''' send a function's args and kwargs to attributes, also clearing the args and kwargs''' return streamz.map(child, StreamDoc_core.to_attributes)
def get_attributes(child): return streamz.map(child, StreamDoc_core.get_attributes)
def add_attributes(child, **kwargs): return streamz.map(child, StreamDoc_core.add_attributes, attributes=kwargs)
def merge(child): return streamz.map(child, StreamDoc_core.merge)
def select(child, *mapping): return streamz.map(child, StreamDoc_core.select, *mapping)
def squash(child): return streamz.map(child, StreamDoc_core.squash)