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

Lower cased and applied small fixes to datashader operations #907

Merged
merged 1 commit into from
Oct 6, 2016
Merged
Changes from all 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
35 changes: 23 additions & 12 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def dataset_pipeline(dataset, schema, canvas, glyph, summary):
kdims=[dataset.get_dimension(column)])


class Aggregate(ElementOperation):
class aggregate(ElementOperation):
"""
Aggregate implements 2D binning for any valid HoloViews Element
aggregate implements 2D binning for any valid HoloViews Element
type using datashader. I.e., this operation turns a HoloViews
Element or overlay of Elements into an hv.Image or an overlay of
hv.Images by rasterizing it, which provides a fixed-sized
Expand Down Expand Up @@ -182,9 +182,9 @@ def _process(self, element, key=None):



class Shade(ElementOperation):
class shade(ElementOperation):
"""
Shade applies a normalization function followed by colormapping to
shade applies a normalization function followed by colormapping to
an Image or NdOverlay of Images, returning an RGB Element.
The data must be in the form of a 2D or 3D DataArray, but NdOverlays
of 2D Images will be automatically converted to a 3D array.
Expand Down Expand Up @@ -231,6 +231,16 @@ def uint32_to_uint8(cls, img):
return np.flipud(img.view(dtype=np.uint8).reshape(img.shape + (4,)))


@classmethod
def rgb2hex(cls, rgb):
"""
Convert RGB(A) tuple to hex.
"""
if len(rgb) > 3:
rgb = rgb[:-1]
return "#{0:02x}{1:02x}{2:02x}".format(*(int(v*255) for v in rgb))


def _process(self, element, key=None):
if isinstance(element, NdOverlay):
bounds = element.last.bounds
Expand All @@ -253,12 +263,13 @@ def _process(self, element, key=None):
shade_opts['color_key'] = [c for i, c in
zip(range(categories), self.p.cmap)]
else:
shade_opts['color_key'] = [self.p.cmap(s) for s in
np.linspace(0, 1, categories)]
colors = [self.p.cmap(s) for s in np.linspace(0, 1, categories)]
shade_opts['color_key'] = map(self.rgb2hex, colors)
elif not self.p.cmap:
pass
elif isinstance(self.p.cmap, Callable):
shade_opts['cmap'] = [self.p.cmap(s) for s in np.linspace(0, 1, 256)]
colors = [self.p.cmap(s) for s in np.linspace(0, 1, 256)]
shade_opts['cmap'] = map(self.rgb2hex, colors)
else:
shade_opts['cmap'] = self.p.cmap

Expand All @@ -270,16 +281,16 @@ def _process(self, element, key=None):



class Datashade(Aggregate, Shade):
class datashade(aggregate, shade):
"""
Applies the Aggregate and Shade operations, aggregating all
Applies the aggregate and shade operations, aggregating all
elements in the supplied object and then applying normalization
and colormapping the aggregated data returning RGB elements.

See Aggregate and Shade operations for more details.
See aggregate and shade operations for more details.
"""

def _process(self, element, key=None):
aggregate = Aggregate._process(self, element, key)
shaded = Shade._process(self, aggregate, key)
aggregate = aggregate._process(self, element, key)
shaded = shade._process(self, aggregate, key)
return shaded