Utilities for data visualization (pwkit.data_gui_helpers)

pwkit.data_gui_helpers - helpers for GUIs looking at data arrays

Classes:

Clipper - Map data into [0,1] ColorMapper - Map data onto RGB colors using pwkit.colormaps Stretcher - Map data within [0,1] using a stretch like sqrt, etc.

Functions:

data_to_argb32 - Turn arbitrary data values into ARGB32 colors. data_to_imagesurface - Turn arbitrary data values into a Cairo ImageSurface.

class pwkit.data_gui_helpers.Stretcher(mode)[source]

Assumes that its inputs are in [0, 1]. Maps its outputs to the same range.

offset_cbrt(dest)[source]

This stretch is useful when you have values that are symmetrical around zero, and you want to enhance contrasts at small values while preserving sign.

pwkit.data_gui_helpers.data_to_argb32(data, cmin=None, cmax=None, stretch='linear', cmap='black_to_blue')[source]

Turn arbitrary data values into ARGB32 colors.

There are three steps to this process: clipping the data values to a maximum and minimum; stretching the spacing between those values; and converting their amplitudes into colors with some kind of color map.

data - Input data; can (and should) be a MaskedArray if some values are

invalid.

cmin - The data clip minimum; all values <= cmin are treated

identically. If None (the default), data.min() is used.

cmax - The data clip maximum; all values >= cmax are treated

identically. If None (the default), data.max() is used.

stretch - The stretch function name; ‘linear’, ‘sqrt’, or ‘square’; see

the Stretcher class.

cmap - The color map name; defaults to ‘black_to_blue’. See the

pwkit.colormaps module for more choices.

Returns a Numpy array of the same shape as data with dtype np.uint32, which represents the ARGB32 colorized version of the data. If your colormap is restricted to a single R or G or B channel, you can make color images by bitwise-or’ing together different such arrays.

pwkit.data_gui_helpers.data_to_imagesurface(data, **kwargs)[source]

Turn arbitrary data values into a Cairo ImageSurface.

The method and arguments are the same as data_to_argb32, except that the data array will be treated as 2D, and higher dimensionalities are not allowed. The return value is a Cairo ImageSurface object.

Combined with the write_to_png() method on ImageSurfaces, this is an easy way to quickly visualize 2D data.