From 7eb9223d4f9f253bf8b0a029eb18f5677b448e03 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Thu, 1 Sep 2022 12:52:46 +0200 Subject: [PATCH] Ensure rectilinear rasters support geometry selections --- holoviews/core/data/xarray.py | 4 ++++ holoviews/element/raster.py | 4 +++- holoviews/element/selection.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/holoviews/core/data/xarray.py b/holoviews/core/data/xarray.py index 4971538b8c..4313a8d51e 100644 --- a/holoviews/core/data/xarray.py +++ b/holoviews/core/data/xarray.py @@ -422,6 +422,10 @@ def values(cls, dataset, dim, expanded=True, flat=True, compute=True, keep_index return data.T.flatten() if flat and not keep_index else data elif expanded: data = cls.coords(dataset, dim.name, expanded=True) + if keep_index: + da = dataset.data[dataset.vdims[0].name].copy().rename(dim.name) + da.data[:] = data + return da return data.T.flatten() if flat else data else: if keep_index: diff --git a/holoviews/element/raster.py b/holoviews/element/raster.py index 16e596b92e..8089d43479 100644 --- a/holoviews/element/raster.py +++ b/holoviews/element/raster.py @@ -403,7 +403,7 @@ def aggregate(self, dimensions=None, function=None, spreadfn=None, **kwargs): agg = super().aggregate(dimensions, function, spreadfn, **kwargs) return Curve(agg) if isinstance(agg, Dataset) and len(self.vdims) == 1 else agg - def select(self, selection_specs=None, **selection): + def select(self, selection_expr=None, selection_specs=None, **selection): """ Allows selecting data by the slices, sets and scalar values along a particular dimension. The indices should be supplied as @@ -413,6 +413,8 @@ def select(self, selection_specs=None, **selection): supplied, which will ensure the selection is only applied if the specs match the selected object. """ + if selection_expr is not None: + return super().select(selection_expr, selection_specs, **selection) if selection_specs and not any(self.matches(sp) for sp in selection_specs): return self diff --git a/holoviews/element/selection.py b/holoviews/element/selection.py index 773ca059e9..f8c921cfec 100644 --- a/holoviews/element/selection.py +++ b/holoviews/element/selection.py @@ -73,7 +73,7 @@ def spatial_select_gridded(xvals, yvals, geometry): target = Image((xs, ys, np.empty(ys.shape+xs.shape))) poly = Polygons([geometry]) mask = rasterize(poly, target=target, dynamic=False, aggregator='any') - return mask.dimension_values(2, flat=False) + return mask.interface.values(mask, mask.vdims[0], keep_index=True) else: mask = spatial_select_columnar(xvals.flatten(), yvals.flatten(), geometry) return mask.reshape(xvals.shape)