Stream manipulation¶
Manipulate MorphoCut streams and show diagnostic information.
-
morphocut.stream.
Enumerate
(start=0)[source]¶ Enumerate objects in the
Stream
.- Parameters
start (int, default 0) – Start value of the counter.
- Returns
Variable[int] – Index (from start).
-
morphocut.stream.
Filter
(function)[source]¶ Stream Filter objects in the
Stream
.After this node, the stream will only contain objects for which function evaluates to True.
- Parameters
function (Callable) – A callable recieving a
StreamObject
and returning a bool.
-
morphocut.stream.
FilterVariables
(*variables)[source]¶ Only keep the specified Variables in the stream.
This might speed up processing, especially when
StreamObject
s have to be sent to other processes.
-
morphocut.stream.
Pack
(size, *variables)[source]¶ Pack values of subsequent objects in the stream into one tuple.
- Parameters
size (int or Variable) – Number of objects to aggregate.
*variables (Variable) – Variables to pack.
- Returns
One or more Variable – One output Variable per input Variable.
Example
with Pipeline() as p: a = Unpack([1,2,3]) # The stream now consists of three objects: # {a: 1}, {a: 2}, {a: 3} a123 = Pack(3, a) # The stream now consists one object: # {a: 1, a123: (1,2,3)}
See also
-
morphocut.stream.
PrintObjects
(*args)[source]¶ Print the contents of
StreamObject
s.For debugging purposes only.
- Parameters
*args (Variable) – Variables to display.
-
morphocut.stream.
Slice
(*args)[source]¶ Stream Slice the
Stream
.Filter objects in the
Stream
based on their index.- Parameters
start (int, optional) – Skip this many objects upfront.
stop (int, optional) – Stop at this index.
step (int, optional) – Skip this many objects in every step.
-
morphocut.stream.
StreamBuffer
(maxsize)[source]¶ Buffer the stream.
- Parameters
maxsize (int) – Maximum size of the buffer.
This allows continued processing while I/O bound Nodes wait for data.
-
morphocut.stream.
TQDM
(description=None, monitor_interval=None)[source]¶ Show a dynamically updating progress bar using tqdm.
Note
The external dependency tqdm is required to use this Node.
- Parameters
description (str) – Description of the progress bar.
Example
with Pipeline() as pipeline: TQDM("Description")
Output: Description|███████████████████████| [00:00, 2434.24it/s]
-
morphocut.stream.
Unpack
(iterable)[source]¶ Stream Unpack values from an iterable into the
Stream
.The result is basically the cross-product of the stream with the iterable.
- Parameters
iterable (Iterable or Variable) – An iterable to unpack.
- Returns
Variable – One value from the iterable.
Example
with Pipeline() as p: a = Unpack([1,2,3]) # The stream now consists of three objects: # {a: 1}, {a: 2}, {a: 3} b = Unpack([1,2,3]) # The stream now consists of nine objects: # {a: 1, b: 1}, {a: 1, b: 2}, {a: 1, b: 3}, # {a: 2, b: 1}, {a: 2, b: 2}, {a: 2, b: 3}, # {a: 3, b: 1}, {a: 3, b: 2}, {a: 3, b: 3}
See also