ImageCollection को छोटा करना

ImageCollection में इमेज को कॉम्पोज़ करने के लिए, imageCollection.reduce() का इस्तेमाल करें. इससे कलेक्शन में मौजूद सभी इमेज को एक इमेज में जोड़ दिया जाएगा. उदाहरण के लिए, इमेज का कम से कम, ज़्यादा से ज़्यादा, औसत या स्टैंडर्ड वैरिएशन. (रिड्यूसर के बारे में ज़्यादा जानकारी के लिए, रिड्यूसर सेक्शन देखें). उदाहरण के लिए, किसी कलेक्शन से मीडियन वैल्यू वाली इमेज बनाने के लिए:

कोड एडिटर (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 API के बारे में जानकारी पाने और इंटरैक्टिव डेवलपमेंट के लिए geemap का इस्तेमाल करने के लिए, Python एनवायरमेंट पेज देखें.

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(), इस कॉल के लिए एक सुविधाजनक तरीका है:

कोड एडिटर (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 API के बारे में जानकारी पाने और इंटरैक्टिव डेवलपमेंट के लिए geemap का इस्तेमाल करने के लिए, Python एनवायरमेंट पेज देखें.

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() का इस्तेमाल करने पर, बैंड के नाम अलग-अलग हो जाते हैं. खास तौर पर, रिड्यूसर के नाम को बैंड के नामों के साथ जोड़ दिया गया है.

reduce() का इस्तेमाल करके, ज़्यादा जटिल डेटा को भी कम किया जा सकता है. उदाहरण के लिए, किसी कलेक्शन के लिए लंबे समय के लीनियर रुझान का हिसाब लगाने के लिए, लीनियर रिग्रेशन रिड्यूसर में से किसी एक का इस्तेमाल करें. नीचे दिया गया कोड, MODIS बेहतर वनस्पति सूचकांक (ईवीआई) के लीनियर रुझान का हिसाब लगाता है:

कोड एडिटर (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 API के बारे में जानकारी पाने और इंटरैक्टिव डेवलपमेंट के लिए geemap का इस्तेमाल करने के लिए, Python एनवायरमेंट पेज देखें.

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) के लिए होता है. ImageCollection को एक Image में कम करने के लिए उपलब्ध रिड्यूसर की सूची देखने के लिए, एपीआई दस्तावेज़ देखें.

कंपोजिट में कोई प्रोजेक्शन नहीं होता

इमेज कलेक्शन को छोटा करके बनाई गई कंपोजिट इमेज, अनुरोध किए गए किसी भी प्रोजेक्शन में पिक्सल जनरेट कर सकती हैं. इसलिए, उनका कोई तय आउटपुट प्रोजेक्शन नहीं होता. इसके बजाय, कंपोजिट में WGS-84 का डिफ़ॉल्ट प्रोजेक्शन होता है. इसमें पिक्सल का रिज़ॉल्यूशन एक डिग्री होता है. डिफ़ॉल्ट प्रोजेक्शन वाले कॉम्पोज़िट का हिसाब, उस आउटपुट प्रोजेक्शन में लगाया जाएगा जिसके लिए अनुरोध किया गया है. कोड एडिटर में कॉम्पोज़िट दिखाने पर अनुरोध होता है. साथ ही, ReduceRegion या Export जैसे एग्रीगेशन में प्रोजेक्शन/स्केल को साफ़ तौर पर बताने पर भी अनुरोध होता है. कोड एडिटर, स्केल और प्रोजेक्शन को कैसे सेट करता है, इस बारे में जानें.