Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop z dimension from ImageStack DataArray before shading #6378

Merged
merged 8 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions holoviews/core/data/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def retrieve_unit_and_label(dim):
if isinstance(data, xr.DataArray):
kdim_len = len(kdim_param.default) if kdims is None else len(kdims)
vdim_len = len(vdim_param.default) if vdims is None else len(vdims)
if vdim_len > 1 and kdim_len == len(data.dims)-1 and data.shape[-1] == vdim_len:
if kdim_len == len(data.dims)-1 and data.shape[-1] == vdim_len:
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
packed = True
elif vdims:
vdim = vdims[0]
Expand Down Expand Up @@ -446,7 +446,11 @@ def unpack_scalar(cls, dataset, data):
Given a dataset object and data in the appropriate format for
the interface, return a simple scalar.
"""
if not cls.packed(dataset) and len(data.data_vars) == 1:
if cls.packed(dataset):
array = data.squeeze()
if len(array.shape) == 0:
return array.item()
elif len(data.data_vars) == 1:
array = data[dataset.vdims[0].name].squeeze()
if len(array.shape) == 0:
return array.item()
Expand Down
21 changes: 17 additions & 4 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,10 +1289,23 @@ def _process(self, element, key=None):
kdims = element.kdims
if isinstance(element, ImageStack):
vdim = element.vdims
if element.interface.datatype != 'xarray':
element = element.clone(datatype=['xarray'])
array = element.data
if hasattr(array, "to_array"):
array = array.to_array("z")
array = array.transpose(*[kdim.name for kdim in kdims], ...)
# If data is a Dataset it has to be converted to a
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
# DataArray, either by selecting the singular value
# dimension or by adding a z-dimension
kdims = [kdim.name for kdim in kdims]
if not element.interface.packed(element):
if len(vdim) == 1:
array = array[vdim[0].name]
else:
array = array.to_array("z")
# If data is 3D then we have one extra constant dimension
if array.ndim > 3:
drop = [d for d in array.dims if d not in kdims+["z"]]
array = array.squeeze(drop)
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
array = array.transpose(*kdims, ...)
else:
vdim = element.vdims[0].name
array = element.data[vdim]
Expand Down Expand Up @@ -1335,7 +1348,7 @@ def _process(self, element, key=None):
if self.p.clims:
shade_opts['span'] = self.p.clims
elif ds_version > Version('0.5.0') and self.p.cnorm != 'eq_hist':
shade_opts['span'] = element.range(vdim)
shade_opts['span'] = (array.min(), array.max())
philippjfr marked this conversation as resolved.
Show resolved Hide resolved

params = dict(get_param_values(element), kdims=kdims,
bounds=bounds, vdims=RGB.vdims[:],
Expand Down
Loading