Google Earth Engine(GEE)——ee-palettes

ee-palettes

Gennadii Donchyts, Fedor Baart & Justin Braaten

about

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

Add module

Visit this URL to add the module to your GEE account's reader repository. After adding the module, you can find the source code in the Script Manager at:Reader: users/gena/packages/palettes.

how to use

Load module

You can access the ee palette through therequire() function. Running the following line will make the palette available to you via JavaScript (JS) object access notation. The returned variable will be a nested series of JS objects ending with a list of hexadecimal colors.

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

Define color palette

Each palette is defined by a group and a name, which are separated by periods (JS object dot notation) and color levels.

If you want to retrieve the desired palette, use JS object notation to specify the group, name, and number of shades. The number of available colors varies by palette, which is listed below after the palette name. Note that all non-ColorBrewer palettes only have 7 colors, so always use 7 for the Levels property of these palettes.

After you determine the palette group, name, and scale, set the palette as a variable.

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

application

To apply the defined palette to the map data, set the palette variable to the object supplied to the Map.addLayer() function. The value of the swatch key. It is also helpful to determine and define appropriate minimum and maximum values ​​to ensure good stretching. Below is a simple example of loading the module, defining a color palette, and applying it to temperature data. visParamsee-palettes

// 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 operations

Palette inversion

Use the reverse() function to invert the palette. Note that this will invert the palette in the imported palette JS object, as well as any palette variables you happen to define. If you want the imported palette JS object to remain unchanged, copy the palette and then invert it: .slice(0).reverse().

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

palette subset

If you only want to use a certain part of the palette, you can use theslice() function to subset the desired colors. For example, if you only want the pink to yellow portion of the misc.gnuplot palette, use the following palette definition.

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

color palette

References

Most palettes were derived from the pals R library. Please see its documentation and repository for palette source information.misc.BlueFluorite source: https://gist.github.com/jscarto/6cc7f547bb7d5d9acda51e5c15256b01

Guess you like

Origin blog.csdn.net/weixin_48048649/article/details/128876843