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
dataand provides an interface for indexing slider dimensions, applying window functions, spatial functions, and mapping reference-space values to local array indices. Subclasses must implementget(), which is called when theReferenceIndexupdates.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_dimsbecomes a slider dimension. Each slider dim must have aReferenceRangedefined in theReferenceIndexof the parentNDWidget. The widget uses this to direct a change in theReferenceIndexand 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 indisplay_dimsare treated as slider dimensions and must appear as keys in the parentNDWidget’sref_rangesExamples:
("time", "depth", "row", "col") ("channels", "time", "xy") ("keypoints", "time", "xyz")
A custom subclass’s
dataobject doesn’t necessarily need to have these dims, but theget()method must operate as if these dimensions exist and return an array that matches the spatial dimensions.display_dims (Sequence[str]) – Subset of
dimsthat 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,
searchsortedis then used as the transform (ex: a timestamps array).If
Noneand 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: intandkeepdims: boolkwargs (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 to1. 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_dimsorder, i.e. the array as it is rendered, and must return an array with those same dims.