Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if px == 0:
return img
mask = _mask_lookup[shape](px)
elif not (isinstance(mask, np.ndarray) and mask.ndim == 2 and
mask.shape[0] == mask.shape[1] and mask.shape[0] % 2 == 1):
raise ValueError("mask must be a square 2 dimensional ndarray with "
"odd dimensions.")
mask = mask if mask.dtype == 'bool' else mask.astype('bool')
kernel = _build_spread_kernel(how)
w = mask.shape[0]
extra = w // 2
M, N = img.shape
buf = np.zeros((M + 2*extra, N + 2*extra), dtype='uint32')
kernel(img.data, mask, buf)
out = buf[extra:-extra, extra:-extra].copy()
return Image(out, dims=img.dims, coords=img.coords, name=name)
# Convert cupy array to numpy before passing to matplotlib colormap
scaled_data = cupy.asnumpy(scaled_data)
rgba = cmap(scaled_data, bytes=True)
rgba[:, :, 3] = np.where(np.isnan(scaled_data), 0, alpha).astype(np.uint8)
else:
raise TypeError("Expected `cmap` of `matplotlib.colors.Colormap`, "
"`list`, `str`, or `tuple`; got: '{0}'".format(type(cmap)))
img = rgba.view(np.uint32).reshape(data.shape)
if cupy and isinstance(img, cupy.ndarray):
# Convert cupy array to numpy for final image
img = cupy.asnumpy(img)
return Image(img, coords=agg.coords, dims=agg.dims, name=name)
offset = total.min()
mask = np.isnan(total)
if offset == 0:
mask = mask | (total <= 0)
offset = total[total > 0].min()
a = _normalize_interpolate_how(how)(total - offset, mask)
a = interp(a, array([np.nanmin(a).item(), np.nanmax(a).item()]),
array([min_alpha, 255]), left=0, right=255).astype(np.uint8)
r[mask] = g[mask] = b[mask] = 255
values = np.dstack([r, g, b, a]).view(np.uint32).reshape(a.shape)
if cupy and isinstance(values, cupy.ndarray):
# Convert cupy array to numpy for final image
values = cupy.asnumpy(values)
return Image(values,
dims=agg.dims[:-1],
coords=OrderedDict([
(agg.dims[1], agg.coords[agg.dims[1]]),
(agg.dims[0], agg.coords[agg.dims[0]]),
]),
name=name)
data = orient_array(agg).copy()
# Compute mask
if np.issubdtype(data.dtype, np.bool_):
mask = ~data
data = data.astype(np.int8)
else:
if np.issubdtype(data.dtype, np.integer):
mask = data == 0
else:
mask = np.isnan(data)
# Handle case where everything is masked out
if mask.all():
return Image(np.zeros(shape=agg.data.shape,
dtype=np.uint32), coords=agg.coords,
dims=agg.dims, attrs=agg.attrs, name=name)
# Handle offset / clip
if span is None:
offset = np.nanmin(data[~mask])
else:
offset = np.array(span, dtype=data.dtype)[0]
masked_clip_2d(data, mask, *span)
# If log/cbrt, could case to float64 right away
# If linear, can keep current type
data -= offset
with np.errstate(invalid="ignore", divide="ignore"):
# Transform data (log, eq_hist, etc.)
The compositing operator to combine pixels. Default is `'over'`.
"""
if not imgs:
raise ValueError("No images passed in")
for i in imgs:
if not isinstance(i, Image):
raise TypeError("Expected `Image`, got: `{0}`".format(type(i)))
name = kwargs.get('name', None)
op = composite_op_lookup[kwargs.get('how', 'over')]
if len(imgs) == 1:
return imgs[0]
imgs = xr.align(*imgs, copy=False, join='outer')
with np.errstate(divide='ignore', invalid='ignore'):
out = tz.reduce(tz.flip(op), [i.data for i in imgs])
return Image(out, coords=imgs[0].coords, dims=imgs[0].dims, name=name)
Parameters
-----------------
img : Image
color : color name or tuple, optional
The background color. Can be specified either by name, hexcode, or as a
tuple of ``(red, green, blue)`` values.
"""
if not isinstance(img, Image):
raise TypeError("Expected `Image`, got: `{0}`".format(type(img)))
name = img.name if name is None else name
if color is None:
return img
background = np.uint8(rgb(color) + (255,)).view('uint32')[0]
data = over(img.data, background)
return Image(data, coords=img.coords, dims=img.dims, name=name)