How to use the datashader.sum function in datashader

To help you get started, we’ve selected a few datashader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lmcinnes / umap / umap / plot.py View on Github external
extent = _get_extent(points)
    canvas = ds.Canvas(plot_width=width,
                       plot_height=height,
                       x_range=(extent[0], extent[1]),
                       y_range=(extent[2], extent[3]))

    if edge_bundling is None:
        edges = bd.directly_connect_edges(point_df, edge_df, weight='weight')
    elif edge_bundling == 'hammer':
        warn('Hammer edge bundling is expensive for large graphs!\n'
             'This may take a long time to compute!')
        edges = bd.hammer_bundle(point_df, edge_df, weight='weight')
    else:
        raise ValueError('{} is not a recognised bundling method'.format(edge_bundling))

    edge_img = tf.shade(canvas.line(edges, 'x', 'y', agg=ds.sum('weight')),
                        cmap=plt.get_cmap(edge_cmap), how=edge_how)
    edge_img = tf.set_background(edge_img, background)

    if show_points:
        point_img = _datashade_points(points, None, labels, values, cmap, color_key,
                                      color_key_cmap, None, width, height)
        if px_size > 1:
            point_img = tf.dynspread(point_img, threshold=0.5, max_px=px_size)
        result = tf.stack(edge_img, point_img, how="over")
    else:
        result = edge_img

    font_color = _select_font_color(background)

    dpi = plt.rcParams['figure.dpi']
    fig = plt.figure(figsize=(width / dpi, height / dpi))
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
def applies(cls, element, agg_fn):
        return (isinstance(element, NdOverlay) and
                ((isinstance(agg_fn, (ds.count, ds.sum, ds.mean)) and
                  (agg_fn.column is None or agg_fn.column not in element.kdims)) or
                 (isinstance(agg_fn, ds.count_cat) and agg_fn.column in element.kdims)))
github holoviz / datashader / examples / dashboard / dashboard.py View on Github external
def __init__(self, config_file, outofcore, app_port):

        self.load_config_file(config_file)
        self.plot_height = 600
        self.plot_width = 990

        self.aggregate_functions = OrderedDict()
        self.aggregate_functions['Count'] = ds.count
        self.aggregate_functions['Mean'] = ds.mean
        self.aggregate_functions['Sum'] = ds.sum
        self.aggregate_functions['Min'] = ds.min
        self.aggregate_functions['Max'] = ds.max
        self.agg_function_name = list(self.aggregate_functions.keys())[0]

        # transfer function configuration
        self.transfer_functions = OrderedDict()
        self.transfer_functions['Histogram Equalization'] = 'eq_hist'
        self.transfer_functions['Linear'] = 'linear'
        self.transfer_functions['Log'] = 'log'
        self.transfer_functions[u"\u221B - Cube Root"] = 'cbrt'
        self.transfer_function = list(self.transfer_functions.values())[0]

        self.basemaps = OrderedDict()
        self.basemaps['Imagery'] = ('http://server.arcgisonline.com/arcgis'
                                    '/rest/services/World_Imagery/MapServer'
                                    '/tile/{Z}/{Y}/{X}.png')
github pyviz-dev / nbsite / examples / sites / holoviews / holoviews / operation / datashader.py View on Github external
grouped = element
            else:
                grouped = element.groupby([agg_fn.column], container_type=NdOverlay,
                                          group_type=NdOverlay)
            return grouped.clone({k: agg_fn1(v) for k, v in grouped.items()})

        # Create aggregate instance for sum, count operations, breaking mean
        # into two aggregates
        column = agg_fn.column or 'Count'
        if isinstance(agg_fn, ds.mean):
            agg_fn1 = aggregate.instance(**dict(agg_params, aggregator=ds.sum(column)))
            agg_fn2 = aggregate.instance(**dict(agg_params, aggregator=ds.count()))
        else:
            agg_fn1 = aggregate.instance(**agg_params)
            agg_fn2 = None
        is_sum = isinstance(agg_fn1.aggregator, ds.sum)

        # Accumulate into two aggregates and mask
        agg, agg2, mask = None, None, None
        mask = None
        for v in element:
            # Compute aggregates and mask
            new_agg = agg_fn1.process_element(v, None)
            if is_sum:
                new_mask = np.isnan(new_agg.data[column].values)
                new_agg.data = new_agg.data.fillna(0)
            if agg_fn2:
                new_agg2 = agg_fn2.process_element(v, None)

            if agg is None:
                agg = new_agg
                if is_sum: mask = new_mask
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
groups = []
            for k, v in grouped.items():
                agg = agg_fn1(v)
                groups.append((k, agg.clone(agg.data, bounds=bbox)))
            return grouped.clone(groups)

        # Create aggregate instance for sum, count operations, breaking mean
        # into two aggregates
        column = agg_fn.column or 'Count'
        if isinstance(agg_fn, ds.mean):
            agg_fn1 = aggregate.instance(**dict(agg_params, aggregator=ds.sum(column)))
            agg_fn2 = aggregate.instance(**dict(agg_params, aggregator=ds.count()))
        else:
            agg_fn1 = aggregate.instance(**agg_params)
            agg_fn2 = None
        is_sum = isinstance(agg_fn1.aggregator, ds.sum)

        # Accumulate into two aggregates and mask
        agg, agg2, mask = None, None, None
        mask = None
        for v in element:
            # Compute aggregates and mask
            new_agg = agg_fn1.process_element(v, None)
            if is_sum:
                new_mask = np.isnan(new_agg.data[column].values)
                new_agg.data = new_agg.data.fillna(0)
            if agg_fn2:
                new_agg2 = agg_fn2.process_element(v, None)

            if agg is None:
                agg = new_agg
                if is_sum: mask = new_mask
github pyviz-dev / nbsite / examples / sites / holoviews / holoviews / operation / datashader.py View on Github external
def _process(self, element, key=None):
        agg_fn = self.p.aggregator
        category = agg_fn.column if isinstance(agg_fn, ds.count_cat) else None

        if (isinstance(element, NdOverlay) and
            ((isinstance(agg_fn, (ds.count, ds.sum, ds.mean)) and agg_fn.column not in element.kdims) or
             (isinstance(agg_fn, ds.count_cat) and agg_fn.column in element.kdims))):
            return self._aggregate_ndoverlay(element, agg_fn)

        x, y, data, glyph = self.get_agg_data(element, category)
        (x_range, y_range), (xs, ys), (width, height), (xtype, ytype) = self._get_sampling(element, x, y)

        if x is None or y is None:
            xarray = xr.DataArray(np.full((height, width), np.NaN, dtype=np.float32),
                                  dims=['y', 'x'], coords={'x': xs, 'y': ys})
            return self.p.element_type(xarray)

        cvs = ds.Canvas(plot_width=width, plot_height=height,
                        x_range=x_range, y_range=y_range)

        column = agg_fn.column
        if column and isinstance(agg_fn, ds.count_cat):