disdrodb.viz package#

Submodules#

disdrodb.viz.plots module#

DISDRODB Plotting Tools.

disdrodb.viz.plots.compute_dense_lines(da: DataArray, coord: str, x_bins: list, y_bins: list, normalization='max')[source][source]#

Compute a 2D density-of-lines histogram from an xarray.DataArray.

Parameters:
  • da (xarray.DataArray) – Input data array. One of its dimensions (named by coord) is taken as the horizontal coordinate. All other dimensions are collapsed into “series,” so that each combination of the remaining dimension values produces one 1D line along coord.

  • coord (str) – The name of the coordinate/dimension of the DataArray to bin over. da.coords[coord] must be a 1D numeric array (monotonic is recommended).

  • x_bins (array_like of shape (nx+1,)) – Bin edges to bin the coordinate/dimension. Must be monotonically increasing. The number of x-bins will be nx = len(x_bins) - 1.

  • y_bins (array_like of shape (ny+1,)) – Bin edges for the DataArray values. Must be monotonically increasing. The number of y-bins will be ny = len(y_bins) - 1.

  • normalization (bool, optional) – If ‘none’, returns the raw histogram. By default, the function normalize the histogram by its global maximum (‘max’). Log-normalization (‘log’) is also available.

Returns:

2D histogram of shape (ny, nx). Dimensions are ('y', 'x'), where:

  • x: the bin-center coordinate of x_bins (length nx)

  • y: the bin-center coordinate of y_bins (length ny)

Each element out.values[y_i, x_j] is the count (or normalized count) of how many “series-values” from da fell into the rectangular bin x_bins[j] x_value < x_bins[j+1] and y_bins[i] data_value < y_bins[i+1].

Return type:

xr.DataArray

References

Moritz, D., Fisher, D. (2018). Visualizing a Million Time Series with the Density Line Chart https://doi.org/10.48550/arXiv.1808.06019

disdrodb.viz.plots.max_blend_images(ds_rgb, dim)[source][source]#

Max blend a RGBA DataArray across a samples dimensions.

disdrodb.viz.plots.normalize_array(arr, method='max')[source][source]#

Normalize a NumPy array according to the chosen method.

Parameters:
  • arr (np.ndarray) – Input array.

  • method (str) – Normalization method. Options: - ‘max’ : Divide by the maximum value. - ‘minmax’: Scale to [0, 1] range. - ‘zscore’: Standardize to mean 0, std 1. - ‘log’ : Apply log10 transform (shifted if min <= 0). - ‘none’ : No normalization (return original array).

Returns:

Normalized array.

Return type:

np.ndarray

disdrodb.viz.plots.plot_nd(ds, var='drop_number_concentration', cmap=None, norm=None)[source][source]#

Plot drop number concentration N(D) timeseries.

disdrodb.viz.plots.plot_raw_and_filtered_spectra(ds, cmap=None, norm=None, extend='max', add_theoretical_average_velocity=True, add_measured_average_velocity=True, figsize=(8, 4), dpi=300)[source][source]#

Plot raw and filtered drop spectrum.

disdrodb.viz.plots.plot_spectrum(xr_obj, variable='raw_drop_number', ax=None, cmap=None, norm=None, extend='max', add_colorbar=True, cbar_kwargs=None, title='Drop Spectrum', **plot_kwargs)[source][source]#

Plot the spectrum.

Parameters:
  • xr_obj (xarray.Dataset or xarray.DataArray) – Input xarray object. If Dataset, the variable to plot must be specified. If DataArray, it must have both diameter and velocity dimensions.

  • variable (str) – Name of the variable to plot if xr_obj is a Dataset.

  • ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, uses current axes or creates a new one.

  • cmap (Colormap, optional) – Colormap to use. If None, uses ‘Spectral_r’ with ‘under’ set to ‘none’.

  • norm (matplotlib.colors.Normalize, optional) – Normalization for colormap. If None, uses LogNorm with vmin=1.

  • extend ({'neither', 'both', 'min', 'max'}, optional) – Whether to draw arrows on the colorbar to indicate out-of-range values. Default is ‘max’.

  • add_colorbar (bool, optional) – Whether to add a colorbar. Default is True.

  • cbar_kwargs (dict, optional) – Additional keyword arguments for colorbar. If None, uses {‘label’: ‘Number of particles ‘}.

  • title (str, optional) – Title of the plot. Default is ‘Drop Spectrum’.

  • **plot_kwargs (dict) – Additional keyword arguments passed to xarray’s plot.pcolormesh method.

Notes

  • If the input DataArray has a time dimension, it is summed over time before plotting

    unless FacetGrid options (e.g., col, row) are specified in plot_kwargs.

  • If FacetGrid options are used, the plot will create a grid of subplots for each time slice. To create a FacetGrid plot, use:

    ds.isel(time=slice(0, 9)).disdrodb.plot_spectrum(col=”time”, col_wrap=3)

disdrodb.viz.plots.to_rgba(obj, cmap='viridis', norm=None, scaling='none')[source][source]#

Map a xarray DataArray (or numpy array) to RGBA with optional alpha-scaling.

Module contents#

DISDRODB Visualization Module.