Save-Best Joins

コレクション内の各要素に最も一致する値のみを保存するには、ee.Join.saveBest() を使用します。saveBest() 結合は saveAll() 結合と同様に機能しますが、primary コレクション内の各要素を除き、最も一致する secondary コレクションの要素を保存します。プライマリ コレクション内の一致しない要素は破棄されます。primary コレクション内の各 Landsat 画像に最も近い時間の天気画像を見つけたいとします。この結合を実行するには、単一の結合条件に対して ee.Filter を再定義する必要があります(複数のサブフィルタのランクをどのように結合するかが不明確であるため、結合フィルタは saveBest() では機能しません)。

コードエディタ(JavaScript)

// Load a primary collection: Landsat imagery.
var primary = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filterDate('2014-04-01', '2014-06-01')
    .filterBounds(ee.Geometry.Point(-122.092, 37.42));

// Load a secondary collection: GRIDMET meteorological data
var gridmet = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET');

// Define a max difference filter to compare timestamps.
var maxDiffFilter = ee.Filter.maxDifference({
  difference: 2 * 24 * 60 * 60 * 1000,
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

// Define the join.
var saveBestJoin = ee.Join.saveBest({
  matchKey: 'bestImage',
  measureKey: 'timeDiff'
});

// Apply the join.
var landsatMet = saveBestJoin.apply(primary, gridmet, maxDiffFilter);

// Print the result.
print(landsatMet);

Python の設定

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

import ee
import geemap.core as geemap

Colab(Python)

# Load a primary collection: Landsat imagery.
primary = (
    ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filterDate('2014-04-01', '2014-06-01')
    .filterBounds(ee.Geometry.Point(-122.092, 37.42))
)

# Load a secondary collection: GRIDMET meteorological data
gridmet = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET')

# Define a max difference filter to compare timestamps.
max_diff_filter = ee.Filter.maxDifference(
    difference=2 * 24 * 60 * 60 * 1000,
    leftField='system:time_start',
    rightField='system:time_start',
)

# Define the join.
save_best_join = ee.Join.saveBest(matchKey='bestImage', measureKey='timeDiff')

# Apply the join.
landsat_met = save_best_join.apply(primary, gridmet, max_diff_filter)

# Print the result.
display(landsat_met)

saveBest() 結合では、最適な一致を保存するプロパティの名前(‘bestImage’)と、一致の良さを示す指標を保存するプロパティの名前(‘timeDiff’)を定義します。結果を調べると、primary コレクション内の Landsat シーンごとに、一致する DAYMET 画像がプロパティ bestImage に追加されていることがわかります。これらの DAYMET 画像にはそれぞれ、DAYMET 画像と Landsat 画像の間のミリ秒単位の時間差を示す timeDiff プロパティがあります。これは、フィルタの条件を満たす DAYMET 画像の中で最小値になります。