NDWidget - #971
NDWidget#971kushalkolar wants to merge 172 commits into
NDWidget#971Conversation
|
Got basic timeseries with linestack working. I've also got some code snippets for interpolating to display heatmap with non-uniformly sampled timeseries data. I should be able to have this fully working with time series very soon :D Kooha-2025-12-27-03-50-45.mp4 |
|
Got heatmap to display timeseries working. It should also work with non-uniformly sampled data by interpolating, need to test. Also need to implementing switching between heatmap and line representations, need to delete the graphic when switching. Kooha-2025-12-27-17-47-16.mp4 |
|
So timeseries can be represented with arrays of one of the following shapes (let's ignore x-axis values for now). If we have: l: number of timeseries We can have the following shapes: Extended to n-dimensional arrays (for example, trajectories projected onto principal components?). If each non-timeseries dim is I don't think we can auto-detect if
Scatters can be similar to some cases of nd-lines 🤔 , but x values would be directly specified and the current index is parametric (example with time indicating position in a low dim space). This would actually be true for lines as well if representing trajectories. So for nd-line maybe we have two versions, parametric (y and z are not functions of x, but x, y, z are a function of some other dim) and non-parametric (simple timeseries lines where y and z are functions of x). |
|
I made a more generalist
where: It can map arrays of these dims to a line, line collection, line stack, scatter, or list of scatters (similar to multi-line). I think this is a much more elegant way to deal with things, and Example if we have data that is I think we can also use this for heatmaps and interpolation. Use the reference units to determine a uniform x-range for the current display window, and we can interpolate using EDIT: I think that the |
|
For positions graphics, I should actually do |
|
Some more ideas: Allow any 2-3 dims to be used as the graphic dimensions and specify the slider dims. This would also allow using named dims (such as those used in xarray). We interpret the given order of the EDIT: A limitation of the above is that a user can't collapse multiple "graphic/display dimensions" into "final graphic/display dimensions" if they're hard-coded this like. So something like: An example for images would be collapsing |
|
We can use I was thinking of what's the best way to show a scatter for each keypoint, and I think I should make a |
|
ok I think stuff is working ndpositions-2026-01-29_22.55.54.mp4 |
|
I think I need to make a |
|
A set of imgui UIs that allow controlling some aspects of the "nd graphics" could be useful, such as:
|
Stuff I should finish before implementing the orchestrator:
Things that make me "uncomfortable" that I need to settle:dim shapesDim shape for nd-positions is
Do we just document this well, that the When using nd-positions data in conjunction with nd-image data, we'd have something like this: Where The |
|
Working on "implement mapping from a slider reference index with units (such as time) to array index.", which requires proper implementation of |
|
Window funcs working for ndp_windows-2026-02-01_03.39.52.mp4 |
* refactor cmap and cmap_transform for positional graphics * color mode stuff * WIP * more WIP * better add_graphic autogen * more progress * mostly done refactoring positions graphics cmap stuff * forgot to update mixin * cmap_transform tweaks * wip, JaggedArray * mostly works, writing tests * remove a print * image collection examples * fix * feature inheritance in PositionsGraphic and cmap_range * cmap handling * cmap tweaks * remove parse_cmap_values, rely on cmap lib * fix example, remove unused line of code * Image just uses cmap lib now too * delete_ndgraphic() * ndtimeseries cmap example * steps for stacks * ndtimeseries sets stack steps * docstrings * docstrings * comments * renames * docstring * fixes * update tests/test_colors_buffer_manager.py * update test_markers_buffer_manager.py * update plot_helpers test * update test_point_rotations_buffer_manager.py * update test_positions_graphics.py * update another test * more tests * update yet more tests * remove unused * infline tests * collections tests * updating examples, wip * more examples updates * more examples updates * more example updates * more example updates * example and docstring * docstring * remove complex line collection slicing example, stick with real usecases * better line stack example * update example * update example * update link * update more examples * examples and fixes * fix * more fixes * fix * updates * Fix * update docs * docs * add image collection to docs conf.py * update docs
* rename for consistency * more consistency * more * final renames * fix
…ims and no appended UIs
* basic scaffold done * inheritance * done * config works! * config on graphics * axes config * full config implementation basically works * fix * mixins call Graphic construtors with kwargs nothing is positional * print * config presets * comments, docstrings * docstrings * remove ConfigValue * comments * much better add graphics mixin using descriptors, examples, fix a test * anotehr example * GlobalConfig.to_dict() * docs * reset to default config after each screenshot test * add_<graphics>() stub generator, fix maintain_aspect logic w.r.t. config stuff * change so maintain_aspect can be tested better * docstring * reset config after running each docs gallery examle * better example * docs

Internals
RangeContinuous
Just a dataclass that stores the start, stop, and step of a reference range. A reference range is usually in scientific units, such as seconds/ms for time. Depth is another example of a reference range. A reference range just specifies the min and max of a dimension that will be used as a slider dimension. The imgui sliders use the reference range to determine the min, max, and step size of the UI elements (sliders, step-one button, etc.).
RangeDiscreteis mostly a placeholder for now, not fully implemented yet, waiting for a proper usecase. Genes might be an example? Session index for multi-session data could be another potential usecase.Users must define a reference range for every dimension they want to use as a slider dimension.
TODO: Would be useful to have an automatic reference range that's generated for a slider dimension when it's not specified. For example, sometimes you just want to dump a bunch of calcium arrays and look at them, and they're already in the same time-space. Could have a simple auto-reference range mode that just sets the min and max for eacher slider dim based on the current arrays in the
NDWidget.ReferenceIndex
This manages the reference index for an
NDWidget. It's the only place where indices should be set.TODO: pushing/popping reference ranges.
NDProcessor
This manages n-dimensional data of any type. Subclasses must implement a
get()method which takes a dict mapping dim names -> index for that dim. If specified, window functions are applied on slider dimensions._get_slider_dims_indexertakes the indices dict and outputs a dict of dim_names -> slice._apply_window_functions()uses these slices and applies the window functions. The final output after window functions has the same number of dims as the data, but with 1 element in any dimensions that were sliced (i.e. all slider dims, spatial dims remain untouched). In the end, theget()method must return an array that can be directly mapped to graphic data.Key properties in an
NDProcessor:data- usually an xarray, but subclasses can manage data that is of any type. The NDProcessorNDPP_Pandasfor positional data stored in a pandas dataframe is an example of this.shape,ndim,dims,spatial_dims,slider_dims- self explanatory, dims are always namedwindow_funcs- window functions, dict {dim_name: (func, window_size)}. A window function must takeaxisandkeep_dimsas kwargs.slider_dim_transforms- dict of functions for each slider dim that maps a reference range value to the local array index value. If a user doesn't provide a transform for a dim (for example, they just want to look at many arrays which are already in the same time-space, such as calcium movies) the it just uses an identify mapping.NDPositionsProcessorandNDImageProcessorhave logic specific to those types of data.NDPositionsProcessorhas an additionaldisplay_windowproperties which acts on thedatapointsdimension. Thedatapointsdim is also both a slider dim and spatial dim, but it is excluded forwindow_funcs.datapoints_window_funcis a separate property onNDPositionsProcessorthat applies window funcs for that dimension since it's a bit different from other slider dims.NDGraphic
A n-dimensional graphical representation. It has an
NDProcessorandfpl.Graphicthat it manages.ReferenceIndexsets the indices on anNDGraphic, which then callget()on itsNDProcessorto retrieve the new graphic data, and then sets it on the graphic. It has property aliases for the various processor properties, so that users can set window funcs, slider dim transforms, etc.NDPositionsandNDImageare twoNDGraphicsubclasses that have specific code for positional and image specific representations.NDPositionsalso manages a linear selector for timeseries representations, and allows swapping between scatter, line stack, line collection, and heatmap representations. It also manages an "auto x range" mode for timeseries representationsNDImagealso manages theHistogramLUTTooland swapping betweenImageGraphicandImageVolumeGraphic. It also sets the camera and controller when these are swapped.NDWSubplot
The main entry point for users to add
NDGraphicsto a subplot in anNDWidget. It mainly hasadd_nd<...>methods for users to provide data and kwargs to addNDGraphics.Need to cleanup this subclass so the args and kwargs for each add method are properly specified and documented.
NDWidget
Just a very simple class that has a
fpl.Figure, an instance ofReferenceIndex, and theNDWSubsplots.Very simplified diagram:
s1, ... snare slider dims,d1, d2, ...are spatial dims.User API
The user mainly interacts via the NDW subplots and
NDGraphics. For example with images:Positional data:
Main things left todo
NDProcessor.get()returns empty arraysReferenceIndexReferenceIndexto also ignore it.NDSubplot.delete_ndgraphic()NDSubplotas a subclass ofSubplotLineStackorScatterStacksdue to max y-value inpdimget()ReferenceIndex->ReferenceIndices, it manages multiple indicesref_indices->indices, keep constructor and properties symmetric like the rest of fplspatial_dims-> ???, see Includes basic np dlpack function that is tested to work across jax a… #1067 (comment)ImageWidgetwith almost same API built on top ofNDWidgetimplements #951