צמצום של ImageCollection

כדי ליצור תמונה מורכבת ב-ImageCollection, משתמשים ב-imageCollection.reduce(). הפעולה הזו תשלב את כל התמונות בקולקציה לתמונה אחת שמייצגת, לדוגמה, את הערך המינימלי, המקסימלי, הממוצע או סטיית התקן של התמונות. (מידע נוסף על reducers זמין בקטע reducers). לדוגמה, כדי ליצור תמונה של ערך חציוני מאוסף:

Code Editor‏ (JavaScript)

// Load a Landsat 8 collection for a single path-row.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filter(ee.Filter.eq('WRS_PATH', 44))
    .filter(ee.Filter.eq('WRS_ROW', 34))
    .filterDate('2014-01-01', '2015-01-01');

// Compute a median image and display.
var median = collection.median();
Map.setCenter(-122.3578, 37.7726, 12);
Map.addLayer(median, {bands: ['B4', 'B3', 'B2'], max: 0.3}, 'Median');

הגדרת Python

בדף סביבת Python מפורט מידע על Python API ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Load a Landsat 8 collection for a single path-row.
collection = (
    ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
    .filter(ee.Filter.eq('WRS_PATH', 44))
    .filter(ee.Filter.eq('WRS_ROW', 34))
    .filterDate('2014-01-01', '2015-01-01')
)

# Compute a median image and display.
median = collection.median()
m = geemap.Map()
m.set_center(-122.3578, 37.7726, 12)
m.add_layer(median, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3}, 'Median')
m

בכל מיקום בתמונה הפלט, בכל פס, ערך הפיקסל הוא החציון של כל הפיקסלים ללא מסכה בתמונות הקלט (התמונות בקולקציה). בדוגמה הקודמת, median() היא שיטה נוחה לקריאה הבאה:

Code Editor‏ (JavaScript)

// Reduce the collection with a median reducer.
var median = collection.reduce(ee.Reducer.median());

// Display the median image.
Map.addLayer(median,
             {bands: ['B4_median', 'B3_median', 'B2_median'], max: 0.3},
             'Also median');

הגדרת Python

בדף סביבת Python מפורט מידע על Python API ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# Reduce the collection with a median reducer.
median = collection.reduce(ee.Reducer.median())

# Display the median image.
m.add_layer(
    median,
    {'bands': ['B4_median', 'B3_median', 'B2_median'], 'max': 0.3},
    'Also median',
)
m

שימו לב לשמות השונים של הלהקות, שנובעים משימוש ב-reduce() במקום ב-method הנוחה. באופן ספציפי, שמות המצמצמים נוספו לשמות של הלהקות.

אפשר גם להשתמש ב-reduce() כדי לבצע הפחתות מורכבות יותר. לדוגמה, כדי לחשב את המגמה הלינארית לטווח ארוך בתוך אוסף, משתמשים באחד ממפחיתי הרגרסיה הלינאריים. הקוד הבא מחשב את המגמה הליניארית של מדד הצמחייה המשופרת (EVI) של MODIS:

Code Editor‏ (JavaScript)

// This function adds a band representing the image timestamp.
var addTime = function(image) {
  return image.addBands(image.metadata('system:time_start')
    // Convert milliseconds from epoch to years to aid in
    // interpretation of the following trend calculation.
    .divide(1000 * 60 * 60 * 24 * 365));
};

// Load a MODIS collection, filter to several years of 16 day mosaics,
// and map the time band function over it.
var collection = ee.ImageCollection('MODIS/006/MYD13A1')
  .filterDate('2004-01-01', '2010-10-31')
  .map(addTime);

// Select the bands to model with the independent variable first.
var trend = collection.select(['system:time_start', 'EVI'])
  // Compute the linear trend over time.
  .reduce(ee.Reducer.linearFit());

// Display the trend with increasing slopes in green, decreasing in red.
Map.setCenter(-96.943, 39.436, 5);
Map.addLayer(
    trend,
    {min: 0, max: [-100, 100, 10000], bands: ['scale', 'scale', 'offset']},
    'EVI trend');

הגדרת Python

בדף סביבת Python מפורט מידע על Python API ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# This function adds a band representing the image timestamp.
def add_time(image):
  return image.addBands(
      image.metadata('system:time_start')
      # Convert milliseconds from epoch to years to aid in
      # interpretation of the following trend calculation.
      .divide(1000 * 60 * 60 * 24 * 365)
  )


# Load a MODIS collection, filter to several years of 16 day mosaics,
# and map the time band function over it.
collection = (
    ee.ImageCollection('MODIS/006/MYD13A1')
    .filterDate('2004-01-01', '2010-10-31')
    .map(add_time)
)

# Select the bands to model with the independent variable first.
trend = collection.select(['system:time_start', 'EVI']).reduce(
    # Compute the linear trend over time.
    ee.Reducer.linearFit()
)

# Display the trend with increasing slopes in green, decreasing in red.
m.set_center(-96.943, 39.436, 5)
m = geemap.Map()
m.add_layer(
    trend,
    {
        'min': 0,
        'max': [-100, 100, 10000],
        'bands': ['scale', 'scale', 'offset'],
    },
    'EVI trend',
)
m

שימו לב שהפלט של הפחתת המאפיינים בדוגמה הזו הוא תמונה עם שתי רצועות, עם רצועה אחת לשימוש במדרון של רגרסיה לינארית (scale) ורצועה אחת לשימוש בנקודת החיתוך (offset). במסמכי התיעוד של ה-API מופיעה רשימה של הפחתות המאפיינים שזמינות להפחתת ImageCollection ל-Image יחיד.

לתמונות מורכבות אין הקרנה

תמונות מורכבות שנוצרות על ידי צמצום אוסף תמונות יכולות לייצר פיקסלים בכל הקרנה מתוזמנת, ולכן אין להן הקרנת פלט קבועה. במקום זאת, למוצרים המשולבים יש תצוגה שמוגדרת כברירת מחדל של WGS-84 עם פיקסלים ברזולוציה של מעלה אחת. אובייקטים מורכבים עם הקרנה שמוגדרת כברירת מחדל יחושבו בכל הקרנת פלט שתתבקש. הבקשה מתבצעת על ידי הצגת המאפיין המשולב בכלי לעריכת קוד (מידע נוסף על האופן שבו כלי לעריכת קוד מגדיר סולם והצגה), או על ידי ציון מפורש של הצגה/סולם, כמו בצבירה כמו ReduceRegion או Export.