🔍 Code Extractor

function dimensioned_streams

Maturity: 40

Filters and returns streams from a DynamicMap that have parameters matching the DynamicMap's key dimensions.

File:
/tf/active/vicechatdev/patches/util.py
Lines:
1967 - 1977
Complexity:
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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function drop_streams 75.1% similar

    Filters out dimensioned stream parameters from key dimensions (kdims) and their corresponding keys, returning cleaned dimensions and keys.

    From: /tf/active/vicechatdev/patches/util.py
  • function unbound_dimensions 74.2% similar

    Filters a list of dimensions (kdims) to return only those that have not been associated with any of the provided streams.

    From: /tf/active/vicechatdev/patches/util.py
  • function get_nested_streams 71.2% similar

    Recursively traverses a DynamicMap object to extract and return all unique Stream objects found within it and its nested DynamicMaps.

    From: /tf/active/vicechatdev/patches/spaces.py
  • function dimensionless_contents 69.7% similar

    Filters stream parameters to return only those that are not associated with any of the provided key dimensions.

    From: /tf/active/vicechatdev/patches/util.py
  • class DynamicMap 61.2% similar

    A DynamicMap is a type of HoloMap where the elements are dynamically generated by a callable. The callable is invoked with values associated with the key dimensions or with values supplied by stream parameters.

    From: /tf/active/vicechatdev/patches/spaces.py
← Back to Browse