nd.visualize package
Quickly visualize datasets.
- nd.visualize.colorize(labels, N=None, nan_vals=[], cmap='jet')[source]
Apply a color map to a map of integer labels.
- Parameters
labels (np.array, shape (M,N)) – The labeled image.
N (int, optional) – The number of colors to use (default: 10)
- Returns
A colored image in BGR space, ready to be handled by OpenCV.
- Return type
np.array, shape (M,N,3)
- nd.visualize.plot_map(ds, buffer=None, background='_default', imscale=6, gridlines=True, coastlines=True, scalebar=True, gridlines_kwargs={})[source]
Show the boundary of the dataset on a visually appealing map.
- Parameters
ds (xr.Dataset or xr.DataArray) – The dataset whose bounds to plot on the map.
buffer (float, optional) – Margin around the bounds polygon to plot, relative to the polygon dimension. By default, add around 20% on each side.
background (
cartopy.io.img_tiles
image tiles, optional) – The basemap to plot in the background (default: Stamen terrain). If None, do not plot a background map.imscale (int, optional) – The zoom level of the background image (default: 6).
gridlines (bool, optional) – Whether to plot gridlines (default: True).
coastlines (bool, optional) – Whether to plot coastlines (default: True).
scalebar (bool, optional) – Whether to add a scale bar (default: True).
gridlines_kwargs (dict, optional) – Additional keyword arguments for gridlines_with_labels().
- Returns
The corresponding GeoAxes object.
- Return type
cartopy.mpl.geoaxes.GeoAxes
- nd.visualize.to_rgb(data, output=None, vmin=None, vmax=None, pmin=2, pmax=98, categorical=False, mask=None, shape=None, cmap=None)[source]
Turn some data into a numpy array representing an RGB image.
- Parameters
data (list of DataArray) –
output (str) – file path
vmin (float or list of float) – minimum value, or list of values per channel (default: None).
vmax (float or list of float) – maximum value, or list of values per channel (default: None).
pmin (float) – lowest percentile to plot (default: 2). Ignored if vmin is passed.
pmax (float) – highest percentile to plot (default: 98). Ignored if vmax is passed.
categorical (bool, optional) – Whether the data is categorical. If True, return a randomly colorized image according to the data value (default: False).
mask (np.ndarray, optional) – If specified, parts of the image outside of the mask will be black.
shape (tuple, optional) – The output height and width (either or both may be None)
cmap (opencv colormap, optional) – The colormap used to colorize grayscale data
- Returns
Returns the generate RGB image if output is None, else returns None.
- Return type
np.ndarray or None
- nd.visualize.write_video(ds, path, timestamp='upper left', fontcolor=(0, 0, 0), width=None, height=None, fps=1, codec=None, rgb=None, cmap=None, mask=None, contours=None, **kwargs)[source]
Create a video from an xarray.Dataset.
- Parameters
ds (xarray.Dataset or xarray.DataArray) – The dataset must have dimensions ‘y’, ‘x’, and ‘time’.
path (str) – The output file path of the video.
timestamp (str, optional) – Location to print the timestamp: [‘upper left’, ‘lower left’, ‘upper right’, ‘lower right’, ‘ul’, ‘ll’, ‘ur’, ‘lr’] Set to None to disable (default: ‘upper left’).
fontcolor (tuple, optional) – RGB tuple for timestamp font color (default: (0, 0, 0), i.e., black).
width (int, optional) – The width of the video (default: ds.dim[‘x’])
height (int, optional) – The height of the video (default: ds.dim[‘y’])
fps (int, optional) – Frames per second (default: 1).
codec (str, optional) – fourcc codec (see http://www.fourcc.org/codecs.php)
rgb (callable, optional) – A callable that takes a Dataset as input and returns a list of R, G, B channels. By default will compute the C11, C22, C11/C22 representation. For a DataArray, use
cmap
.cmap (str, optional) – For DataArrays only. Colormap used to colorize univariate data.
mask (np.ndarray, optional) – If specified, parts of the image outside of the mask will be black.