Welcome to colorella’s documentation!¶
Created On 2019-10-16, last modified @author: Felix Reuß felix.reuss@geo.tuwien.ac.at - includes functions from pytesmo package https://github.com/TUW-GEO/pytesmo
Colorella Package: Color organizing and easy to learn laboratory The packages allows to load color maps from several sources including: - matplotlib default colormaps (e.g viridis, plasma) - colorcet colormaps (e.g fire, rainbow) - cpt files - ct files - json - or to create new colormaps from dictionaries or lists of colors classmethods allow the following functions: - save a newly or modified colormap as .cpt, .ct or .json file - turn a colormap to greyscale (e.g. for printing in greyscale) - reverse a colormap - view a colormap as plot - load or convert to gdal colortable objects - create a list or dictionary object contaning all the colors from a colormap
-
class
colorella.colormap.
ColorMap
(arg)¶ create a colormap object compatible with matplotlib
-
convert2greyscale
(weights=1, inplace=True)¶ Return a grayscale version of the given colormap. Luminanance values are calculated using a dot product of a weight array and the color array of the object
- Parameters
weights (int) – weights used to convert RGB values to luminance, default =1
inplace (bool) – if True the original object is replaced, if False a new ColorMap object is returned
- Returns
- Return type
ColorMap object if inpalce = False
-
classmethod
from_cptfile
(filepath, gradient=True)¶ Create a LinearSegmented Colormap from a .cpt file
- Parameters
filepath (str) – absolute filepath including filename and extension of the cpt file
- Returns
- Return type
ColorMap object (LinearSegmented Colormap object)
-
classmethod
from_ctfile
(filepath, gradient=True)¶ Create a Listed Colormap from a gdal .ct file
- Parameters
filepath (str) – absolute filepath including filename and extension of the ct file
- Returns
- Return type
ColorMap object (Listed Colormap object)
-
classmethod
from_dict
(cdict, name='default')¶ Create color map from linear mapping segments Parameters: ———- cdict: dictionary
- cdict argument is a dictionary with a red, green and blue
entries. Each entry should be a list of x, y0, y1 tuples, forming rows in a table. Entries for alpha are optional.
example from matplotlib: suppose you want red to increase from 0 to 1 over
the bottom half, green to do the same over the middle half, and blue over the top half. Then you would use:
cdict = {'red': [(0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)], 'green': [(0.0, 0.0, 0.0), (0.25, 0.0, 0.0), (0.75, 1.0, 1.0), (1.0, 1.0, 1.0)], 'blue': [(0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (1.0, 1.0, 1.0)]}
Each row in the table for a given color is a sequence of x, y0, y1 tuples. In each sequence, x must increase monotonically from 0 to 1. For any input value z falling between x[i] and x[i+1], the output value of a given color will be linearly interpolated between y1[i] and y0[i+1]:
row i: x y0 y1 / / row i+1: x y0 y1
Hence y0 in the first row and y1 in the last row are never used.
- name: str
name of the Colormap
- Returns
- Return type
ColorMap object (LinearSegmented Colormap object)
-
classmethod
from_file
(filepath, name=None, gradient=True)¶ Function to open colormap objects from .cpt, .ct, .json files
- filepath: str
path and filename of the colormap to be opened
- name: str, optional
name of the Colormap
- Returns
- Return type
ColorMap object
-
classmethod
from_gdal
(ct)¶ Converts a gdal Colortable to a matplotlib colormap
- Parameters
ct (gdal colortable object) – gdal colortable object from which a ColorMap shall be created
- Returns
- Return type
ColorMap object (Listed Colormap object)
-
classmethod
from_jsonfile
(filepath)¶ Creates a LinearSegmented Colormap from a .json file
- Parameters
filepath (str) – absolute filepath including filename and extension of the json file
- Returns
- Return type
ColorMap object (LinearSegmented or Listed Colormap object)
-
classmethod
from_list
(clist, name='default', gradient=False)¶ Make a linear segmented colormap with name from a sequence of colors which evenly transitions from colors[0] at val=0 to colors[-1] at val=1. Alternatively, a list of (value, color) tuples can be given to divide
- Parameters
clist (list) – list of colors given as RGBA tuples
name (str) – name of the Colormap
gradient (bool) – if False a Listed Colormap is created, if True a LinearSegmented Colormap is created
- Returns
- Return type
ColorMap object (LinearSegmented or Listed Colormap object)
-
property
name
¶ Returns attribute name
- Returns
- Return type
attribute name
-
reverse
(inplace=True)¶ Reverses a colormap, a.k.a returns the containing colors in reverse direction. Class type remains the same
- Parameters
inplace (bool) – if True the original object is replaced, if False a new ColorMap object is returned
- Returns
- Return type
ColorMap object if inplace = False
-
save_as_cpt
(outpath=None, **kwargs)¶ Saves a acolormap.object as a .cpt file
- Parameters
outname (str, optional) – outname for the file
keyword arguments (int) – Vmin, Vmax, N (Number of colorsteps)
-
save_as_ct
(outpath=None)¶ Saves a colormap.object as a gdal .ct file
- Parameters
outname (str, optional) – outname for the file
-
save_as_json
(outpath=None)¶ Saves a colormap.object as a gdal .ct file
- Parameters
outname (str, optional) – outname for the file
-
show
()¶ Shows the colormap as a colorbar in a plot
-
to_dict
()¶ Creates a dictionary of colors from a colormap object
- Returns
- Return type
dict object
-
to_gdal
(accelerate=1)¶ Converts a ColorMap object to a gdal colortable object
- Parameters
accelerate (int) – scale factor applied to Colors
- Returns
- Return type
Gdal color table object
-
to_gradient
(inplace=True)¶ Converts a listed Colormap to a Linear Segmented Colormap
- Parameters
outname (str, optional) – filename if the colormap is saved
inplace (bool) – if True the original object is replaced, if False a new ColorMap object is returned
- Returns
- Return type
ColorMap object is inplace = False
-
to_list
()¶ Creates a list of colors from a colormap object
- Returns
- Return type
List object
-
to_matplotlib
()¶ Returns the matplotlib colormap object
- Returns
- Return type
matplotlib colormap object
-