function dimensioned_streams
Filters and returns streams from a DynamicMap that have parameters matching the DynamicMap's key dimensions.
/tf/active/vicechatdev/patches/util.py
1967 - 1977
simple
Purpose
This function analyzes a DynamicMap object to identify which of its associated streams have parameters that are also defined as key dimensions of the DynamicMap. This is useful for determining which streams are 'dimensioned' - meaning they control parameters that directly correspond to the dimensional structure of the DynamicMap. This helps in understanding the relationship between stream parameters and the dimensional space of the visualization or data structure.
Source Code
def dimensioned_streams(dmap):
"""
Given a DynamicMap return all streams that have any dimensioned
parameters, i.e. parameters also listed in the key dimensions.
"""
dimensioned = []
for stream in dmap.streams:
stream_params = stream_parameters([stream])
if set([str(k) for k in dmap.kdims]) & set(stream_params):
dimensioned.append(stream)
return dimensioned
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
dmap |
- | - | positional_or_keyword |
Parameter Details
dmap: A DynamicMap object that contains streams and key dimensions (kdims). The function will examine this object's streams attribute and kdims attribute to find overlapping parameter names. Expected to be an instance of a DynamicMap class with 'streams' and 'kdims' attributes.
Return Value
Returns a list of stream objects from the input DynamicMap where at least one stream parameter name matches a key dimension name. If no streams have dimensioned parameters, returns an empty list. Each element in the returned list is a stream object that was originally attached to the input DynamicMap.
Dependencies
param
Required Imports
The function itself does not require explicit imports to run, but it depends on the 'stream_parameters' function being available in the same scope
The DynamicMap object passed as parameter must be from a library that implements this pattern (likely HoloViews)
Usage Example
# Assuming HoloViews context with DynamicMap and streams
import holoviews as hv
from holoviews.streams import Stream
# Create a simple stream with a parameter
class MyStream(Stream):
x = param.Number(default=0)
# Create a DynamicMap with 'x' as a key dimension
def my_function(x):
return hv.Curve([(0, x), (1, x+1)])
stream = MyStream()
dmap = hv.DynamicMap(my_function, kdims=['x'], streams=[stream])
# Get dimensioned streams
dim_streams = dimensioned_streams(dmap)
print(f"Dimensioned streams: {dim_streams}") # Will include MyStream since 'x' is both a kdim and stream parameter
Best Practices
- Ensure the DynamicMap object has properly initialized streams and kdims attributes before calling this function
- The function assumes stream_parameters() is available in scope - ensure this dependency is met
- This function performs string comparison of dimension names, so ensure consistent naming between stream parameters and key dimensions
- The function returns references to the original stream objects, not copies, so modifications to returned streams will affect the original DynamicMap
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function drop_streams 75.1% similar
-
function unbound_dimensions 74.2% similar
-
function get_nested_streams 71.2% similar
-
function dimensionless_contents 69.7% similar
-
class DynamicMap 61.2% similar