Raw metrics often need unit scaling, clamping, or conditional logic—such as converting bytes to gigabytes or milliseconds to seconds.
In SignalFlow, .map(lambda x: ...) applies a point-by-point transformation function to every datapoint in each MTS of a stream. Because SignalFlow uses Python-like lambda syntax, you can perform arithmetic scaling, conditional ternary checks (x if x is not None else 0), or value capping directly on the stream.
You can also combine multiple streams element-wise using standard operators (+, -, *, /) when both streams share compatible dimensions, such as computing memory utilization % = (memory_used / memory_total) * 100.
# Convert bytes to GiB and replace missing/null datapoints with 0
gib = data('memory.used').map(lambda x: (x / 1073741824) if x is not None else 0)
gib.publish(label='Memory Used (GiB)')