Beispiel #1
0
        def extend(aggs, xr_ds, vt, bounds):
            # Convert from bin centers to interval edges
            x_breaks = xr_ds[x_name].values
            x_breaks = infer_interval_breaks(x_breaks, axis=1)
            x_breaks = infer_interval_breaks(x_breaks, axis=0)

            y_breaks = xr_ds[y_name].values
            y_breaks = infer_interval_breaks(y_breaks, axis=1)
            y_breaks = infer_interval_breaks(y_breaks, axis=0)

            # Scale x and y vertices into integer canvas coordinates
            x0, x1, y0, y1 = bounds
            xspan = x1 - x0
            yspan = y1 - y0
            xscaled = (x_mapper(x_breaks) - x0) / xspan
            yscaled = (y_mapper(y_breaks) - y0) / yspan

            plot_height, plot_width = aggs[0].shape[:2]

            xs = (xscaled * plot_width).astype(int)
            ys = (yscaled * plot_height).astype(int)

            coord_dims = xr_ds.coords[x_name].dims
            aggs_and_cols = aggs + info(xr_ds.transpose(*coord_dims))
            _extend(plot_height, plot_width, xs, ys, *aggs_and_cols)
Beispiel #2
0
        def extend(aggs, xr_ds, vt, bounds):
            # Convert from bin centers to interval edges
            x_breaks = infer_interval_breaks(xr_ds[x_name].values)
            y_breaks = infer_interval_breaks(xr_ds[y_name].values)

            x0, x1, y0, y1 = bounds
            xspan = x1 - x0
            yspan = y1 - y0
            xscaled = (x_mapper(x_breaks) - x0) / xspan
            yscaled = (y_mapper(y_breaks) - y0) / yspan

            xmask = np.where((xscaled >= 0) & (xscaled <= 1))
            ymask = np.where((yscaled >= 0) & (yscaled <= 1))
            xm0, xm1 = max(xmask[0].min() - 1, 0), xmask[0].max() + 1
            ym0, ym1 = max(ymask[0].min() - 1, 0), ymask[0].max() + 1

            plot_height, plot_width = aggs[0].shape[:2]

            # Downselect xs and ys and convert to int
            xs = (xscaled[xm0:xm1 + 1] * plot_width).astype(int).clip(0, plot_width)
            ys = (yscaled[ym0:ym1 + 1] * plot_height).astype(int).clip(0, plot_height)

            # For input "column", down select to valid range
            cols_full = info(xr_ds.transpose(y_name, x_name))
            cols = tuple([c[ym0:ym1, xm0:xm1] for c in cols_full])

            aggs_and_cols = aggs + cols

            _extend(xs, ys, *aggs_and_cols)
Beispiel #3
0
        def extend(aggs, xr_ds, vt, bounds):
            from datashader.core import LinearAxis
            use_cuda = cupy and isinstance(xr_ds[name].data, cupy.ndarray)

            xs = xr_ds[x_name].values
            ys = xr_ds[y_name].values
            if use_cuda:
                xs = cupy.array(xs)
                ys = cupy.array(ys)

                x_mapper2 = _cuda_mapper(x_mapper)
                y_mapper2 = _cuda_mapper(y_mapper)
            else:
                x_mapper2 = x_mapper
                y_mapper2 = y_mapper

            # Convert from bin centers to interval edges
            x_breaks = infer_interval_breaks(xs)
            y_breaks = infer_interval_breaks(ys)

            x0, x1, y0, y1 = bounds
            xspan = x1 - x0
            yspan = y1 - y0

            if x_mapper is LinearAxis.mapper:
                xscaled = (x_breaks - x0) / xspan
            else:
                xscaled = (x_mapper2(x_breaks) - x0) / xspan

            if y_mapper is LinearAxis.mapper:
                yscaled = (y_breaks - y0) / yspan
            else:
                yscaled = (y_mapper2(y_breaks) - y0) / yspan

            xmask = np.where((xscaled >= 0) & (xscaled <= 1))
            ymask = np.where((yscaled >= 0) & (yscaled <= 1))
            xm0, xm1 = max(xmask[0].min() - 1, 0), xmask[0].max() + 1
            ym0, ym1 = max(ymask[0].min() - 1, 0), ymask[0].max() + 1

            plot_height, plot_width = aggs[0].shape[:2]

            # Downselect xs and ys and convert to int
            xs = (xscaled[xm0:xm1 + 1] * plot_width).astype(int).clip(
                0, plot_width)
            ys = (yscaled[ym0:ym1 + 1] * plot_height).astype(int).clip(
                0, plot_height)

            # For input "column", down select to valid range
            cols_full = info(xr_ds.transpose(y_name, x_name))
            cols = tuple([c[ym0:ym1, xm0:xm1] for c in cols_full])

            aggs_and_cols = aggs + cols

            if use_cuda:
                do_extend = extend_cuda[cuda_args(xr_ds[name].shape)]
            else:
                do_extend = extend_cpu

            do_extend(xs, ys, *aggs_and_cols)
Beispiel #4
0
        def extend(aggs, xr_ds, vt, bounds):
            from datashader.core import LinearAxis
            use_cuda = cupy and isinstance(xr_ds[name].data, cupy.ndarray)

            x_breaks = xr_ds[x_name].values
            y_breaks = xr_ds[y_name].values
            if use_cuda:
                x_breaks = cupy.array(x_breaks)
                y_breaks = cupy.array(y_breaks)

                x_mapper2 = _cuda_mapper(x_mapper)
                y_mapper2 = _cuda_mapper(y_mapper)
            else:
                x_mapper2 = _cuda_mapper(x_mapper)
                y_mapper2 = _cuda_mapper(y_mapper)

            # Convert from bin centers to interval edges
            x_breaks = infer_interval_breaks(x_breaks, axis=1)
            x_breaks = infer_interval_breaks(x_breaks, axis=0)

            y_breaks = infer_interval_breaks(y_breaks, axis=1)
            y_breaks = infer_interval_breaks(y_breaks, axis=0)

            # Scale x and y vertices into integer canvas coordinates
            x0, x1, y0, y1 = bounds
            xspan = x1 - x0
            yspan = y1 - y0

            if x_mapper is LinearAxis.mapper:
                xscaled = (x_breaks - x0) / xspan
            else:
                xscaled = (x_mapper2(x_breaks) - x0) / xspan

            if y_mapper is LinearAxis.mapper:
                yscaled = (y_breaks - y0) / yspan
            else:
                yscaled = (y_mapper2(y_breaks) - y0) / yspan

            plot_height, plot_width = aggs[0].shape[:2]

            xs = (xscaled * plot_width).astype(int)
            ys = (yscaled * plot_height).astype(int)

            coord_dims = xr_ds.coords[x_name].dims
            aggs_and_cols = aggs + info(xr_ds.transpose(*coord_dims))
            if use_cuda:
                do_extend = extend_cuda[cuda_args(xr_ds[name].shape)]
            else:
                do_extend = extend_cpu

            do_extend(plot_height, plot_width, xs, ys, *aggs_and_cols)
Beispiel #5
0
 def compute_y_bounds(self, xr_ds):
     ys = xr_ds[self.y].values
     ys = infer_interval_breaks(ys, axis=1)
     ys = infer_interval_breaks(ys, axis=0)
     bounds = Glyph._compute_bounds_2d(ys)
     return self.maybe_expand_bounds(bounds)
Beispiel #6
0
 def compute_x_bounds(self, xr_ds):
     xs = xr_ds[self.x].values
     xs = infer_interval_breaks(xs, axis=1)
     xs = infer_interval_breaks(xs, axis=0)
     bounds = Glyph._compute_bounds_2d(xs)
     return self.maybe_expand_bounds(bounds)
Beispiel #7
0
 def infer_interval_breaks(self, centers):
     # Infer breaks for 1D array of centers
     breaks = infer_interval_breaks(centers, axis=1)
     breaks = infer_interval_breaks(breaks, axis=0)
     return breaks
Beispiel #8
0
 def infer_interval_breaks(self, centers):
     # Infer breaks for 1D array of centers
     return infer_interval_breaks(centers)