Save-Best Joins

หากต้องการบันทึกเฉพาะรายการที่ตรงกันที่สุดสำหรับองค์ประกอบแต่ละรายการในคอลเล็กชัน ให้ใช้ ee.Join.saveBest() การรวม saveBest() ทํางานในลักษณะที่เทียบเท่าการรวม saveAll() ยกเว้นสําหรับแต่ละองค์ประกอบในคอลเล็กชัน primary ระบบจะบันทึกองค์ประกอบจากคอลเล็กชัน secondary ที่ตรงกันที่สุด ระบบจะทิ้งองค์ประกอบที่ตรงกันไม่ได้ในคอลเล็กชันหลัก สมมติว่าคุณต้องการค้นหาภาพอุตุนิยมวิทยาที่ใกล้เคียงกับเวลาของภาพ Landsat แต่ละภาพในคอลเล็กชัน primary มากที่สุด หากต้องการใช้การรวมนี้ คุณต้องกําหนดค่า 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’) การตรวจสอบผลลัพธ์แสดงให้เห็นว่ามีการเพิ่มรูปภาพ DAYMET ที่ตรงกันลงในพร็อพเพอร์ตี้ bestImage สำหรับแต่ละภาพ Landsat ในคอลเล็กชัน primary รูปภาพ DAYMET แต่ละรูปมีพร็อพเพอร์ตี้ timeDiff ซึ่งระบุความแตกต่างของเวลาเป็นมิลลิวินาทีระหว่างรูปภาพ DAYMET กับรูปภาพ Landsat ซึ่งจะเป็นค่าต่ำสุดในรูปภาพ DAYMET ที่ผ่านเงื่อนไขในตัวกรอง