کاهش وزنی

به طور پیش‌فرض، کاهنده‌های اعمال شده بر روی تصاویر، ورودی‌ها را بر اساس مقدار ماسک وزن می‌دهند. این موضوع در زمینه پیکسل‌های کسری ایجاد شده از طریق عملیاتی مانند clip() مرتبط است. این رفتار را با فراخوانی unweighted() روی کاهنده تنظیم کنید. استفاده از یک کاهنده بدون وزن، تمام پیکسل‌های موجود در منطقه را مجبور به داشتن وزن یکسان می‌کند. مثال زیر نشان می‌دهد که چگونه وزن‌دهی پیکسل می‌تواند بر خروجی کاهنده تأثیر بگذارد:

برای کاهش‌های وزنی، وزن‌های تقاطع پیکسل‌ها به صورت داخلی به صورت اعداد صحیح ۸ بیتی (۰ تا ۲۵۵) نمایش داده می‌شوند. این روش، پوشش کسری پیکسل را به ۲۵۶ سطح گسسته کوانتیزه می‌کند. در نتیجه، هر کسر پوششی کمتر از تقریباً ۱/۲۵۶ (~۰.۴٪) به وزن ۰ (نامعتبر) گرد می‌شود. برای جزئیات بیشتر در مورد نحوه وزن‌دهی پیکسل‌ها در یک منطقه، به راهنمای Reduce Region مراجعه کنید.

ویرایشگر کد (جاوااسکریپت)

// 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);

تنظیمات پایتون

برای اطلاعات بیشتر در مورد API پایتون و استفاده از geemap برای توسعه تعاملی، به صفحه محیط پایتون مراجعه کنید.

import ee
import geemap.core as geemap

کولب (پایتون)

# 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() در تابع reducer، وزنی برابر با یک دریافت می‌کنند.

برای به دست آوردن یک خروجی با وزن مشخص، ترجیح داده می‌شود که وزن‌ها به طور صریح با splitWeights() که در reducer فراخوانی می‌شود، تنظیم شوند. یک reducer اصلاح‌شده توسط splitWeights() دو ورودی می‌گیرد که ورودی دوم وزن است. مثال زیر splitWeights() با محاسبه میانگین وزنی شاخص پوشش گیاهی نرمال شده (NDVI) در یک منطقه، با وزن‌های داده شده توسط امتیاز ابر (هرچه ابری‌تر، وزن کمتر) نشان می‌دهد:

ویرایشگر کد (جاوااسکریپت)

// 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);

تنظیمات پایتون

برای اطلاعات بیشتر در مورد API پایتون و استفاده از geemap برای توسعه تعاملی، به صفحه محیط پایتون مراجعه کنید.

import ee
import geemap.core as geemap

کولب (پایتون)

# 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 به عنوان یک باند اضافه شود. نتیجه نشان می‌دهد که میانگین NDVI تخمینی در نتیجه کاهش وزن پیکسل‌های ابری، بالاتر است.