Skip to content

Adds nd vector graphic#1034

Merged
kushalkolar merged 8 commits intondwidgetfrom
add_ndvector
Apr 15, 2026
Merged

Adds nd vector graphic#1034
kushalkolar merged 8 commits intondwidgetfrom
add_ndvector

Conversation

@apasarkar
Copy link
Copy Markdown
Collaborator

ND Vector graphic, useful for displaying slider-dimension varying vector fields. for my use case i'm primarily interested in showing piecewise rigid shifts. see below video for an example of what i'm doing. also see code snippet below for example of how to reproduce the video outputs.


height, width = 200, 200
start, stop, step = 0, 200, 10

# get uniform x, y positions
x, y = np.meshgrid(np.arange(start, stop, step), np.arange(start, stop, step))

x = x.ravel()
y = y.ravel()

num_pts = x.shape[0]
num_frames = 500

# positions of each vector as [n_points, 2] array
positions = np.column_stack([x, y])
positions = np.broadcast_to(positions[None, :, :], (num_frames, num_pts, positions.shape[1]))
# directions of each vector as a [n_points, 2] array
directions = np.random.rand(*positions.shape) 

data = np.stack([positions, directions], axis = -1)

img_data = np.random.rand(num_frames, height, width)



ref_range = {"time": (0, num_frames, 1)}
extents = {"raw data": (0, 1, 0, 1)}

np.random.rand
ndw = fpl.NDWidget(
    ref_range,
    extents=extents,
    names=[
        "raw data",
    ],
    controller_ids=[
        ["raw data"],
    ],
    size=(1200, 1200),
)

frame_timings = np.arange(num_frames)
movie_dims = ["time", "m", "n"]
movie_spatial_dims = ["m", "n"]
movie_index_mapping = {"time": frame_timings}
img_graphic = ndw["raw data"].add_nd_image(
    img_data,
    movie_dims,
    movie_spatial_dims,
    slider_dim_transforms=movie_index_mapping.copy(),
    name="raw img data",
)


vector_dims = ["time", "num vecs", "vec dim", "stack dim"]
spatial_dims = ["num vecs", "vec dim", "stack dim"]
vec_graphic = ndw['raw data'].add_nd_vector(data=data,
                                    dims=vector_dims,
                                    spatial_dims = spatial_dims,
                                    name='vec img data')


ndw.show()

Screen.Recording.2026-04-14.at.11.21.13.PM.mov

Copy link
Copy Markdown
Member

@kushalkolar kushalkolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, main comment is I think [n_vecs, pos/dir, xyz] is more intuitive and more similar to NDPositions

Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_ndw_subplot.py Outdated
Comment thread fastplotlib/graphics/features/_vectors.py
Comment thread fastplotlib/graphics/features/_vectors.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_ndw_subplot.py
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vector.py Outdated
Comment thread fastplotlib/widgets/nd_widget/__init__.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_ndw_subplot.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vectors.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vectors.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vectors.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vectors.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vectors.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vectors.py Outdated
Comment thread fastplotlib/widgets/nd_widget/_nd_vectors.py Outdated
Co-authored-by: Kushal Kolar <kushalkolar@gmail.com>
@kushalkolar kushalkolar merged commit 4c6769e into ndwidget Apr 15, 2026
@kushalkolar kushalkolar deleted the add_ndvector branch April 15, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants