Visualisation

ela.visual module

class ela.visual.LithologiesClassesVisual(class_names, color_names, missing_value_color_name)

Bases: object

Visual information to map to rendering lithology classes

A parent helper class with lithology classes and color scheme information to apply to data in a set of custom visual rendering using Mayavi

class_names
Type

str

color_names
Type

str

color_names_with_missing
Type

str

nb_labels()

Gets the number of classes. Used for e.g. legend’s portioning

nb_labels_with_missing()

Gets the number of classes plus one for the missing value code. Used for e.g. legend’s portioning

ela.visual.cartopy_color_settings(color_names, numeric_classes=None)

Builds a discrete color settings for use in cartopy functions.

Parameters
  • color_names (list of str) – color names e.g. [‘navyblue’,’red’]

  • numeric_classes (list of int) – numeric code for classes. Defaults to zero-based integers if None.

Returns

color map with keys ‘cmap’, ‘bounds’, ‘norm’

Return type

dict

ela.visual.discrete_classes_colormap(color_names)

Builds a colormap mapping from zero-indexed class codes to rgba colors

Parameters

color_names (list of str) – color names e.g. [‘navyblue’,’red’]

Returns

color map with keys as zero based numeric integers and values RGBA tuples.

Return type

dict

ela.visual.get_color_component(color_array, color_index)

Gets one of the color components in an RGBA image specification. Helper function to save geotiff.

Parameters
  • color_array (ndarray) – numpy array, 3 dims (x, y, and RGBA)

  • color_index (int) – index, 0 to 3, for which of the RGBA component to retrieve

Returns

2D array with the color component of interes

Return type

ndarray

ela.visual.interp(x1, x2, fraction)
ela.visual.interp_color(t_c1, t_c2, fraction)
ela.visual.interpolate_rgba(cmap, lower_index, fraction, type='linear')

Interpolate between two colors

Parameters
  • cmap (dict) – color map with keys as zero based numeric integers and values RGBA tuples.

  • lower_index (int) – lower_index, key to the color to interpolate from (to the next color at lower_index + 1)

  • fraction (float) – 0 to 1, weight to interpolate between the two colors

  • type (str) – ignored; future arg for other interpolation schemes.

Returns

RGBA values.

Return type

tuple

ela.visual.legend_fig(k_legend_display_info)

Plot a legend for color coded classes. Adapted from https://matplotlib.org/examples/color/named_colors.html

Parameters

k_legend_display_info (list) – values are 3-item tuples (rgb_val(not used), k_label, colorname)

Returns

Return type

matplotlib Figure

ela.visual.show_wordcloud(text, title=None, max_words=200, max_font_size=40, seed=1, scale=3, figsize=(12, 12))

Plot wordclouds from text

Parameters

text (str or list of str) – text to depict

ela.visual.to_carto(x)

Reorient an array X-Y to an array suitable for ‘natural’ orientation with cartopy

Parameters

x (ndarray) – numpy array, 2 dims

Returns

2D array

Return type

ndarray

ela.visual.to_color_image(x, cmap)

Convert a 2D array to a color representation (RGBA)

Parameters
  • x (2d array) – array of data to reprecent as colors

  • cmap (dict) – discrete color map with keys as zero based numeric integers and values RGBA tuples.

Returns

RGBA values.

Return type

tuple

ela.visual.to_rgb(color_name)

Returns an RGB tuple of three floats from 0-1. shortcut to matplotlib, needed bc anaconda2 seems stuck with Matplotlib 1.5 .

color_name can be an RGB or RGBA sequence or a string in any of several forms:

  1. a letter from the set ‘rgbcmykw’

  2. a hex color string, like ‘#00FFFF’

  3. a standard name, like ‘aqua’

  4. a string representation of a float, like ‘0.4’,

    indicating gray on a 0-1 scale

if arg is RGBA, the A will simply be discarded.

ela.visual.to_rgb_255(colorname)

Returns an RGB tuple of three ints from 0-255

ela.visual.to_rgba_255(colorname, alpha=255)

Returns an RGBA tuple of 4 ints from 0-255