Simplest way to show 3D numpy cube

In the gridded dataset user_guide notebook, I’m missing an example, how to quickly show a 3D numpy cube, e.g. stacked 2D image data.
There’s only an example on how to show an xarray dataset, but i never can remember the syntax to create an xr.dataset, and I shouldn’t have to go via an xarray, when i simply can np.dstack() a bunch of image files?
There should be a direct way, shouldn’t there, where i can simply declare x,y,time as the key dimensions, but the holoviews syntax is still too nebulous for me to guess it on my own… :frowning:
If you tell me how it works, i’ll submit a PR extension to the gridded user_guide… :wink:

The syntax for creating multi-dimensional cubes in HoloViews is something like this:

# Declare coordinate arrays (i.e. kdims)
xs = np.arange(10)
ys = np.arange(20)
time = np.arange(30)

# Declare value array (i.e. the vdim)
values = np.random.rand(20, 10, 30)
hv.Dataset((time, xs, ys, values), ['time', 'x', 'y'], ['value'])

i.e. you provide a tuple of the coordinate arrays along with the value array(s). You could then group by the ‘time’ or ‘z’ dimension. Not also that if you remember this HoloViews can generate an xarray object for you:

ds = hv.Dataset((time, xs, ys, values), ['time', 'x', 'y'], ['value'], datatype=['xarray'])
ds.data # This is now an xr.Dataset

Hope that helps.

1 Like