Map an algorithm over a dictionary. The algorithm is expected to take 2 arguments, a key from the existing dictionary and the value it corresponds to, and return a new value for the given key. If the algorithm returns null, the key is dropped.
Usage | Returns | Dictionary.map(baseAlgorithm) | Dictionary |
Argument | Type | Details | this: dictionary | Dictionary | |
baseAlgorithm | Algorithm | |
Examples
Code Editor (JavaScript)
// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
var dict = ee.Dictionary({
B1: 182,
B2: 219,
B3: 443
});
/**
* Convert S2 surface reflectance units to native scale.
*/
function scale(key, value) {
return ee.Number(value).divide(1e4);
}
print('S2 surface reflectance in native units', dict.map(scale));
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
Colab (Python)
# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
dic = ee.Dictionary({
'B1': 182,
'B2': 219,
'B3': 443
})
def scale(key, value):
"""Convert S2 surface reflectance units to native scale."""
return ee.Number(value).divide(1e4)
print('S2 surface reflectance in native units:', dic.map(scale).getInfo())