fastplotlib.NDSlicer#

class NDSlicer(data, dims, display_dims, slider_maps=None, window_funcs=None, window_order=None, spatial_func=None)[source]#

Base class for managing n-dimensional data and producing array slices.

Wraps array-like data and provides an interface for indexing slider dimensions, applying window functions, spatial functions, and mapping reference-space values to local array indices. Subclasses must implement get(), which is called when the ReferenceIndex updates.

Subclasses can implement any type of data representation, they do not necessarily need to be array-like. However their get() method must still return a data slice that corresponds to the graphical representation they map to.

Every dimension that is not listed in display_dims becomes a slider dimension. Each slider dim must have a ReferenceRange defined in the ReferenceIndex of the parent NDWidget. The widget uses this to direct a change in the ReferenceIndex and update the graphics.

Parameters:
  • data (ArrayProtocol) – data object that is managed, usually uses the ArrayProtocol. Custom subclasses can manage any kind of data object but the corresponding get() must return an array-like that maps to a graphical representation.

  • dims (Sequence[str]) –

    names for each dimension in data. Dimensions not listed in display_dims are treated as slider dimensions and must appear as keys in the parent NDWidget’s ref_ranges

    Examples:

    ("time", "depth", "row", "col")
    ("channels", "time", "xy")
    ("keypoints", "time", "xyz")
    

    A custom subclass’s data object doesn’t necessarily need to have these dims, but the get() method must operate as if these dimensions exist and return an array that matches the spatial dimensions.

  • display_dims (Sequence[str]) – Subset of dims that are spatial (rendered) dimensions in display order. All remaining dims are treated as slider dims. See subclass for specific info.

  • slider_maps (dict mapping dim_name -> Callable, an ArrayLike, or None) –

    Per-slider-dim mapping from reference-space values to local array indices.

    You may also provide an array of reference values for the slider dims, searchsorted is then used as the transform (ex: a timestamps array).

    If None and identity mapping is used, i.e. rounds the current reference index value to the nearest integer for array indexing.

    If a transform is not provided for a dim then the identity mapping is used.

  • window_funcs (dict[) – str, tuple[WindowFuncCallable | None, int | float | None]

  • ]

    Per-slider-dim window functions applied around the current slider position. Ex: {“time”: (np.mean, 2.5)}. Each value is a (func, window_size) pair where:

    • func must accept axis: int and keepdims: bool kwargs (ex: np.mean, np.max). The window function must return an array that has the same dimensions as specified in the NDSlicer, therefore the size of any dim along which a window_func was applied should reduce to 1. These dims must not be removed by the window_func.

    • window_size is in reference-space units (ex: 2.5 seconds).

window_order: tuple[str, …]

Order in which window functions are applied across dims. Only dims listed here have their window function applied. window_funcs are ignored for any dims not specified in window_order

spatial_func:

A function applied to the spatial slice after window_funcs right before rendering. It is given the slice in display_dims order, i.e. the array as it is rendered, and must return an array with those same dims.