Пример #1
0
def test_std():
    out = df.i32.reshape((2, 2, 5)).std(axis=2).T
    eq(c.points(df, 'x', 'y', ds.std('i32')), out)
    eq(c.points(df, 'x', 'y', ds.std('i64')), out)
    out = np.nanstd(df.f64.reshape((2, 2, 5)), axis=2).T
    eq(c.points(df, 'x', 'y', ds.std('f32')), out)
    eq(c.points(df, 'x', 'y', ds.std('f64')), out)
Пример #2
0
def test_std():
    out = xr.DataArray(df.i32.values.reshape((2, 2, 5)).std(axis=2, dtype='f8').T,
                       coords=coords, dims=dims)
    assert_eq(c.points(df, 'x', 'y', ds.std('i32')), out)
    assert_eq(c.points(df, 'x', 'y', ds.std('i64')), out)
    out = xr.DataArray(np.nanstd(df.f64.values.reshape((2, 2, 5)), axis=2).T,
                       coords=coords, dims=dims)
    assert_eq(c.points(df, 'x', 'y', ds.std('f32')), out)
    assert_eq(c.points(df, 'x', 'y', ds.std('f64')), out)
Пример #3
0
def test_std():
    out = xr.DataArray(df.i32.values.reshape((2, 2, 5)).std(axis=2, dtype='f8').T,
                       coords=coords, dims=dims)
    assert_eq(c.points(ddf, 'x', 'y', ds.std('i32')), out)
    assert_eq(c.points(ddf, 'x', 'y', ds.std('i64')), out)
    out = xr.DataArray(np.nanstd(df.f64.values.reshape((2, 2, 5)), axis=2).T,
                       coords=coords, dims=dims)
    assert_eq(c.points(ddf, 'x', 'y', ds.std('f32')), out)
    assert_eq(c.points(ddf, 'x', 'y', ds.std('f64')), out)
Пример #4
0
def test_std(ddf):
    if dask_cudf and isinstance(ddf, dask_cudf.DataFrame):
        pytest.skip("std not supported with cudf")

    out = xr.DataArray(
        values(df_pd.i32).reshape((2, 2, 5)).std(axis=2, dtype='f8').T,
        coords=coords, dims=dims)
    assert_eq_xr(c.points(ddf, 'x', 'y', ds.std('i32')), out)
    assert_eq_xr(c.points(ddf, 'x', 'y', ds.std('i64')), out)
    out = xr.DataArray(
        np.nanstd(values(df_pd.f64).reshape((2, 2, 5)), axis=2).T,
        coords=coords, dims=dims)
    assert_eq_xr(c.points(ddf, 'x', 'y', ds.std('f32')), out)
    assert_eq_xr(c.points(ddf, 'x', 'y', ds.std('f64')), out)
Пример #5
0
def test_categorical_std(ddf):
    if cudf and isinstance(ddf._meta, cudf.DataFrame):
        pytest.skip("The 'std' reduction is yet supported on the GPU")

    sol = np.sqrt(
        np.array([[[2.5, nan, nan, nan], [nan, nan, 2., nan]],
                  [[nan, 2., nan, nan], [nan, nan, nan, 2.]]]))
    out = xr.DataArray(sol,
                       coords=(coords + [['a', 'b', 'c', 'd']]),
                       dims=(dims + ['cat']))

    agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.std('f32')))
    assert_eq_xr(agg, out, True)

    agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.std('f64')))
    assert_eq_xr(agg, out, True)
Пример #6
0
    def __call__(self, dset, **params):

        self.p = ParamOverrides(self, params)

        if self.p.vdim is None:
            vdim = dset.vdims[0].name
        else:
            vdim = self.p.vdim

        pts = hv.util.Dynamic(dset, operation=skypoints,
                              streams=[self.p.filter_stream])

        if self.p.aggregator == 'mean':
            aggregator = ds.mean(vdim)
        elif self.p.aggregator == 'std':
            aggregator = ds.std(vdim)
        elif self.p.aggregator == 'count':
            aggregator = ds.count()


        decimate_opts = dict(plot={'tools': ['hover',
                                             'box_select']},
                             style={'alpha': 0,
                                    'size': self.p.decimate_size,
                                    'nonselection_alpha': 0})

        decimated = decimate(pts).opts(**decimate_opts)
        raster_ = rasterize(pts, aggregator=aggregator)
        color_gadget = raster_.opts(cmap=Viridis[256], colorbar=True, alpha=0)
        sky_shaded = shade(raster_, cmap=viridis)

        plot = dynspread(sky_shaded) * decimated * color_gadget

        return plot.options(bgcolor="black", responsive=True, min_height=100)
Пример #7
0
    def _process(self, element, key=None):

        vdim = self.p.vdim
        if self.p.aggregator == 'mean':
            aggregator = ds.mean(vdim)
        elif self.p.aggregator == 'std':
            aggregator = ds.std(vdim)
        elif self.p.aggregator == 'count':
            aggregator = ds.count()

        kwargs = dict(cmap=cc.palette[self.p.cmap], aggregator=aggregator)
        if self.p.width is not None:
            kwargs.update(width=self.p.width,
                          height=self.p.height,
                          streams=[hv.streams.RangeXY])

        datashaded = dynspread(datashade(element, **kwargs))

        # decimate_opts = dict(plot={'tools':['hover', 'box_select']},
        #                     style={'alpha':0, 'size':self.p.decimate_size,
        #                            'nonselection_alpha':0})

        # decimated = decimate(element, max_samples=self.p.max_samples).opts(**decimate_opts)

        return datashaded  # * decimated
Пример #8
0
def test_categorical_std(ddf):
    sol = np.sqrt(np.array([
        [[ 2.5,  nan,  nan,  nan],
         [ nan,  nan,   2.,  nan]],
        [[ nan,   2.,  nan,  nan],
         [ nan,  nan,  nan,   2.]]])
    )
    out = xr.DataArray(
        sol,
        coords=(coords + [['a', 'b', 'c', 'd']]),
        dims=(dims + ['cat']))

    agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.std('f32')))
    assert_eq_xr(agg, out, True)

    agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.std('f64')))
    assert_eq_xr(agg, out, True)
Пример #9
0
def test_multiple_aggregates():
    agg = c.points(ddf, 'x', 'y',
                   f64=dict(std=ds.std('f64'), mean=ds.mean('f64')),
                   i32_sum=ds.sum('i32'),
                   i32_count=ds.count('i32'))

    eq(agg.f64.std, df.f64.reshape((2, 2, 5)).std(axis=2).T)
    eq(agg.f64.mean, df.f64.reshape((2, 2, 5)).mean(axis=2).T)
    eq(agg.i32_sum, df.i32.reshape((2, 2, 5)).sum(axis=2).T)
    eq(agg.i32_count, np.array([[5, 5], [5, 5]], dtype='i4'))
Пример #10
0
def test_categorical_std(ddf):
    if cudf and isinstance(ddf._meta, cudf.DataFrame):
        pytest.skip("The 'std' reduction is yet supported on the GPU")

    sol = np.sqrt(
        np.array([[[2.5, nan, nan, nan], [nan, nan, 2., nan]],
                  [[nan, 2., nan, nan], [nan, nan, nan, 2.]]]))
    out = xr.DataArray(sol,
                       coords=(coords + [['a', 'b', 'c', 'd']]),
                       dims=(dims + ['cat']))

    agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.std('f32')))
    assert_eq_xr(agg, out, True)

    agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.std('f64')))
    assert_eq_xr(agg, out, True)

    out = xr.DataArray(sol,
                       coords=(coords + [range(4)]),
                       dims=(dims + ['cat_int']))
    agg = c.points(
        ddf, 'x', 'y',
        ds.by(ds.category_modulo('cat_int', modulo=4, offset=10),
              ds.std('f32')))
    assert_eq_xr(agg, out)

    agg = c.points(
        ddf, 'x', 'y',
        ds.by(ds.category_modulo('cat_int', modulo=4, offset=10),
              ds.std('f64')))
    assert_eq_xr(agg, out)

    # add an extra category (this will count nans and out of bounds)
    sol = np.append(sol, [[[nan], [nan]], [[nan], [nan]]], axis=2)

    for col in 'f32', 'f64':
        out = xr.DataArray(sol,
                           coords=(coords + [range(5)]),
                           dims=(dims + [col]))
        agg = c.points(ddf, 'x', 'y',
                       ds.by(ds.category_binning(col, 0, 20, 4), ds.std(col)))
        assert_eq_xr(agg, out)
Пример #11
0
def test_multiple_aggregates():
    agg = c.points(ddf,
                   'x',
                   'y',
                   f64=dict(std=ds.std('f64'), mean=ds.mean('f64')),
                   i32_sum=ds.sum('i32'),
                   i32_count=ds.count('i32'))

    eq(agg.f64.std, df.f64.reshape((2, 2, 5)).std(axis=2).T)
    eq(agg.f64.mean, df.f64.reshape((2, 2, 5)).mean(axis=2).T)
    eq(agg.i32_sum, df.i32.reshape((2, 2, 5)).sum(axis=2).T)
    eq(agg.i32_count, np.array([[5, 5], [5, 5]], dtype='i4'))
Пример #12
0
def test_multiple_aggregates():
    agg = c.points(ddf, 'x', 'y',
                   ds.summary(f64_std=ds.std('f64'),
                              f64_mean=ds.mean('f64'),
                              i32_sum=ds.sum('i32'),
                              i32_count=ds.count('i32')))

    f = lambda x: xr.DataArray(x, coords=coords, dims=dims)
    assert_eq(agg.f64_std, f(np.nanstd(df.f64.values.reshape((2, 2, 5)), axis=2).T))
    assert_eq(agg.f64_mean, f(np.nanmean(df.f64.values.reshape((2, 2, 5)), axis=2).T))
    assert_eq(agg.i32_sum, f(df.i32.values.reshape((2, 2, 5)).sum(axis=2, dtype='f8').T))
    assert_eq(agg.i32_count, f(np.array([[5, 5], [5, 5]], dtype='i4')))
Пример #13
0
def test_multiple_aggregates():
    agg = c.points(df, 'x', 'y',
                   ds.summary(f64_std=ds.std('f64'),
                              f64_mean=ds.mean('f64'),
                              i32_sum=ds.sum('i32'),
                              i32_count=ds.count('i32')))

    f = lambda x: xr.DataArray(x, coords=coords, dims=dims)
    assert_eq(agg.f64_std, f(np.nanstd(df.f64.values.reshape((2, 2, 5)), axis=2).T))
    assert_eq(agg.f64_mean, f(np.nanmean(df.f64.values.reshape((2, 2, 5)), axis=2).T))
    assert_eq(agg.i32_sum, f(df.i32.values.reshape((2, 2, 5)).sum(axis=2, dtype='f8').T))
    assert_eq(agg.i32_count, f(np.array([[5, 5], [5, 5]], dtype='i4')))
Пример #14
0
def test_multiple_aggregates(ddf):
    if dask_cudf and isinstance(ddf, dask_cudf.DataFrame):
        pytest.skip("std not supported with cudf")

    agg = c.points(ddf, 'x', 'y',
                   ds.summary(f64_std=ds.std('f64'),
                              f64_mean=ds.mean('f64'),
                              i32_sum=ds.sum('i32'),
                              i32_count=ds.count('i32')))

    f = lambda x: xr.DataArray(x, coords=coords, dims=dims)
    assert_eq_xr(agg.f64_std, f(np.nanstd(values(df_pd.f64).reshape((2, 2, 5)), axis=2).T))
    assert_eq_xr(agg.f64_mean, f(np.nanmean(values(df_pd.f64).reshape((2, 2, 5)), axis=2).T))
    assert_eq_xr(agg.i32_sum, f(values(df_pd.i32).reshape((2, 2, 5)).sum(axis=2, dtype='f8').T))
    assert_eq_xr(agg.i32_count, f(np.array([[5, 5], [5, 5]], dtype='i4')))
Пример #15
0
    def _process(self, element, key=None):

        vdim = self.p.vdim
        if self.p.aggregator == "mean":
            aggregator = ds.mean(vdim)
        elif self.p.aggregator == "std":
            aggregator = ds.std(vdim)
        elif self.p.aggregator == "count":
            aggregator = ds.count()

        kwargs = dict(cmap=list(cc.palette[self.p.cmap]),
                      aggregator=aggregator)

        datashaded = dynspread(datashade(element, **kwargs))

        # decimate_opts = dict(plot={'tools':['hover', 'box_select']},
        #                     style={'alpha':0, 'size':self.p.decimate_size,
        #                            'nonselection_alpha':0})
        # decimated = decimate(element, max_samples=self.p.max_samples).opts(**decimate_opts)

        return datashaded.options(responsive=True, height=300)  # * decimated
Пример #16
0
    def __call__(self, dset, **params):
        self.p = ParamOverrides(self, params)

        if self.p.vdim is None:
            vdim = dset.vdims[0].name
        else:
            vdim = self.p.vdim

        pts = hv.util.Dynamic(dset,
                              operation=skypoints,
                              streams=[self.p.filter_stream])

        if self.p.aggregator == 'mean':
            aggregator = ds.mean(vdim)
        elif self.p.aggregator == 'std':
            aggregator = ds.std(vdim)
        elif self.p.aggregator == 'count':
            aggregator = ds.count()

        kwargs = dict(cmap=cc.palette[self.p.cmap], aggregator=aggregator)
        if self.p.width is not None:
            kwargs.update(width=self.p.width, height=self.p.height)


#                          streams=[hv.streams.RangeXY])

        decimate_opts = dict(plot={'tools': ['hover', 'box_select']},
                             style={
                                 'alpha': 0,
                                 'size': self.p.decimate_size,
                                 'nonselection_alpha': 0
                             })

        decimated = decimate(pts).opts(**decimate_opts)
        sky_shaded = datashade(pts, **kwargs)

        return dynspread(sky_shaded) * decimated
Пример #17
0
def test_std():
    out = df.i32.reshape((2, 2, 5)).std(axis=2).T
    eq(c.points(ddf, 'x', 'y', agg=ds.std('i32')).agg, out)
    eq(c.points(ddf, 'x', 'y', agg=ds.std('i64')).agg, out)
    eq(c.points(ddf, 'x', 'y', agg=ds.std('f32')).agg, out)
    eq(c.points(ddf, 'x', 'y', agg=ds.std('f64')).agg, out)
Пример #18
0
    def __call__(self, dset, **params):
        self.p = ParamOverrides(self, params)

        if self.p.vdim is None:
            vdim = dset.vdims[0].name
        else:
            vdim = self.p.vdim

        ra_range = (ra0, ra1) = dset.range("ra")
        if self.p.ra_sampling:
            xsampling = (ra1 - ra0) / self.p.ra_sampling
        else:
            xsampling = None

        dec_range = (dec0, dec1) = dset.range("dec")
        if self.p.dec_sampling:
            ysampling = (dec1 - dec0) / self.p.dec_sampling
        else:
            ysampling = None

        if self.p.aggregator == "mean":
            aggregator = ds.mean(vdim)
        elif self.p.aggregator == "std":
            aggregator = ds.std(vdim)
        elif self.p.aggregator == "count":
            aggregator = ds.count()

        sky_range = RangeXY()
        if self.p.range_stream:

            def redim(dset, x_range, y_range):
                ranges = {}
                if x_range and all(isfinite(v) for v in x_range):
                    ranges["ra"] = x_range
                if y_range and all(isfinite(v) for v in x_range):
                    ranges["dec"] = y_range
                return dset.redim.range(**ranges) if ranges else dset

            dset = dset.apply(redim, streams=[self.p.range_stream])
            link_streams(self.p.range_stream, sky_range)
        streams = [sky_range, PlotSize()]

        pts = dset.apply(skypoints, streams=[self.p.filter_stream])

        reset = PlotReset(source=pts)
        reset.add_subscriber(partial(reset_stream, None,
                                     [self.p.range_stream]))

        rasterize_inst = rasterize.instance(aggregator=aggregator,
                                            streams=streams,
                                            x_sampling=xsampling,
                                            y_sampling=ysampling)
        raster_pts = apply_when(
            pts,
            operation=rasterize_inst,
            predicate=lambda pts: len(pts) > self.p.max_points)
        return raster_pts.opts(
            opts.Image(
                bgcolor="black",
                colorbar=True,
                cmap=self.p.cmap,
                min_height=100,
                responsive=True,
                tools=["hover"],
                symmetric=True,
            ),
            opts.Points(
                color=vdim,
                cmap=self.p.cmap,
                framewise=True,
                size=self.p.decimate_size,
                tools=["hover"],
                symmetric=True,
            ),
            opts.Overlay(hooks=[
                partial(reset_hook, x_range=ra_range, y_range=dec_range)
            ]),
        )
Пример #19
0
def test_std():
    out = df.i32.reshape((2, 2, 5)).std(axis=2).T
    eq(c.points(ddf, 'x', 'y', agg=ds.std('i32')).agg, out)
    eq(c.points(ddf, 'x', 'y', agg=ds.std('i64')).agg, out)
    eq(c.points(ddf, 'x', 'y', agg=ds.std('f32')).agg, out)
    eq(c.points(ddf, 'x', 'y', agg=ds.std('f64')).agg, out)