napari / napari

napari: a fast, interactive, multi-dimensional image viewer for python
https://napari.org
BSD 3-Clause "New" or "Revised" License
2.07k stars 410 forks source link

Empty timeframes in 4D vectors layers #6856

Open jo-mueller opened 4 weeks ago

jo-mueller commented 4 weeks ago

🐛 Bug Report

Minor thing what's been bugging me for some time: If a set of 4D vectors (vectors array of shape (N, 2, 4) and timepoints (1, 2, 3,4, 5)) is added to the napari viewer, the time sliders sets itself to double the amount of timepoints in the data, i.e., 10 timepoints.

💡 Steps to Reproduce

I used the latest napari version from main.

Script to reproduce:

import numpy as np
import napari

n_points = 100
n_timepoints = 5

vectors_base_points = np.random.rand(n_points, 4)
vectors_base_points[:, 0] = np.arange(n_timepoints).repeat(n_points // n_timepoints)
vector_directions = np.random.rand(n_points, 4)
vector_directions[:, 0] = np.arange(n_timepoints).repeat(n_points // n_timepoints)

# stack vectors into proper format
vectors = np.stack([vectors_base_points, vector_directions], axis=1)

viewer = napari.Viewer(ndisplay=3)
viewer.add_vectors(vectors)

print(viewer.dims)

would result into this, in my case:

> Dims(ndim=4, ndisplay=3, order=(0, 1, 2, 3), axis_labels=('0', '1', '2', '3'), rollable=(True, True, True, True), range=(RangeTuple(start=0.0, stop=8.0, step=1.0),, ...

clearly, this (RangeTuple(start=0.0, stop=8.0, step=1.0)) is not correct.

💡 Expected Behavior

I would expect the maximum timeframe to be the maximum number in the time column of the 4D data, i.e., max(vectors[:, 0, 0]) - in the example above that would be 4.

🌎 Environment

napari: 0.1.dev3361+gea9a516 Platform: Windows-10-10.0.19045-SP0 Python: 3.11.8 | packaged by conda-forge | (main, Feb 16 2024, 20:40:50) [MSC v.1937 64 bit (AMD64)] Qt: 5.15.8 PyQt5: 5.15.9 NumPy: 1.26.4 SciPy: 1.13.0 Dask: 2024.4.1 VisPy: 0.14.2 magicgui: 0.8.2 superqt: 0.6.3 in-n-out: 0.2.0 app-model: 0.2.6 npe2: 0.7.5

OpenGL:

Screens:

Optional:

Settings path:

💡 Additional Context

II tried to pinpoint the location where the dimensions are determined - if pointed to the correct place, I would be happy to send a PR with a fix :)