بررسی اجمالی کاهنده
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
کاهنده ها راهی برای جمع آوری داده ها در طول زمان، فضا، باندها، آرایه ها و سایر ساختارهای داده در Earth Engine هستند. کلاس ee.Reducer
نحوه جمع آوری داده ها را مشخص می کند. کاهندههای این کلاس میتوانند یک آمار ساده برای استفاده برای تجمیع (مانند حداقل، حداکثر، میانگین، میانه، انحراف استاندارد، و غیره) یا خلاصهای پیچیدهتر از دادههای ورودی (مانند هیستوگرام، رگرسیون خطی، فهرست) را مشخص کنند. کاهش ممکن است در طول زمان رخ دهد ( imageCollection.reduce()
)، فضا ( image.reduceRegion()
، image.reduceNeighborhood()
)، باندها ( image.reduce()
)، یا فضای ویژگی یک FeatureCollection
( featureCollection.reduceColumns()
یا متدهای FeatureCollection
که با aggregate_
شروع می شوند.
کاهنده ها یک مجموعه داده ورودی را می گیرند و یک خروجی واحد تولید می کنند. هنگامی که یک کاهش دهنده ورودی به یک تصویر چند باند اعمال می شود، Earth Engine به طور خودکار کاهنده را تکرار می کند و آن را به طور جداگانه برای هر باند اعمال می کند. در نتیجه، تصویر خروجی دارای همان تعداد باندهای تصویر ورودی است. هر باند در خروجی کاهش پیکسل ها از باند مربوطه در داده های ورودی است. برخی کاهنده ها چندین مجموعه داده ورودی را می گیرند. این کاهنده ها به طور خودکار برای هر باند تکرار نمی شوند. به عنوان مثال، ee.Reducer.LinearRegression()
مجموعه داده های پیش بینی کننده چندگانه (نماینده متغیرهای مستقل در رگرسیون) را در یک ترتیب خاص می گیرد (به کاهنده های رگرسیون مراجعه کنید).
برخی از کاهنده ها چندین خروجی تولید می کنند، به عنوان مثال ee.Reducer.minMax()
, ee.Reducer.histogram()
یا ee.Reducer.toList()
. به عنوان مثال:
ویرایشگر کد (جاوا اسکریپت)
// Load and filter the Sentinel-2 image collection.
var collection = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
.filterDate('2016-01-01', '2016-12-31')
.filterBounds(ee.Geometry.Point([-81.31, 29.90]));
// Reduce the collection.
var extrema = collection.reduce(ee.Reducer.minMax());
راه اندازی پایتون
برای اطلاعات در مورد API پایتون و استفاده از geemap
برای توسعه تعاملی به صفحه محیط پایتون مراجعه کنید.
import ee
import geemap.core as geemap
کولب (پایتون)
# Load and filter the Sentinel-2 image collection.
collection = (
ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
.filterDate('2016-01-01', '2016-12-31')
.filterBounds(ee.Geometry.Point([-81.31, 29.90]))
)
# Reduce the collection.
extrema = collection.reduce(ee.Reducer.minMax())
این یک خروجی با دو برابر تعداد باندهای ورودی تولید می کند، که در آن نام باندها در خروجی '_min' یا '_max' به نام باند اضافه شده است.
نوع خروجی باید با محاسبات مطابقت داشته باشد. به عنوان مثال، کاهش دهنده اعمال شده بر روی ImageCollection
دارای خروجی Image
است. از آنجایی که خروجی به عنوان یک مقدار پیکسل تفسیر میشود، باید از کاهندههایی با خروجی عددی برای کاهش ImageCollection
استفاده کنید (کاهندههایی مانند toList()
یا histogram()
کار نمیکنند.
بهطور پیشفرض، کاهشهای بیش از مقادیر پیکسل با ماسک آنها وزن میشوند، اگرچه این رفتار را میتوان تغییر داد (به بخش وزندهی مراجعه کنید). پیکسل هایی با ماسک برابر با 0 در کاهش استفاده نمی شوند.
ترکیب کاهنده ها
اگر قصد شما این است که چند کاهنده را برای ورودی های یکسان اعمال کنید، بهتر است برای کارایی، کاهنده ها combine()
. به طور خاص، فراخوانی combine()
روی یک کاهنده با sharedInputs
که روی true
تنظیم شده باشد، تنها منجر به یک عبور از داده ها می شود. به عنوان مثال، برای محاسبه میانگین و انحراف استاندارد پیکسل ها در یک تصویر، می توانید از چیزی شبیه به زیر استفاده کنید:
ویرایشگر کد (جاوا اسکریپت)
// Load a Landsat 8 image.
var image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318');
// Combine the mean and standard deviation reducers.
var reducers = ee.Reducer.mean().combine({
reducer2: ee.Reducer.stdDev(),
sharedInputs: true
});
// Use the combined reducer to get the mean and SD of the image.
var stats = image.reduceRegion({
reducer: reducers,
bestEffort: true,
});
// Display the dictionary of band means and SDs.
print(stats);
راه اندازی پایتون
برای اطلاعات در مورد API پایتون و استفاده از geemap
برای توسعه تعاملی به صفحه محیط پایتون مراجعه کنید.
import ee
import geemap.core as geemap
کولب (پایتون)
# Load a Landsat 8 image.
image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318')
# Combine the mean and standard deviation reducers.
reducers = ee.Reducer.mean().combine(
reducer2=ee.Reducer.stdDev(), sharedInputs=True
)
# Use the combined reducer to get the mean and SD of the image.
stats = image.reduceRegion(reducer=reducers, bestEffort=True)
# Display the dictionary of band means and SDs.
display(stats)
در خروجی توجه داشته باشید که نام کاهنده ها به نام ورودی ها اضافه شده است تا خروجی های کاهنده را متمایز کند. این رفتار برای خروجی های تصویر نیز اعمال می شود، که نام کاهش دهنده به نام باندهای خروجی اضافه می شود.
اگر کاهندهها را با استفاده از ورودیهای وزنی و کاهندهها را با استفاده از ورودیهای وزنی ترکیب میکنید، همه ورودیهای وزندار باید قبل از همه ورودیهای بدون وزن باشند.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eReducers in Earth Engine aggregate data over time, space, bands, arrays, and other data structures, using methods like \u003ccode\u003ereduceRegion()\u003c/code\u003e and \u003ccode\u003ereduce()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eReducers can calculate simple statistics (e.g., mean, minimum) or more complex summaries (e.g., histograms, linear regressions) on images, image collections, and feature collections.\u003c/p\u003e\n"],["\u003cp\u003eWhen applied to multi-band images, single input reducers are automatically applied to each band, producing an output with the same number of bands.\u003c/p\u003e\n"],["\u003cp\u003eReducers can be combined using \u003ccode\u003ecombine()\u003c/code\u003e for efficient processing, allowing multiple calculations in a single pass over the data.\u003c/p\u003e\n"],["\u003cp\u003eBy default, pixel values in reductions are weighted by their mask, meaning pixels with a mask of 0 are excluded from the calculation.\u003c/p\u003e\n"]]],[],null,["# Reducer Overview\n\nReducers are the way to aggregate data over time, space, bands, arrays and other data\nstructures in Earth Engine. The `ee.Reducer` class specifies how data is\naggregated. The reducers in this class can specify a simple statistic to use for the\naggregation (e.g. minimum, maximum, mean, median, standard deviation, etc.), or a more complex\nsummary of the input data (e.g. histogram, linear regression, list). Reductions may occur over\ntime (`imageCollection.reduce()`), space (`image.reduceRegion()`,\n`image.reduceNeighborhood()`), bands (`image.reduce()`), or the\nattribute space of a `FeatureCollection` (`featureCollection.reduceColumns()`\nor `FeatureCollection` methods that start with `aggregate_`).\n\nReducers have inputs and outputs\n--------------------------------\n\n\nReducers take an input dataset and produce a single output. When a single input reducer is\napplied to a multi-band image, Earth Engine automatically replicates the reducer and applies\nit separately to each band. As a result, the output image has the same number of bands as the\ninput image; each band in the output is the reduction of pixels from the corresponding band in\nthe input data. Some reducers take tuples of input datasets. These reducers will not be\nautomatically replicated for each band. For example,\n`ee.Reducer.LinearRegression()` takes multiple predictor datasets (representing\nindependent variables in the regression) in a particular order (see\n[Regression reducers](/earth-engine/guides/reducers_regression)).\n\n\nSome reducers produce multiple outputs, for example `ee.Reducer.minMax()`,\n`ee.Reducer.histogram()` or `ee.Reducer.toList()`. For example:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load and filter the Sentinel-2 image collection.\nvar collection = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')\n .filterDate('2016-01-01', '2016-12-31')\n .filterBounds(ee.Geometry.Point([-81.31, 29.90]));\n\n// Reduce the collection.\nvar extrema = collection.reduce(ee.Reducer.minMax());\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# Load and filter the Sentinel-2 image collection.\ncollection = (\n ee.ImageCollection('COPERNICUS/S2_HARMONIZED')\n .filterDate('2016-01-01', '2016-12-31')\n .filterBounds(ee.Geometry.Point([-81.31, 29.90]))\n)\n\n# Reduce the collection.\nextrema = collection.reduce(ee.Reducer.minMax())\n```\n\n\nThis will produce an output with twice the number of bands of the inputs, where band names in\nthe output have '_min' or '_max' appended to the band name.\n\n\nThe output type should match the computation. For example, a reducer applied to an\n`ImageCollection` has an `Image` output. Because the output is\ninterpreted as a pixel value, you must use reducers with a numeric output to reduce an\n`ImageCollection` (reducers like `toList()` or\n`histogram()` won't work).\n\nReducers use weighted inputs\n----------------------------\n\n\nBy default, reductions over pixel values are weighted by their mask, though this behavior can\nbe changed (see the [Weighting section](/earth-engine/guides/reducers_weighting)). Pixels with mask\nequal to 0 will not be used in the reduction.\n\nCombining reducers\n------------------\n\n\nIf your intent is to apply multiple reducers to the same inputs, it's good practice to\n`combine()` the reducers for efficiency. Specifically, calling\n`combine()` on a reducer with `sharedInputs` set to\n`true` will result in only a single pass over the data. For example, to compute the\nmean and standard deviation of pixels in an image, you could use something like this:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a Landsat 8 image.\nvar image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318');\n\n// Combine the mean and standard deviation reducers.\nvar reducers = ee.Reducer.mean().combine({\n reducer2: ee.Reducer.stdDev(),\n sharedInputs: true\n});\n\n// Use the combined reducer to get the mean and SD of the image.\nvar stats = image.reduceRegion({\n reducer: reducers,\n bestEffort: true,\n});\n\n// Display the dictionary of band means and SDs.\nprint(stats);\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# Load a Landsat 8 image.\nimage = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318')\n\n# Combine the mean and standard deviation reducers.\nreducers = ee.Reducer.mean().combine(\n reducer2=ee.Reducer.stdDev(), sharedInputs=True\n)\n\n# Use the combined reducer to get the mean and SD of the image.\nstats = image.reduceRegion(reducer=reducers, bestEffort=True)\n\n# Display the dictionary of band means and SDs.\ndisplay(stats)\n```\n\n\nIn the output, note that the names of the reducers have been appended to the names of the\ninputs to distinguish the reducer outputs. This behavior also applies to image outputs, which\nwill have the name of the reducer appended to output band names.\n\n\nIf you are combining reducers using unweighted inputs and reducers using weighted inputs, all\nweighted inputs must be before all unweighted inputs."]]