Esempio n. 1
0
def test_multiple_aggregates():
    agg = c.points(df, 'x', 'y',
                   ds.summary(f64=ds.summary(std=ds.std('f64'),
                                             mean=ds.mean('f64')),
                              i32_sum=ds.sum('i32'),
                              i32_count=ds.count('i32')))

    eq(agg.f64.std, np.nanstd(df.f64.reshape((2, 2, 5)), axis=2).T)
    eq(agg.f64.mean, np.nanmean(df.f64.reshape((2, 2, 5)), 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'))
Esempio n. 2
0
def shade_mesh(vertices, triangles, cmap=colorcet.rainbow, **kwargs):
    """"""

    if "plot_width" not in kwargs or "plot_height" not in kwargs:
        raise ValueError(
            "Please provide plot_width and plot_height for the canvas.")

    if not isinstance(vertices, pd.DataFrame):
        vertices = pd.DataFrame(vertices,
                                columns=["x", "y", "z", "patch_id"],
                                copy=False)

    if not isinstance(triangles, pd.DataFrame):
        triangles = pd.DataFrame(triangles,
                                 columns=["v0", "v1", "v2"],
                                 copy=False)

    cvs = ds.Canvas(**kwargs)
    img = cvs.trimesh(vertices, triangles, interpolate="nearest")

    summary = ds.summary(id_info=ds.max("patch_id"))
    summary.column = "z"

    hover_agg = cvs.trimesh(vertices, triangles, agg=summary)
    res = tf.shade(img, cmap=cmap, how="linear", span=[0,
                                                       len(cmap)]), hover_agg

    return res
Esempio n. 3
0
def test_multiple_aggregates(df):
    agg = c.points(df, 'x', 'y',
                   ds.summary(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_mean, f(np.nanmean(values(df.f64).reshape((2, 2, 5)), axis=2).T))
    assert_eq_xr(agg.i32_sum, f(values(df.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')))
Esempio n. 4
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')))
def make_image(data, time_range, y_range, size, scale=None, width=0):

    "Flatten the given range of the data into a 2d image"
    time_range = (time_range[0].timestamp() * 1e6,
                  time_range[1].timestamp() * 1e6)
    cvs = datashader.Canvas(x_range=time_range,
                            y_range=y_range,
                            plot_width=size[0],
                            plot_height=size[1],
                            y_axis_type=scale or "linear")

    # aggregate some useful measures
    agg_line = cvs.line(source=data["data"], x="t", y="value_r")
    agg_points = cvs.points(source=data["data"],
                            x="t",
                            y="value_r",
                            agg=datashader.summary(
                                count=datashader.count("value_r"),
                                vmean=datashader.mean("value_r"),
                                vmin=datashader.min("value_r"),
                                vmax=datashader.max("value_r")))
    color = data["info"].get("color", "red")
    image = datashader.transfer_functions.shade(agg_line, cmap=[color])

    if width > 0:
        image = datashader.transfer_functions.spread(image, px=width)
        # image = datashader.transfer_functions.spread(
        #     image, mask=np.matrix([[False, False, False],
        #                            [False, True, True],
        #                            [False, True, True]]))

    with timer("Making hover info"):
        indices = np.where(np.nanmax(agg_points["count"].values, axis=0))[0]
        vmin = np.take(np.nanmin(agg_points["vmin"].values, axis=0), indices)
        vmax = np.take(np.nanmax(agg_points["vmax"].values, axis=0), indices)
        # vmean = np.take(np.nanmax(agg_points["vmean"].values, axis=0), indices)
        # TODO: aggregating the mean is not quite this simple...
        timestamps = np.take(agg_points["x_axis"].values, indices)
        count = np.take(np.sum(agg_points["count"].values, axis=0), indices)
        desc = {
            "total_points": data["points"],
            "indices": indices.tolist(),
            "min": np.where(np.isnan(vmin), None, vmin).tolist(),
            "max": np.where(np.isnan(vmax), None, vmax).tolist(),
            "timestamp": [float(t) for t in timestamps],
            # "mean": np.where(np.isnan(vmean), None, vmean).tolist(),
            "count": np.where(np.isnan(count), None, count).tolist()
        }
    return image, desc
Esempio n. 6
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')))