Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def viewInteractiveImage(x_range, y_range, w, h, data_source):
cvs = cds.Canvas(
plot_width=w, plot_height=h, x_range=x_range, y_range=y_range
)
aggs = dict(
(_y, cvs.line(data_source, x=self.x, y=_y)) for _y in self.y
)
imgs = [
tf.shade(aggs[_y], cmap=["white", color])
for _y, color in zip(self.y, self.colors)
]
return tf.stack(*imgs)
def timed_agg(df, filepath, plot_width=int(900), plot_height=int(900*7.0/12), cache_ranges=True):
global CACHED_RANGES
start = time.time()
cvs = ds.Canvas(plot_width, plot_height, x_range=CACHED_RANGES[0], y_range=CACHED_RANGES[1])
agg = cvs.points(df, p.x, p.y)
end = time.time()
if cache_ranges:
CACHED_RANGES = (cvs.x_range, cvs.y_range)
img = export_image(tf.shade(agg),filepath,export_path=".")
return img, end-start
def _shade(xr, x_range, y_range):
"""Create a tile"""
canvas = datashader.Canvas(plot_width=256,
plot_height=256,
x_range=x_range,
y_range=y_range)
xri = canvas.quadmesh(xr)
image = np.ma.masked_array(xri.values, np.isnan(xri.values))
image = image.astype(np.float32) # Reduce bandwith needed to send values
return {
"x": [x_range[0]],
"y": [y_range[0]],
"dw": [x_range[1] - x_range[0]],
"dh": [y_range[1] - y_range[0]],
"image": [image]
}
def _gen_heights(bumps):
out = np.zeros(len(bumps))
for i, b in enumerate(bumps):
x = b[0]
y = b[1]
val = agg.data[y, x]
if val >= 0.33 and val <= 3:
out[i] = 0.1
return out
def _scale(value, old_range, new_range):
return ((value - old_range[0]) / (old_range[1] - old_range[0])) * (new_range[1] - new_range[0]) + new_range[0]
if not isinstance(canvas, Canvas):
raise TypeError('canvas must be instance type datashader.Canvas')
mercator_extent = (-np.pi * 6378137, -np.pi * 6378137, np.pi * 6378137, np.pi * 6378137)
crs_extents = {'3857': mercator_extent}
if isinstance(full_extent, str):
full_extent = crs_extents[full_extent]
elif full_extent is None:
full_extent = (canvas.x_range[0], canvas.y_range[0], canvas.x_range[1], canvas.y_range[1])
elif not isinstance(full_extent, (list, tuple)) and len(full_extent) != 4:
raise TypeError('full_extent must be tuple(4) or str wkid')
full_xrange = (full_extent[0], full_extent[2])
full_yrange = (full_extent[1], full_extent[3])
# print locs
data['Signal'][locs] *= 2
# # Default plot ranges:
x_range = (start, end)
y_range = (1.2 * signal.min(), 1.2 * signal.max())
# Create a dataframe
data['Time'] = np.linspace(start, end, n)
df = pd.DataFrame(data)
time_start = df['Time'].values[0]
time_end = df['Time'].values[-1]
cvs = ds.Canvas(x_range=x_range, y_range=y_range)
aggs = OrderedDict((c, cvs.line(df, 'Time', c)) for c in cols)
img = tf.shade(aggs['Signal'])
arr = np.array(img)
z = arr.tolist()
# axes
dims = len(z[0]), len(z)
x = np.linspace(x_range[0], x_range[1], dims[0])
y = np.linspace(y_range[0], y_range[1], dims[0])
#######################################################################################################################
# Layout
#######################################################################################################################
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.shade(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 viewInteractiveImage(x_range, y_range, w, h, data_source):
cvs = cds.Canvas(
plot_width=w, plot_height=h, x_range=x_range, y_range=y_range
)
agg = cvs.points(
data_source,
self.x,
self.y,
getattr(cds, self.aggregate_fn)(self.aggregate_col),
)
img = tf.shade(
agg, cmap=self.color_palette, how=self.pixel_shade_type
)
if self.pixel_spread == "dynspread":
return tf.dynspread(
img,
threshold=self.pixel_density,
max_px=self.point_size,