वज़न में कमी

डिफ़ॉल्ट रूप से, इमेजरी पर लागू किए गए रिड्यूसर, इनपुट को मास्क वैल्यू के हिसाब से तवज्जो देते हैं. यह clip() जैसे ऑपरेशन से बनाए गए फ़्रैक्शनल पिक्सल के संदर्भ में काम का है. रिड्यूसर पर unweighted() को कॉल करके, इस व्यवहार में बदलाव करें. बिना वज़न वाले रिड्यूसर का इस्तेमाल करने से, क्षेत्र के सभी पिक्सल का वज़न एक जैसा हो जाता है. यहां दिए गए उदाहरण में दिखाया गया है कि पिक्सल की अहमियत से, रिड्यूसर के आउटपुट पर क्या असर पड़ सकता है:

कोड एडिटर (JavaScript)

// Load a Landsat 8 input image.
var image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318');

// Create an arbitrary region.
var geometry = ee.Geometry.Rectangle(-122.496, 37.532, -121.554, 37.538);

// Make an NDWI image.  It will have one band named 'nd'.
var ndwi = image.normalizedDifference(['B3', 'B5']);

// Compute the weighted mean of the NDWI image clipped to the region.
var weighted = ndwi.clip(geometry)
  .reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: geometry,
    scale: 30})
  .get('nd');

// Compute the UN-weighted mean of the NDWI image clipped to the region.
var unweighted = ndwi.clip(geometry)
  .reduceRegion({
    reducer: ee.Reducer.mean().unweighted(),
    geometry: geometry,
    scale: 30})
  .get('nd');

// Observe the difference between weighted and unweighted reductions.
print('weighted:', weighted);
print('unweighted', unweighted);

Python सेटअप

Python API के बारे में जानकारी पाने और इंटरैक्टिव डेवलपमेंट के लिए geemap का इस्तेमाल करने के लिए, Python एनवायरमेंट पेज देखें.

import ee
import geemap.core as geemap

Colab (Python)

# Load a Landsat 8 input image.
image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318')

# Create an arbitrary region.
geometry = ee.Geometry.Rectangle(-122.496, 37.532, -121.554, 37.538)

# Make an NDWI image.  It will have one band named 'nd'.
ndwi = image.normalizedDifference(['B3', 'B5'])

# Compute the weighted mean of the NDWI image clipped to the region.
weighted = (
    ndwi.clip(geometry)
    .reduceRegion(reducer=ee.Reducer.mean(), geometry=geometry, scale=30)
    .get('nd')
)

# Compute the UN-weighted mean of the NDWI image clipped to the region.
unweighted = (
    ndwi.clip(geometry)
    .reduceRegion(
        reducer=ee.Reducer.mean().unweighted(), geometry=geometry, scale=30
    )
    .get('nd')
)

# Observe the difference between weighted and unweighted reductions.
display('weighted:', weighted)
display('unweighted', unweighted)

नतीजों में अंतर इसलिए है, क्योंकि क्षेत्र के किनारे के पिक्सल को एक वज़न मिलता है. ऐसा, रिड्यूसर पर unweighted() को कॉल करने की वजह से होता है.

साफ़ तौर पर अहमियत वाला आउटपुट पाने के लिए, रिड्यूसर पर कॉल किए गए splitWeights() के साथ, वज़न को साफ़ तौर पर सेट करना बेहतर होता है. splitWeights() से बदला गया रिड्यूसर, दो इनपुट लेता है. इनमें से दूसरा इनपुट, वेट होता है. यहां दिए गए उदाहरण में, किसी इलाके में वीडस इंडेक्स (एनडीवीआई) का भारित औसत कैलकुलेट करके splitWeights() दिखाया गया है. इसमें, क्लाउड स्कोर के हिसाब से वैल्यू को तय किया गया है. जितने ज़्यादा बादल होंगे, वैल्यू उतनी ही कम होगी:

कोड एडिटर (JavaScript)

// Load an input Landsat 8 image.
var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_186059_20130419');

// Compute cloud score and reverse it such that the highest
// weight (100) is for the least cloudy pixels.
var cloudWeight = ee.Image(100).subtract(
  ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud']));

// Compute NDVI and add the cloud weight band.
var ndvi = image.normalizedDifference(['B5', 'B4']).addBands(cloudWeight);

// Define an arbitrary region in a cloudy area.
var region = ee.Geometry.Rectangle(9.9069, 0.5981, 10.5, 0.9757);

// Use a mean reducer.
var reducer = ee.Reducer.mean();

// Compute the unweighted mean.
var unweighted = ndvi.select(['nd']).reduceRegion(reducer, region, 30);

// compute mean weighted by cloudiness.
var weighted = ndvi.reduceRegion(reducer.splitWeights(), region, 30);

// Observe the difference as a result of weighting by cloudiness.
print('unweighted:', unweighted);
print('weighted:', weighted);

Python सेटअप

Python API के बारे में जानकारी पाने और इंटरैक्टिव डेवलपमेंट के लिए geemap का इस्तेमाल करने के लिए, Python एनवायरमेंट पेज देखें.

import ee
import geemap.core as geemap

Colab (Python)

# Load an input Landsat 8 image.
image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_186059_20130419')

# Compute cloud score and reverse it such that the highest
# weight (100) is for the least cloudy pixels.
cloud_weight = ee.Image(100).subtract(
    ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud'])
)

# Compute NDVI and add the cloud weight band.
ndvi = image.normalizedDifference(['B5', 'B4']).addBands(cloud_weight)

# Define an arbitrary region in a cloudy area.
region = ee.Geometry.Rectangle(9.9069, 0.5981, 10.5, 0.9757)

# Use a mean reducer.
reducer = ee.Reducer.mean()

# Compute the unweighted mean.
unweighted = ndvi.select(['nd']).reduceRegion(reducer, region, 30)

# compute mean weighted by cloudiness.
weighted = ndvi.reduceRegion(reducer.splitWeights(), region, 30)

# Observe the difference as a result of weighting by cloudiness.
display('unweighted:', unweighted)
display('weighted:', weighted)

ध्यान दें कि reduceRegion() को कॉल करने से पहले, cloudWeight को बैंड के तौर पर जोड़ना होगा. इस नतीजे से पता चलता है कि बादल वाले पिक्सल का वेट कम होने की वजह से, अनुमानित औसत एनडीवीआई ज़्यादा है.