Summary
VertexRGB cannot be rendered when the channels are multiframe (shape (T, V)) and contain NaNs. The auto-created alpha is constructed as 1-D (V,), but the NaN mask derived from the channels is 2-D (T, V), so indexing fails.
This is an edge case — RGB movies are uncommon — but the failure mode is an unhandled IndexError rather than a clear error or correct behavior, so worth tracking.
Reproducer
import numpy as np
import cortex
T, V = 5, cortex.db.get_surf("S1", "fiducial", merge=True)[0].shape[0]
rng = np.random.default_rng(0)
r = rng.uniform(0, 1, (T, V))
g = rng.uniform(0, 1, (T, V))
b = rng.uniform(0, 1, (T, V))
# inject NaNs in one channel
r[rng.random((T, V)) < 0.2] = np.nan
vrgb = cortex.VertexRGB(r, g, b, "S1")
cortex.webgl.show(vrgb) # raises
Traceback
File ".../cortex/dataset/viewRGB.py", line 860, in alpha
alpha.data[mask] = alpha.vmin
~~~~~~~~~~^^^^^^
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
Root cause
In cortex/dataset/viewRGB.py (VertexRGB.alpha property, ~lines 842–863):
@property
def alpha(self):
alpha = self._alpha
if alpha is None:
alpha = np.ones(self.red.vertices.shape[1]) # 1-D, length V only
alpha = Vertex(alpha, self.red.subject, vmin=0, vmax=1)
...
rgb = np.array([self.red.data, self.green.data, self.blue.data])
mask = np.isnan(rgb).any(axis=0) # (T, V) for multiframe
alpha.data[mask] = alpha.vmin # IndexError
For multiframe input each channel's .data is (T, V), so rgb is (3, T, V) and mask is (T, V). The auto-built alpha is shape (V,), hence the dimensionality mismatch.
Suggested fix
Build the auto-alpha with the same shape as the channel data, e.g.:
alpha = np.ones_like(self.red.data)
(or some equivalent that handles both 1-D and 2-D channel data). A regression test with a (T, V) VertexRGB containing NaNs would help.
Notes
Summary
VertexRGBcannot be rendered when the channels are multiframe (shape(T, V)) and contain NaNs. The auto-created alpha is constructed as 1-D(V,), but the NaN mask derived from the channels is 2-D(T, V), so indexing fails.This is an edge case — RGB movies are uncommon — but the failure mode is an unhandled
IndexErrorrather than a clear error or correct behavior, so worth tracking.Reproducer
Traceback
Root cause
In
cortex/dataset/viewRGB.py(VertexRGB.alphaproperty, ~lines 842–863):For multiframe input each channel's
.datais(T, V), sorgbis(3, T, V)andmaskis(T, V). The auto-builtalphais shape(V,), hence the dimensionality mismatch.Suggested fix
Build the auto-alpha with the same shape as the channel data, e.g.:
(or some equivalent that handles both 1-D and 2-D channel data). A regression test with a
(T, V)VertexRGB containing NaNs would help.Notes
VertexRGBwith NaNs works correctly: NaN vertices end up with alpha=0 (transparent), via the same code path. The bug is specifically the(T, V)shape.Vertex/Vertex2D(FIX NaN values in Volume/Vertex rendering as black instead of transparent #612, Vertex objects without nans are all transparent #626) — those go through the JS NaN-mask path, whileVertexRGBhandles NaN entirely in Python via the alpha channel.