/ee-palettes

A set of common color palettes for Google Earth Engine

Primary LanguageHTMLMIT LicenseMIT

ee-palettes

Gennadii Donchyts, Fedor Baart & Justin Braaten

About

ee-palettes is a module for generating color palettes in Google Earth Engine (EE) to be applied to mapped data.

Add the module

Visit this URL to add the module to the Reader repository of your EE account. After the module is added, you can find the source code in the Script Manager under: Reader:users/gena/packages/palettes.

How to use

Load the module

You can access the ee-palettes through the require() function. Running the following line will make the palettes available to you through JavaScript (JS) object access notation. The returned variable will be a nested series of JS objects ending in lists of hex colors.

var palettes = require('users/gena/packages:palettes');

Define a palette

Find a palette you like from the list below. Each palette is defined by a group and a name, which are separated by a period (JS object dot notation), and a color level.

To retrieve a desired palette, use JS object notation to specify the group, name, and number of color levels. The number of colors available varies by palette, which are listed following the palette names below. Note that all non-ColorBrewer palettes have only 7 colors, so always use 7 as the ‘color levels’ property for these palettes.

After determining the palette group, name, and color level, set the palette as a variable.

var palette = palettes.colorbrewer.RdYlGn[9];

Apply a palette

To apply the defined palette to map data, set the palette variable as the value for the palette key in the visParams object supplied to the Map.addLayer() function. It is also helpful to determine and define appropriate min and max values to ensure a good stretch. The following is a simple example of loading the ee-palettes module, defining a palette, and applying it to temperature data.

// Load some raster data: CONUS mean daily max temperature for January 2010
var tmax = ee.Image('OREGONSTATE/PRISM/AN81m/201001').select('tmax');

// Get a palette: a list of hex strings
var palettes = require('users/gena/packages:palettes');
var palette = palettes.misc.tol_rainbow[7];
 
// Display max temp with defined palette stretched between selected min and max
Map.addLayer(tmax, {min: -11, max: 25, palette: palette}, 'tmax');

Palette manipulation

Palette reverse

Reverse a palette with the reverse() function. Note that this will reverse the palette within the imported palette JS object, as well as the palette varible you happen to define. If you wish to leave the imported palette JS object unaltered, make a copy of the palette and then reverse it: .slice(0).reverse().

var palette = palettes.colorbrewer.RdYlGn[9].reverse();

Palette subset

If you only want to use a section of a palette, you can subset the colors you want using the slice() function. For instance, if you only want the pink to yellow section of the misc.gnuplot palette, use the following palette definition.

var palette = palettes.misc.gnuplot[7].slice(3,7);

Palettes

ColorBrewer Sequential

colorbrewer.Blues | 3,4,5,6,7,8,9
colorbrewer.BuGn | 3,4,5,6,7,8,9
colorbrewer.BuPu | 3,4,5,6,7,8,9
colorbrewer.GnBu | 3,4,5,6,7,8,9
colorbrewer.Greens | 3,4,5,6,7,8,9
colorbrewer.Greys | 3,4,5,6,7,8,9
colorbrewer.Oranges | 3,4,5,6,7,8,9
colorbrewer.OrRd | 3,4,5,6,7,8,9
colorbrewer.PuBu | 3,4,5,6,7,8,9
colorbrewer.PuBuGn | 3,4,5,6,7,8,9
colorbrewer.PuRd | 3,4,5,6,7,8,9
colorbrewer.Purples | 3,4,5,6,7,8,9
colorbrewer.RdPu | 3,4,5,6,7,8,9
colorbrewer.Reds | 3,4,5,6,7,8,9
colorbrewer.YlGn | 3,4,5,6,7,8,9
colorbrewer.YlGnBu | 3,4,5,6,7,8,9
colorbrewer.YlOrBr | 3,4,5,6,7,8,9
colorbrewer.YlOrRd | 3,4,5,6,7,8,9

ColorBrewer Diverging

colorbrewer.BrBG | 3,4,5,6,7,8,9,10,11
colorbrewer.PiYG | 3,4,5,6,7,8,9,10,11
colorbrewer.PRGn | 3,4,5,6,7,8,9,10,11
colorbrewer.PuOr | 3,4,5,6,7,8,9,10,11
colorbrewer.RdBu | 3,4,5,6,7,8,9,10,11
colorbrewer.RdGy | 3,4,5,6,7,8,9,10,11
colorbrewer.RdYlBu | 3,4,5,6,7,8,9,10,11
colorbrewer.RdYlGn | 3,4,5,6,7,8,9,10,11
colorbrewer.Spectral | 3,4,5,6,7,8,9,10,11

ColorBrewer Qualitative

colorbrewer.Accent | 3,4,5,6,7,8
colorbrewer.Dark2 | 3,4,5,6,7,8
colorbrewer.Paired | 3,4,5,6,7,8,9,10,11,12
colorbrewer.Pastel1 | 3,4,5,6,7,8,9
colorbrewer.Pastel2 | 3,4,5,6,7,8
colorbrewer.Set1 | 3,4,5,6,7,8,9
colorbrewer.Set2 | 3,4,5,6,7,8
colorbrewer.Set3 | 3,4,5,6,7,8,9,10,11,12

matplotlib

matplotlib.magma | 7
matplotlib.inferno | 7
matplotlib.plasma | 7
matplotlib.viridis | 7

cmocean

cmocean.Thermal | 7
cmocean.Haline | 7
cmocean.Solar | 7
cmocean.Ice | 7
cmocean.Gray | 7
cmocean.Oxy | 7
cmocean.Deep | 7
cmocean.Dense | 7
cmocean.Algae | 7
cmocean.Matter | 7
cmocean.Turbid | 7
cmocean.Speed | 7
cmocean.Amp | 7
cmocean.Tempo | 7
cmocean.Phase | 7
cmocean.Balance | 7
cmocean.Delta | 7
cmocean.Curl | 7

Niccoli

niccoli.cubicyf | 7
niccoli.cubicl | 7
niccoli.isol | 7
niccoli.linearl | 7
niccoli.linearlhot | 7

Kovesi

kovesi.cyclic_grey_15_85_c0 | 7
kovesi.cyclic_grey_15_85_c0_s25 | 7
kovesi.cyclic_mrybm_35_75_c68 | 7
kovesi.cyclic_mrybm_35_75_c68_s25 | 7
kovesi.cyclic_mygbm_30_95_c78 | 7
kovesi.cyclic_mygbm_30_95_c78_s25 | 7
kovesi.cyclic_wrwbw_40_90_c42 | 7
kovesi.cyclic_wrwbw_40_90_c42_s25 | 7
kovesi.diverging_isoluminant_cjm_75_c23 | 7
kovesi.diverging_isoluminant_cjm_75_c24 | 7
kovesi.diverging_isoluminant_cjo_70_c25 | 7
kovesi.diverging_linear_bjr_30_55_c53 | 7
kovesi.diverging_linear_bjy_30_90_c45 | 7
kovesi.diverging_rainbow_bgymr_45_85_c67 | 7
kovesi.diverging_bkr_55_10_c35 | 7
kovesi.diverging_bky_60_10_c30 | 7
kovesi.diverging_bwr_40_95_c42 | 7
kovesi.diverging_bwr_55_98_c37 | 7
kovesi.diverging_cwm_80_100_c22 | 7
kovesi.diverging_gkr_60_10_c40 | 7
kovesi.diverging_gwr_55_95_c38 | 7
kovesi.diverging_gwv_55_95_c39 | 7
kovesi.isoluminant_cgo_70_c39 | 7
kovesi.isoluminant_cgo_80_c38 | 7
kovesi.isoluminant_cm_70_c39 | 7
kovesi.rainbow_bgyr_35_85_c72 | 7
kovesi.rainbow_bgyr_35_85_c73 | 7
kovesi.rainbow_bgyrm_35_85_c69 | 7
kovesi.rainbow_bgyrm_35_85_c71 | 7
kovesi.linear_bgy_10_95_c74 | 7
kovesi.linear_bgyw_15_100_c67 | 7
kovesi.linear_bgyw_15_100_c68 | 7
kovesi.linear_blue_5_95_c73 | 7
kovesi.linear_blue_95_50_c20 | 7
kovesi.linear_bmw_5_95_c86 | 7
kovesi.linear_bmw_5_95_c89 | 7
kovesi.linear_bmy_10_95_c71 | 7
kovesi.linear_bmy_10_95_c78 | 7
kovesi.linear_gow_60_85_c27 | 7
kovesi.linear_gow_65_90_c35 | 7
kovesi.linear_green_5_95_c69 | 7
kovesi.linear_grey_0_100_c0 | 7
kovesi.linear_grey_10_95_c0 | 7
kovesi.linear_kry_5_95_c72 | 7
kovesi.linear_kry_5_98_c75 | 7
kovesi.linear_kryw_5_100_c64 | 7
kovesi.linear_kryw_5_100_c67 | 7
kovesi.linear_ternary_blue_0_44_c57 | 7
kovesi.linear_ternary_green_0_46_c42 | 7
kovesi.linear_ternary_red_0_50_c52 | 7

Misc

misc.coolwarm | 7
misc.warmcool | 7
misc.cubehelix | 7
misc.gnuplot | 7
misc.jet | 7
misc.parula | 7
misc.tol_rainbow | 7
misc.cividis | 7

References

Palettes were derived from the pals R library. Please see its documentation and repository for palette source information.