ee.Dictionary.map

辞書にアルゴリズムをマッピングします。このアルゴリズムは、既存の辞書のキーとそれに対応する値の 2 つの引数を取り、指定されたキーの新しい値を返すことが想定されています。アルゴリズムが null を返すと、キーは削除されます。

用途戻り値
Dictionary.map(baseAlgorithm)Dictionary
引数タイプ詳細
これ: dictionaryDictionary
baseAlgorithmアルゴリズム

コードエディタ(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 の設定

Python API とインタラクティブな開発での geemap の使用については、 Python 環境のページをご覧ください。

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())