Skip to content

Commit

Permalink
Allow aggregate to rasterize to target Image gridding
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 2, 2017
1 parent 295f54c commit 437cb62
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class aggregate(Operation):
y_sampling = param.Number(default=None, doc="""
Specifies the smallest allowed sampling interval along the y-axis.""")

target = param.ClassSelector(class_=Image, doc="""
A target Image which defines the desired x_range, y_range,
width and height.
""")

streams = param.List(default=[PlotSize, RangeXY], doc="""
List of streams that are applied if dynamic=True, allowing
for dynamic interaction with the plot.""")
Expand Down Expand Up @@ -276,11 +281,20 @@ def _process(self, element, key=None):
dims=['y', 'x'], coords={'x': xc, 'y': yc})
return self.p.element_type(xarray)

xstart, xend = self.p.x_range if self.p.x_range else data.range(x)
ystart, yend = self.p.y_range if self.p.y_range else data.range(y)
if self.p.target:
target = self.p.target
xs, ys = (target.dimension_values(i, expanded=False)
for i in range(2))
x_range, y_range = ((xs.min(), xs.max()+(1/target.xdensity)),
(ys.min(), ys.max()+(1/target.ydensity)))
height, width = target.dimension_values(2, flat=False).shape
else:
x_range = self.p.x_range or element.range(0)
y_range = self.p.y_range or element.range(1)
width, height = self.p.width, self.p.height
(xstart, xend), (ystart, yend) = x_range, y_range

# Compute highest allowed sampling density
width, height = self.p.width, self.p.height
if self.p.x_sampling:
x_range = xend - xstart
width = int(min([(x_range/self.p.x_sampling), width]))
Expand All @@ -303,12 +317,16 @@ def _process(self, element, key=None):

agg = getattr(cvs, glyph)(data, x, y, self.p.aggregator)
if agg.ndim == 2:
return self.p.element_type(agg, **params)
# Replace x and y coordinates
data = (xs, ys, agg.data) if self.p.target else agg
return self.p.element_type(data, **params)
else:
return NdOverlay({c: self.p.element_type(agg.sel(**{column: c}),
**params)
for c in agg.coords[column].data},
kdims=[data.get_dimension(column)])
layers = {}
for c in agg.coords[column].data:
cagg = agg.sel(**{column: c})
data = (xs, ys, cagg.data) if self.p.target else cagg
layers[c] = self.p.element_type(data, **params)
return NdOverlay(layers, kdims=[data.get_dimension(column)])



Expand Down

0 comments on commit 437cb62

Please sign in to comment.