צירופי Save-Best

כדי לשמור רק את ההתאמה הטובה ביותר לכל רכיב באוסף, צריך להשתמש ב-ee.Join.saveBest(). הצירוף saveBest() פועל באופן שווה ערך לצירוף saveAll(), מלבד העובדה שלכל רכיב באוסף primary, הוא שומר את הרכיב מהאוסף secondary עם ההתאמה הטובה ביותר. רכיבים שלא נמצא להם התאמה באוסף הראשי יושמטו. נניח שהמטרה היא למצוא תמונה מטאורולוגית שהכי קרובה בזמן לכל תמונה של Landsat באוסף primary. כדי לבצע את המיזוג הזה, צריך להגדיר מחדש את ee.Filter לתנאי מיזוג יחיד (מסננים משולבים לא יפעלו עם saveBest() כי לא ברור איך לשלב דירוגים מכמה מסנני משנה):

Code Editor‏ (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 מפורט מידע על Python API ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

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 שעומדות בתנאי שבמסנן.