def test_interpolate(attr):
    x = getattr(agg, attr)
    cmap = ['pink', 'red']
    img = tf.interpolate(x, cmap=cmap, how='log')
    sol = np.array([[0, 4291543295, 4286741503], [4283978751, 0, 4280492543],
                    [4279242751, 4278190335, 0]],
                   dtype='u4')
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
    img = tf.interpolate(x, cmap=cmap, how='cbrt')
    sol = np.array([[0, 4291543295, 4284176127], [4282268415, 0, 4279834879],
                    [4278914047, 4278190335, 0]],
                   dtype='u4')
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
    img = tf.interpolate(x, cmap=cmap, how='linear')
    sol = np.array([[0, 4291543295, 4289306879], [4287070463, 0, 4282597631],
                    [4280361215, 4278190335, 0]])
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
    img = tf.interpolate(x, cmap=cmap, how='eq_hist')
    sol = xr.DataArray(eq_hist_sol[attr], coords=coords, dims=dims)
    assert img.equals(sol)
    img = tf.interpolate(x,
                         cmap=cmap,
                         how=lambda x, mask: np.where(mask, np.nan, x**2))
    sol = np.array([[0, 4291543295, 4291148543], [4290030335, 0, 4285557503],
                    [4282268415, 4278190335, 0]],
                   dtype='u4')
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
예제 #2
0
def test_interpolate(attr):
    x = getattr(agg, attr)
    img = tf.interpolate(x, 'pink', 'red', how='log')
    sol = np.array([[0, 4291543295, 4286741503],
                    [4283978751, 0, 4280492543],
                    [4279242751, 4278190335, 0]], dtype='u4')
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
    img = tf.interpolate(x, 'pink', 'red', how='cbrt')
    sol = np.array([[0, 4291543295, 4284176127],
                    [4282268415, 0, 4279834879],
                    [4278914047, 4278190335, 0]], dtype='u4')
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
    img = tf.interpolate(x, 'pink', 'red', how='linear')
    sol = np.array([[0, 4291543295, 4289306879],
                    [4287070463, 0, 4282597631],
                    [4280361215, 4278190335, 0]])
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
    img = tf.interpolate(x, 'pink', 'red', how=lambda x: x ** 2)
    sol = np.array([[0, 4291543295, 4291148543],
                    [4290030335, 0, 4285557503],
                    [4282268415, 4278190335, 0]], dtype='u4')
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
예제 #3
0
def test_interpolate_cmap_errors():
    cmap = ['red', (0, 255, 0), '#0000FF']

    with pytest.raises(ValueError):
        tf.interpolate(agg.a, cmap='foo')

    with pytest.raises(ValueError):
        tf.interpolate(agg.a, low='red', cmap=cmap)
def merged_images(x_range, y_range, w, h, how='log'):
    cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)
    picks = cvs.points(sep_trips, 'pickup_x',  'pickup_y',  ds.count('passenger_count'))
    drops = cvs.points(sep_trips, 'dropoff_x', 'dropoff_y', ds.count('passenger_count'))
    more_drops = tf.interpolate(drops.where(drops > picks), cmap=["lightblue", 'blue'], how=how)
    more_picks = tf.interpolate(picks.where(picks > drops), cmap=["lightpink", 'red'],  how=how)
    img = tf.stack(more_picks,more_drops)
    return tf.dynspread(img, threshold=0.1, max_px=4)
def test_interpolate_bool():
    data = ~np.eye(3, dtype='bool')
    x = xr.DataArray(data, coords=coords, dims=dims)
    sol = xr.DataArray(np.where(data, 4278190335, 0).astype('uint32'),
                       coords=coords, dims=dims)
    img = tf.interpolate(x, cmap=['pink', 'red'], how='log')
    assert img.equals(sol)
    img = tf.interpolate(x, cmap=['pink', 'red'], how='cbrt')
    assert img.equals(sol)
    img = tf.interpolate(x, cmap=['pink', 'red'], how='linear')
    assert img.equals(sol)
    img = tf.interpolate(x, cmap=['pink', 'red'], how='eq_hist')
    assert img.equals(sol)
def test_interpolate_bool():
    data = ~np.eye(3, dtype='bool')
    x = xr.DataArray(data, coords=coords, dims=dims)
    sol = xr.DataArray(np.where(data, 4278190335, 0).astype('uint32'),
                       coords=coords, dims=dims)
    img = tf.interpolate(x, cmap=['pink', 'red'], how='log')
    assert img.equals(sol)
    img = tf.interpolate(x, cmap=['pink', 'red'], how='cbrt')
    assert img.equals(sol)
    img = tf.interpolate(x, cmap=['pink', 'red'], how='linear')
    assert img.equals(sol)
    img = tf.interpolate(x, cmap=['pink', 'red'], how='eq_hist')
    assert img.equals(sol)
def test_interpolate_cmap():
    cmap = ['red', (0, 255, 0), '#0000FF']
    img = tf.interpolate(agg.a, how='log', cmap=cmap)
    sol = np.array([[0, 4278190335, 4278236489], [4280344064, 0, 4289091584],
                    [4292225024, 4294901760, 0]])
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)

    with pytest.raises(TypeError):
        tf.interpolate(agg.a, cmap='foo')

    with pytest.raises(ValueError):
        tf.interpolate(agg.a, low='red', cmap=cmap)
def test_interpolate_cmap():
    cmap = ['red', (0, 255, 0), '#0000FF']
    img = tf.interpolate(agg.a, how='log', cmap=cmap)
    sol = np.array([[0, 4278190335, 4278236489],
                    [4280344064, 0, 4289091584],
                    [4292225024, 4294901760, 0]])
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)

    with pytest.raises(TypeError):
        tf.interpolate(agg.a, cmap='foo')

    with pytest.raises(ValueError):
        tf.interpolate(agg.a, low='red', cmap=cmap)
예제 #9
0
def test14():
    import pandas as pd
    import numpy as np
    import xarray as xr
    import datashader as ds
    import datashader.glyphs
    import datashader.transfer_functions as tf
    from collections import OrderedDict
    import matplotlib.pyplot as plt
    from datashader import reductions

    np.random.seed(1)
    num = 10000
    dists = {cat: pd.DataFrame(dict(x=np.random.normal(x, s, num),
                                    y=np.random.normal(y, s, num),
                                    val=val, cat=cat))
             for x, y, s, val, cat, in
             [(2, 2, 0.01, 10, "d1"), (2, -2, 0.1, 20, "d2"),
              (-2, -2, 0.5, 30, "d3"), (-2, 2, 1.0, 40, "d4"),
              (0, 0, 3, 50, "d5")]
             }
    df = pd.concat(dists, ignore_index=True)
    df['cat'] = df['cat'].astype('category')
    print(df.tail())
    print('-' * 20)
    plt.plot(df['x'], df['y'], 'k.', ms=3, alpha=0.1)
    plt.xlim(-8, 8)
    plt.ylim(-8, 8)
    plt.show()

    cvs = ds.Canvas(plot_width=200, plot_height=200, x_range=(-8, 8), y_range=(-8, 8))
    agg = cvs.points(df, 'x', 'y', agg=reductions.count())
    img = tf.interpolate(agg)
    plt.imshow(img)
    plt.show()
예제 #10
0
def test_interpolate_cmap_non_categorical_alpha(cmap):
    img = tf.interpolate(agg.a, how='log', cmap=cmap)
    sol = np.array([[         0,          0, 1509949440],
                    [2399141888,          0, 3523215360],
                    [3925868544, 4278190080,          0]])
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
예제 #11
0
def update_image():

    global dims, raster_data

    dims_data = dims.data

    if not dims_data['width'] or not dims_data['height']:
        return

    xmin = max(dims_data['xmin'][0], raster_data.bounds.left)
    ymin = max(dims_data['ymin'][0], raster_data.bounds.bottom)
    xmax = min(dims_data['xmax'][0], raster_data.bounds.right)
    ymax = min(dims_data['ymax'][0], raster_data.bounds.top)

    canvas = ds.Canvas(plot_width=dims_data['width'][0],
                       plot_height=dims_data['height'][0],
                       x_range=(xmin, xmax),
                       y_range=(ymin, ymax))

    agg = canvas.raster(raster_data)
    img = tf.interpolate(agg, cmap=Hot, how='linear')

    new_data = {}
    new_data['image'] = [img.data]
    new_data['x'] = [xmin]
    new_data['y'] = [ymin]
    new_data['dh'] = [ymax - ymin]
    new_data['dw'] = [xmax - xmin]
    image_source.stream(new_data, 1)
예제 #12
0
def test_interpolate_should_handle_zeros_array():
    data = np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
                    dtype='uint32')
    arr = xr.DataArray(data, dims=['x', 'y'])
    img = tf.interpolate(arr, cmap=['white', 'black'], how='linear')
    assert img is not None
예제 #13
0
파일: snippet.py 프로젝트: szabo92/gistable
def main():
    shp = 'MAMMALS.shp'
    cvs = ds.Canvas(plot_height=2000,
                    plot_width=4000,
                    x_range=(-180, 180),
                    y_range=(-90, 90))

    out_arr = None
    count = 0
    problems = 0
    with fiona.collection(shp, "r") as source:
        for feat in source:
            try:
                r = rasterize_geom(cvs, feat['geometry'])
                if out_arr is None:
                    out_arr = r
                else:
                    out_arr += r
                count += 1
                print(count)
            except:
                print('problem...')
                problems += 1
                continue

    img = tf.interpolate(DataArray(data=np.flipud(out_arr)),
                         cmap=viridis,
                         how='linear')
    tf.set_background(img, 'black').to_pil().save("mammals_linear.png")
    print('Count: {}'.format(count))
    print('Problems: {}'.format(problems))
예제 #14
0
def update_image(dataframe):
    global dims
    dims_data = dims.data

    if not dims_data['width'] or not dims_data['height']:
        return

    plot_width = int(math.ceil(dims_data['width'][0]))
    plot_height = int(math.ceil(dims_data['height'][0]))
    x_range = (dims_data['xmin'][0], dims_data['xmax'][0])
    y_range = (dims_data['ymin'][0], dims_data['ymax'][0])

    canvas = ds.Canvas(plot_width=plot_width,
                       plot_height=plot_height,
                       x_range=x_range,
                       y_range=y_range)

    agg = canvas.points(dataframe, 'dropoff_x', 'dropoff_y',
                        ds.count('trip_distance'))

    img = tf.interpolate(agg, cmap=BuGn9, how='log')

    new_data = {}
    new_data['image'] = [img.data]
    new_data['x'] = [x_range[0]]
    new_data['y'] = [y_range[0]]
    new_data['dh'] = [y_range[1] - y_range[0]]
    new_data['dw'] = [x_range[1] - x_range[0]]

    image_source.stream(new_data, 1)
예제 #15
0
def update_image(dataframe):
    global dims
    dims_data = dims.data

    if not dims_data['width'] or not dims_data['height']:
        return

    plot_width = int(math.ceil(dims_data['width'][0]))
    plot_height = int(math.ceil(dims_data['height'][0]))
    x_range = (dims_data['xmin'][0], dims_data['xmax'][0])
    y_range = (dims_data['ymin'][0], dims_data['ymax'][0])

    canvas = ds.Canvas(plot_width=plot_width,
                       plot_height=plot_height,
                       x_range=x_range,
                       y_range=y_range)

    agg = canvas.points(dataframe, 'dropoff_x', 'dropoff_y',
                        ds.count('trip_distance'))

    img = tf.interpolate(agg, cmap=BuGn9, how='log')

    new_data = {}
    new_data['image'] = [img.data]
    new_data['x'] = [x_range[0]]
    new_data['y'] = [y_range[0]]
    new_data['dh'] = [y_range[1] - y_range[0]]
    new_data['dw'] = [x_range[1] - x_range[0]]

    image_source.stream(new_data, 1)
예제 #16
0
def update_image():

    global dims, raster_data

    dims_data = dims.data

    if not dims_data['width'] or not dims_data['height']:
        return

    xmin = max(dims_data['xmin'][0], raster_data.bounds.left)
    ymin = max(dims_data['ymin'][0], raster_data.bounds.bottom)
    xmax = min(dims_data['xmax'][0], raster_data.bounds.right)
    ymax = min(dims_data['ymax'][0], raster_data.bounds.top)

    canvas = ds.Canvas(plot_width=dims_data['width'][0],
                       plot_height=dims_data['height'][0],
                       x_range=(xmin, xmax),
                       y_range=(ymin, ymax))

    agg = canvas.raster(raster_data)
    img = tf.interpolate(agg, cmap=Hot, how='linear')

    new_data = {}
    new_data['image'] = [img.data]
    new_data['x'] = [xmin]
    new_data['y'] = [ymin]
    new_data['dh'] = [ymax - ymin]
    new_data['dw'] = [xmax - xmin]
    image_source.stream(new_data, 1)
def test_interpolate_mpl_cmap():
    cm = pytest.importorskip('matplotlib.cm')
    img = tf.interpolate(agg.a, how='log', cmap=cm.viridis)
    sol = np.array([[5505348, 4283695428, 4287524142],
                    [4287143710, 5505348, 4282832267],
                    [4280213706, 4280608765, 5505348]])
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
    def render_image(self):

        # handle categorical field
        if self.field in self.categorical_fields:
            pix = tf.colorize(self.agg, self.colormap, how=self.transfer_function)

        # handle ordinal field
        elif self.field in self.ordinal_fields:
            pix = tf.interpolate(self.agg, cmap=self.color_ramp, how=self.transfer_function)
        # handle no field
        else:
            pix = tf.interpolate(self.agg, cmap=self.color_ramp, how=self.transfer_function)

        if self.spread_size > 0:
            pix = tf.spread(pix, px=self.spread_size)

        return pix
예제 #19
0
def create_image(x_range, y_range, w, h):
    cvs = ds.Canvas(plot_width=w,
                    plot_height=h,
                    x_range=x_range,
                    y_range=y_range)
    agg = cvs.points(df, 'web_long', 'web_lat', ds.count('passenger_count'))
    img = tf.interpolate(agg, cmap=Hot, how='eq_hist')
    return tf.dynspread(img, threshold=0.5, max_px=1)
예제 #20
0
 def create_image(x_range, y_range, w=plot_width, h=plot_height):
     canvas = ds.Canvas(plot_width=plot_width,
                        plot_height=plot_height,
                        x_range=x_range,
                        y_range=y_range)
     agg = canvas.points(df, 'x', 'y')
     img = tf.interpolate(agg, cmap=ds.colors.Hot, how='log')
     return tf.dynspread(img, threshold=0.5, max_px=4)
def test_interpolate_mpl_cmap():
    cm = pytest.importorskip('matplotlib.cm')
    img = tf.interpolate(agg.a, how='log', cmap=cm.viridis)
    sol = np.array([[5505348, 4283695428, 4287524142],
                    [4287143710, 5505348, 4282832267],
                    [4280213706, 4280608765, 5505348]])
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)
def test_interpolate_should_handle_zeros_array():
    data = np.array([[0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0]], dtype='uint32')
    arr = xr.DataArray(data, dims=['x','y'])
    img = tf.interpolate(arr, cmap=['white','black'], how='linear')
    assert img is not None
예제 #23
0
def test_pipeline():
    pipeline = ds.Pipeline(df, ds.Point('x', 'y'))
    img = pipeline((0, 1), (0, 1), 2, 2)
    agg = cvs.points(df, 'x', 'y', ds.count())
    assert img.equals(tf.interpolate(agg))

    color_fn = lambda agg: tf.interpolate(agg, 'pink', 'red')
    pipeline.color_fn = color_fn
    img = pipeline((0, 1), (0, 1), 2, 2)
    assert img.equals(color_fn(agg))

    transform_fn = lambda agg: agg + 1
    pipeline.transform_fn = transform_fn
    img = pipeline((0, 1), (0, 1), 2, 2)
    assert img.equals(color_fn(transform_fn(agg)))

    pipeline = ds.Pipeline(df, ds.Point('x', 'y'), ds.sum('f64'))
    img = pipeline((0, 1), (0, 1), 2, 2)
    agg = cvs.points(df, 'x', 'y', ds.sum('f64'))
    assert img.equals(tf.interpolate(agg))
예제 #24
0
def test_pipeline():
    pipeline = ds.Pipeline(df, ds.Point('x', 'y'))
    img = pipeline((0, 1), (0, 1), 2, 2)
    agg = cvs.points(df, 'x', 'y', ds.count())
    assert img.equals(tf.interpolate(agg))

    color_fn = lambda agg: tf.interpolate(agg, 'pink', 'red')
    pipeline.color_fn = color_fn
    img = pipeline((0, 1), (0, 1), 2, 2)
    assert img.equals(color_fn(agg))

    transform_fn = lambda agg: agg + 1
    pipeline.transform_fn = transform_fn
    img = pipeline((0, 1), (0, 1), 2, 2)
    assert img.equals(color_fn(transform_fn(agg)))

    pipeline = ds.Pipeline(df, ds.Point('x', 'y'), ds.sum('f64'))
    img = pipeline((0, 1), (0, 1), 2, 2)
    agg = cvs.points(df, 'x', 'y', ds.sum('f64'))
    assert img.equals(tf.interpolate(agg))
예제 #25
0
    def render_image(self):

        # handle categorical field
        if self.field in self.categorical_fields:
            pix = tf.colorize(self.agg,
                              self.colormap,
                              how=self.transfer_function)

        # handle ordinal field
        elif self.field in self.ordinal_fields:
            pix = tf.interpolate(self.agg,
                                 cmap=self.color_ramp,
                                 how=self.transfer_function)
        # handle no field
        else:
            pix = tf.interpolate(self.agg,
                                 cmap=self.color_ramp,
                                 how=self.transfer_function)

        if self.spread_size > 0:
            pix = tf.spread(pix, px=self.spread_size)

        return pix
예제 #26
0
def test_interpolate(attr):
    x = getattr(agg, attr)
    img = tf.interpolate(x, 'pink', 'red', how='log').img
    sol = np.array([[0, 4291543295, 4289043711],
                    [4286675711, 0, 4282268671],
                    [4280163839, 4278190335, 0]])
    assert (img == sol).all()
    img = x.interpolate('pink', 'red', how='log').img
    assert (img == sol).all()
    img = tf.interpolate(x, 'pink', 'red', how='cbrt').img
    sol = np.array([[0, 4291543295, 4289109503],
                    [4286807295, 0, 4282399999],
                    [4280229375, 4278190335, 0]])
    assert (img == sol).all()
    img = tf.interpolate(x, 'pink', 'red', how='linear').img
    sol = np.array([[0, 4291543295, 4289306879],
                    [4287070463, 0, 4282597631],
                    [4280361215, 4278190335, 0]])
    assert (img == sol).all()
    img = tf.interpolate(x, 'pink', 'red', how=lambda x: x ** 2).img
    sol = np.array([[0, 4291543295, 4289504255],
                    [4287399423, 0, 4282992127],
                    [4280624127, 4278190335, 0]])
    assert (img == sol).all()
예제 #27
0
def create_ramp_legend(agg, cmap, how='linear', width=600):
    '''
    Helper function to create a Bokeh ``Figure`` object
    with a color ramp corresponding to input aggregate and transfer function.

    Parameters
    ----------
    agg : xarray
        Datashader aggregate object (e.g. result of Canvas.points())

    cmap : list of colors or matplotlib.colors.Colormap, optional
        The colormap to use. Can be either a list of colors (in any of the
        formats described above), or a matplotlib colormap object.

    how : str
        Datashader transfer function name (e.g. linear, log, cbrt, eq_hist)

    width : int
        Width in pixels of resulting legend figure (default=600)
    '''

    vals_arr, min_val, max_val = summarize_aggregate_values(agg, how=how)
    img = tf.interpolate(vals_arr, cmap=cmap, how=how)
    x_axis_type = 'linear' if how == 'linear' else 'log'
    legend_fig = Figure(x_range=(min_val, max_val),
                        plot_height=50,
                        plot_width=width,
                        lod_threshold=None,
                        toolbar_location=None,
                        y_range=(0, 18),
                        x_axis_type=x_axis_type)

    legend_fig.min_border_top = 0
    legend_fig.min_border_bottom = 10
    legend_fig.min_border_left = 15
    legend_fig.min_border_right = 15
    legend_fig.yaxis.visible = False
    legend_fig.grid.grid_line_alpha = 0
    legend_fig.image_rgba(image=[img.values],
                          x=[min_val],
                          y=[0],
                          dw=[max_val - min_val],
                          dh=[18],
                          dw_units='screen')
    return legend_fig
예제 #28
0
    def get(self, args):
        # parse args
        selection = args['select'].strip(',').split(',')
        xmin, ymin, xmax, ymax = map(float, selection)
        self.model.map_extent = [xmin, ymin, xmax, ymax]

        # create image
        cvs = ds.Canvas(plot_width=args['width'],
                        plot_height=args['height'],
                        x_range=(xmin, xmax),
                        y_range=(ymin, ymax))
        agg = cvs.points(self.model.df,
                         self.model.active_axes[1],
                         self.model.active_axes[2],
                         self.model.aggregate_function(self.model.field))
        pix = tf.interpolate(agg, (255, 204, 204), 'red',
                             how=self.model.transfer_function)

        # serialize to image
        img_io = pix.to_bytesio()
        self.write(img_io.getvalue())
        self.set_header("Content-type", "image/png")
예제 #29
0
    def get(self, args):
        # parse args
        selection = args['select'].strip(',').split(',')
        xmin, ymin, xmax, ymax = map(float, selection)
        self.model.map_extent = [xmin, ymin, xmax, ymax]

        # create image
        cvs = ds.Canvas(plot_width=args['width'],
                        plot_height=args['height'],
                        x_range=(xmin, xmax),
                        y_range=(ymin, ymax))
        agg = cvs.points(self.model.df, self.model.active_axes[1],
                         self.model.active_axes[2],
                         self.model.aggregate_function(self.model.field))
        pix = tf.interpolate(agg, (255, 204, 204),
                             'red',
                             how=self.model.transfer_function)

        # serialize to image
        img_io = pix.to_bytesio()
        self.write(img_io.getvalue())
        self.set_header("Content-type", "image/png")
예제 #30
0
    def update_legend(self):

        if self.field in self.categorical_fields:
            cat_legend = self.create_categorical_legend(self.colormap, self.colornames)
            self.legend_side_vbox.children = [cat_legend]
            self.legend_bottom_vbox.children = []

        else:
            min_val = np.nanmin(self.agg.values)

            if min_val == 0:
                min_val = self.agg.data[self.agg.data > 0].min()
                
            max_val = np.nanmax(self.agg.values)
            

            if self.transfer_function == 'linear':
                vals = np.linspace(min_val, max_val, 180)[None, :]
            else:
                vals = (np.logspace(0, 
                                    np.log1p(max_val-min_val),
                                    base=np.e, num=180,
                                    dtype=min_val.dtype) + min_val)[None,:]

            vals_arr = DataArray(vals)
            img = tf.interpolate(vals_arr, cmap=self.color_ramp, how=self.transfer_function)
            dw = max_val - min_val
            legend_fig = self.create_legend(img.values,
                                            x=min_val,
                                            y=0,
                                            dh=18,
                                            dw=dw,
                                            x_start=min_val,
                                            x_end=max_val,
                                            y_range=(0,18))

            self.legend_bottom_vbox.children = [legend_fig]
            self.legend_side_vbox.children = []
예제 #31
0
def test13():

    import pandas as pd
    from bokeh.plotting import figure, show
    import datashader as ds
    from datashader import transfer_functions as tf
    from functools import partial

    import datashader as ds
    from datashader import transfer_functions as tf
    from datashader.colors import Greys9, Hot
    from datashader.bokeh_ext import InteractiveImage
    from datashader import reductions
    import matplotlib

    Greys9_r = list(reversed(Greys9))[:-2]

    tel = SKA1_low()
    tel.add_ska1_v5(r_max=1000)
    tel.dec_deg = tel.lat_deg
    tel.obs_length_h = 4
    tel.num_times = int((tel.obs_length_h * 3600) / 60)
    tel.gen_uvw_coords()
    tel.grid_uvw_coords()
    # print(tel.num_coords())

    uu = np.hstack([tel.uu_m, -tel.uu_m])
    vv = np.hstack([tel.vv_m, -tel.vv_m])

    df = pd.DataFrame(np.vstack([uu, vv, np.ones_like(uu)]).transpose(),
                      columns=list('uvc'))
    print(df.tail())

    img = tf.interpolate(ds.Canvas().points(df, 'u', 'v'))
    print(img.data.min(), img.data.max())
    print(img.values.min(), img.values.max())
    print(tel.uv_grid.min(), tel.uv_grid.max())
		def create_image(x_range,y_range,w=plot_width,h=plot_height):
			canvas = ds.Canvas(plot_width=plot_width,plot_height=plot_height,
			x_range=x_range, y_range=y_range)
			agg = canvas.points(df,'x','y')
			img = tf.interpolate(agg,cmap=ds.colors.Hot,how='log')
			return tf.dynspread(img,threshold=0.5,max_px=4)
예제 #33
0
def image_callback(x_range, y_range, w, h):
    cvs = ds.Canvas(
          plot_width=w,plot_height=h,x_range=x_range,y_range=y_range)
    agg = cvs.points(df,'meterswest','metersnorth')
    img = tf.interpolate(agg, cmap = cmap, how='eq_hist')
    return tf.dynspread(img,threshold=0.75, max_px=8)
예제 #34
0
from datashader.colors import colormap_select, Greys9, Hot, viridis, inferno
from IPython.core.display import HTML, display

print("Begin...")
#df = pd.read_hdf('census.h5', 'census')

USA =          ((-13884029,  -7453304), (2698291, 6455972))
plot_width  = int(1000)
plot_height = int(plot_width*7.0/12)

df = pd.DataFrame(
      {'meterswest': np.random.random(10000)*1000e3 + -10668666.5,
      'metersnorth': np.random.random(10000)*1000e3 + 4577131.5}
      )
print(df.tail())


background = "black"
display(HTML("<style>.container { width:100% !important; }</style>"))

print("Computing aggregate...")
cvs = ds.Canvas(plot_width, plot_height, *USA)
agg = cvs.points(df, 'meterswest', 'metersnorth')

print("Making Image ...")
cmap = colormap_select(Hot,0.2, reverse=(background!="black"))
interp = tf.interpolate(agg, cmap = cmap, how='eq_hist')
export_image(interp, "census_ds_hot_eq_hist", background=background)


def create_image(x_range, y_range, w, h):
    cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)
    agg = cvs.points(sep_trips, 'dropoff_x', 'dropoff_y',  ds.count('passenger_count'))
    img = tf.interpolate(agg, cmap=Hot, how='eq_hist')
    return tf.dynspread(img, threshold=0.5, max_px=4)
예제 #36
0
def create_image(x_range, y_range, w, h):
    cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)
    agg = cvs.points(picks, 'x', 'y',  ds.count('visibility'))
    img = tf.interpolate(agg, cmap=Hot, how='eq_hist')
    return tf.dynspread(img, threshold=0.5, max_px=4)
예제 #37
0
def image_callback(x_range, y_range, w, h):
    cvs = ds.Canvas(
          plot_width=w,plot_height=h,x_range=x_range,y_range=y_range)
    agg = cvs.points(df,'meterswest','metersnorth', ds.mean('temp'))
    img = tf.interpolate(agg, cmap = cmap, how='cbrt',span=[0.0,1.0])
    return tf.dynspread(img,threshold=0.5, max_px=4)
def create_image(x_range, y_range, w, h):
    cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)
    agg = cvs.points(df, 'web_long', 'web_lat',  ds.count('trip_distance'))
    img = tf.interpolate(agg, cmap=Hot, how='eq_hist')
    return tf.dynspread(img, threshold=0.5, max_px=4)
def create_image(x_range, y_range, w, h):
    cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)
    agg = cvs.points(df, 'pickup_longitude', 'pickup_latitude',  ds.count('passenger_count'))
    img = tf.interpolate(agg, cmap=Hot, how='eq_hist')
    return tf.dynspread(img, threshold=0.5, max_px=4)
예제 #40
0
def test_interpolate_cmap_non_categorical_alpha(cmap):
    img = tf.interpolate(agg.a, how='log', cmap=cmap)
    sol = np.array([[0, 671088640, 1946157056], [2701131776, 0, 3640655872],
                    [3976200192, 4278190080, 0]])
    sol = xr.DataArray(sol, coords=coords, dims=dims)
    assert img.equals(sol)